Skip to content

Commit

Permalink
add object.setValueAtIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
krichprollsch committed Feb 26, 2024
1 parent c49a4b9 commit 415fa66
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,19 @@ void v8__Object__Set(
);
}

void v8__Object__SetAtIndex(
const v8::Object& self,
const v8::Context& ctx,
uint32_t idx,
const v8::Value& value,
v8::Maybe<bool>* out) {
*out = ptr_to_local(&self)->Set(
ptr_to_local(&ctx),
idx,
ptr_to_local(&value)
);
}

void v8__Object__DefineOwnProperty(
const v8::Object& self,
const v8::Context& ctx,
Expand Down
6 changes: 6 additions & 0 deletions src/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ void v8__Object__Set(
const Value* key,
const Value* value,
MaybeBool* out);
void v8__Object__SetAtIndex(
const Object* self,
const Context* ctx,
uint32_t idx,
const Value* value,
MaybeBool* out);
void v8__Object__DefineOwnProperty(
const Object* self,
const Context* ctx,
Expand Down
7 changes: 7 additions & 0 deletions src/v8.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,13 @@ pub const Object = struct {
return out.has_value;
}

pub fn setValueAtIndex(self: Self, ctx: Context, idx: u32, value: anytype) bool {
var out: c.MaybeBool = undefined;
c.v8__Object__SetAtIndex(self.handle, ctx.handle, idx, getValueHandle(value), &out);
// Set only returns empty for an error or true.
return out.has_value;
}

pub fn getValue(self: Self, ctx: Context, key: anytype) !Value {
if (c.v8__Object__Get(self.handle, ctx.handle, getValueHandle(key))) |handle| {
return Value{
Expand Down

0 comments on commit 415fa66

Please sign in to comment.