Skip to content

Commit 8b14d09

Browse files
committed
expose v8.Object.Delete
1 parent 5790c80 commit 8b14d09

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/binding.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,17 @@ void v8__Object__Set(
981981
);
982982
}
983983

984+
void v8__Object__Delete(
985+
const v8::Object& self,
986+
const v8::Context& ctx,
987+
const v8::Value& key,
988+
v8::Maybe<bool>* out) {
989+
*out = ptr_to_local(&self)->Delete(
990+
ptr_to_local(&ctx),
991+
ptr_to_local(&key)
992+
);
993+
}
994+
984995
void v8__Object__SetAtIndex(
985996
const v8::Object& self,
986997
const v8::Context& ctx,

src/binding.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,11 @@ void v8__Object__Set(
499499
const Value* key,
500500
const Value* value,
501501
MaybeBool* out);
502+
void v8__Object__Delete(
503+
const Object* self,
504+
const Context* ctx,
505+
const Value* key,
506+
MaybeBool* out);
502507
void v8__Object__SetAtIndex(
503508
const Object* self,
504509
const Context* ctx,

src/main_build.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
pub fn main() !void {
2-
}
1+
pub fn main() !void {}

src/v8.zig

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ pub const ObjectTemplate = struct {
10041004
.enumerator = configuration.enumerator orelse null,
10051005
.definer = configuration.definer orelse null,
10061006
.descriptor = configuration.descriptor orelse null,
1007-
.data = if (@typeInfo(@TypeOf(data)) == .@"null") null else getDataHandle(data),
1007+
.data = if (@typeInfo(@TypeOf(data)) == .null) null else getDataHandle(data),
10081008
.flags = configuration.flags,
10091009
};
10101010
c.v8__ObjectTemplate__SetIndexedHandler(self.handle, &conf);
@@ -1019,7 +1019,7 @@ pub const ObjectTemplate = struct {
10191019
.enumerator = configuration.enumerator orelse null,
10201020
.definer = configuration.definer orelse null,
10211021
.descriptor = configuration.descriptor orelse null,
1022-
.data = if (@typeInfo(@TypeOf(data)) == .@"null") null else getDataHandle(data),
1022+
.data = if (@typeInfo(@TypeOf(data)) == .null) null else getDataHandle(data),
10231023
.flags = configuration.flags,
10241024
};
10251025
c.v8__ObjectTemplate__SetNamedHandler(self.handle, &conf);
@@ -1109,6 +1109,14 @@ pub const Object = struct {
11091109
return out.has_value;
11101110
}
11111111

1112+
// Returns true on success, false on fail.
1113+
pub fn deleteValue(self: Self, ctx: Context, key: anytype) bool {
1114+
var out: c.MaybeBool = undefined;
1115+
c.v8__Object__Delete(self.handle, ctx.handle, getValueHandle(key), &out);
1116+
// Set only returns empty for an error or true.
1117+
return out.has_value;
1118+
}
1119+
11121120
pub fn setValueAtIndex(self: Self, ctx: Context, idx: u32, value: anytype) bool {
11131121
var out: c.MaybeBool = undefined;
11141122
c.v8__Object__SetAtIndex(self.handle, ctx.handle, idx, getValueHandle(value), &out);

0 commit comments

Comments
 (0)