Skip to content

Commit 696fae9

Browse files
Merge pull request #58 from karlseguin/object_delete_value
expose v8.Object.Delete
2 parents debd0cc + 8b14d09 commit 696fae9

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)