From 415fa66677e2b38d8e97d233da013ffaceecc2e4 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Wed, 21 Feb 2024 18:29:57 +0100 Subject: [PATCH] add object.setValueAtIndex --- src/binding.cpp | 13 +++++++++++++ src/binding.h | 6 ++++++ src/v8.zig | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/src/binding.cpp b/src/binding.cpp index 943132d..a58e536 100644 --- a/src/binding.cpp +++ b/src/binding.cpp @@ -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* 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, diff --git a/src/binding.h b/src/binding.h index 10adbbf..5e8bcff 100644 --- a/src/binding.h +++ b/src/binding.h @@ -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, diff --git a/src/v8.zig b/src/v8.zig index 518d409..81af86f 100644 --- a/src/v8.zig +++ b/src/v8.zig @@ -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{