Skip to content

Commit

Permalink
feat: access with receiver (#1542)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek authored Jul 24, 2024
1 parent c9383c2 commit d5da421
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,14 @@ const v8::Value* v8__Object__Get(const v8::Object& self,
ptr_to_local(&self)->Get(ptr_to_local(&context), ptr_to_local(&key)));
}

const v8::Value* v8__Object__GetWithReceiver(const v8::Object& self,
const v8::Context& context,
const v8::Value& key,
const v8::Object& receiver) {
return maybe_local_to_ptr(ptr_to_local(&self)->Get(
ptr_to_local(&context), ptr_to_local(&key), ptr_to_local(&receiver)));
}

const v8::Value* v8__Object__GetIndex(const v8::Object& self,
const v8::Context& context,
uint32_t index) {
Expand Down Expand Up @@ -1411,6 +1419,16 @@ MaybeBool v8__Object__Set(const v8::Object& self, const v8::Context& context,
ptr_to_local(&context), ptr_to_local(&key), ptr_to_local(&value)));
}

MaybeBool v8__Object__SetWithReceiver(const v8::Object& self,
const v8::Context& context,
const v8::Value& key,
const v8::Value& value,
const v8::Object& receiver) {
return maybe_to_maybe_bool(
ptr_to_local(&self)->Set(ptr_to_local(&context), ptr_to_local(&key),
ptr_to_local(&value), ptr_to_local(&receiver)));
}

MaybeBool v8__Object__SetIndex(const v8::Object& self,
const v8::Context& context, uint32_t index,
const v8::Value& value) {
Expand Down
54 changes: 54 additions & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ extern "C" {
context: *const Context,
key: *const Value,
) -> *const Value;
fn v8__Object__GetWithReceiver(
this: *const Object,
context: *const Context,
key: *const Value,
receiver: *const Object,
) -> *const Value;
fn v8__Object__GetIndex(
this: *const Object,
context: *const Context,
Expand All @@ -70,6 +76,13 @@ extern "C" {
key: *const Value,
value: *const Value,
) -> MaybeBool;
fn v8__Object__SetWithReceiver(
this: *const Object,
context: *const Context,
key: *const Value,
value: *const Value,
receiver: *const Object,
) -> MaybeBool;
fn v8__Object__SetIndex(
this: *const Object,
context: *const Context,
Expand Down Expand Up @@ -333,6 +346,28 @@ impl Object {
.into()
}

/// SetWithReceiver only return Just(true) or Empty(), so if it should never fail, use
/// result.Check().
#[inline(always)]
pub fn set_with_receiver(
&self,
scope: &mut HandleScope,
key: Local<Value>,
value: Local<Value>,
receiver: Local<Object>,
) -> Option<bool> {
unsafe {
v8__Object__SetWithReceiver(
self,
&*scope.get_current_context(),
&*key,
&*value,
&*receiver,
)
}
.into()
}

/// Set only return Just(true) or Empty(), so if it should never fail, use
/// result.Check().
#[inline(always)]
Expand Down Expand Up @@ -449,6 +484,25 @@ impl Object {
}
}

#[inline(always)]
pub fn get_with_receiver<'s>(
&self,
scope: &mut HandleScope<'s>,
key: Local<Value>,
receiver: Local<Object>,
) -> Option<Local<'s, Value>> {
unsafe {
scope.cast_local(|sd| {
v8__Object__GetWithReceiver(
self,
sd.get_current_context(),
&*key,
&*receiver,
)
})
}
}

#[inline(always)]
pub fn get_index<'s>(
&self,
Expand Down

0 comments on commit d5da421

Please sign in to comment.