diff --git a/src/external_references.rs b/src/external_references.rs index 91396a9d..e36257ad 100644 --- a/src/external_references.rs +++ b/src/external_references.rs @@ -5,11 +5,13 @@ use crate::FunctionCallback; use crate::IndexedDefinerCallback; use crate::IndexedDeleterCallback; use crate::IndexedGetterCallback; +use crate::IndexedQueryCallback; use crate::IndexedSetterCallback; use crate::MessageCallback; use crate::NamedDefinerCallback; use crate::NamedDeleterCallback; use crate::NamedGetterCallback; +use crate::NamedQueryCallback; use crate::NamedSetterCallback; use crate::PropertyEnumeratorCallback; use std::ffi::c_void; @@ -22,10 +24,12 @@ pub union ExternalReference<'s> { pub named_setter: NamedSetterCallback<'s>, pub named_definer: NamedDefinerCallback<'s>, pub named_deleter: NamedDeleterCallback<'s>, + pub named_query: NamedQueryCallback<'s>, pub indexed_getter: IndexedGetterCallback<'s>, pub indexed_setter: IndexedSetterCallback<'s>, pub indexed_definer: IndexedDefinerCallback<'s>, pub indexed_deleter: IndexedDeleterCallback<'s>, + pub indexed_query: IndexedQueryCallback<'s>, pub enumerator: PropertyEnumeratorCallback<'s>, pub message: MessageCallback, pub pointer: *mut c_void, diff --git a/src/function.rs b/src/function.rs index 931db343..db7efa51 100644 --- a/src/function.rs +++ b/src/function.rs @@ -16,6 +16,7 @@ use crate::Boolean; use crate::Context; use crate::Function; use crate::HandleScope; +use crate::Integer; use crate::Isolate; use crate::Local; use crate::Name; @@ -584,6 +585,33 @@ where } } +pub(crate) type NamedQueryCallback<'s> = extern "C" fn( + Local<'s, Name>, + *const PropertyCallbackInfo, +) -> Intercepted; + +impl MapFnFrom for NamedQueryCallback<'_> +where + F: UnitType + + for<'s> Fn( + &mut HandleScope<'s>, + Local<'s, Name>, + PropertyCallbackArguments<'s>, + ReturnValue, + ) -> Intercepted, +{ + fn mapping() -> Self { + let f = |key: Local, info: *const PropertyCallbackInfo| { + let info = unsafe { &*info }; + let scope = &mut unsafe { CallbackScope::new(info) }; + let args = PropertyCallbackArguments::from_property_callback_info(info); + let rv = ReturnValue::from_property_callback_info(info); + (F::get())(scope, key, args, rv) + }; + f.to_c_fn() + } +} + pub(crate) type NamedSetterCallbackForAccessor<'s> = extern "C" fn( Local<'s, Name>, Local<'s, Value>, @@ -755,6 +783,31 @@ where } } +pub(crate) type IndexedQueryCallback<'s> = + extern "C" fn(u32, *const PropertyCallbackInfo) -> Intercepted; + +impl MapFnFrom for IndexedQueryCallback<'_> +where + F: UnitType + + for<'s> Fn( + &mut HandleScope<'s>, + u32, + PropertyCallbackArguments<'s>, + ReturnValue, + ) -> Intercepted, +{ + fn mapping() -> Self { + let f = |key: u32, info: *const PropertyCallbackInfo| { + let info = unsafe { &*info }; + let scope = &mut unsafe { CallbackScope::new(info) }; + let args = PropertyCallbackArguments::from_property_callback_info(info); + let rv = ReturnValue::from_property_callback_info(info); + (F::get())(scope, key, args, rv) + }; + f.to_c_fn() + } +} + pub(crate) type IndexedSetterCallback<'s> = extern "C" fn( u32, Local<'s, Value>, diff --git a/src/template.rs b/src/template.rs index baef4210..6b9bc02a 100644 --- a/src/template.rs +++ b/src/template.rs @@ -18,12 +18,14 @@ use crate::HandleScope; use crate::IndexedDefinerCallback; use crate::IndexedDeleterCallback; use crate::IndexedGetterCallback; +use crate::IndexedQueryCallback; use crate::IndexedSetterCallback; use crate::Local; use crate::NamedDefinerCallback; use crate::NamedDeleterCallback; use crate::NamedGetterCallback; use crate::NamedGetterCallbackForAccessor; +use crate::NamedQueryCallback; use crate::NamedSetterCallback; use crate::NamedSetterCallbackForAccessor; use crate::Object; @@ -195,7 +197,7 @@ pub type NamedPropertySetterCallback<'s> = NamedSetterCallback<'s>; /// this interceptor depending on the state of the object. /// /// See also [ObjectTemplate::set_named_property_handler]. -pub type NamedPropertyQueryCallback<'s> = NamedGetterCallback<'s>; +pub type NamedPropertyQueryCallback<'s> = NamedQueryCallback<'s>; /// Interceptor for delete requests on an object. /// @@ -253,7 +255,7 @@ pub type IndexedPropertyGetterCallback<'s> = IndexedGetterCallback<'s>; pub type IndexedPropertySetterCallback<'s> = IndexedSetterCallback<'s>; /// See [GenericNamedPropertyQueryCallback]. -pub type IndexedPropertyQueryCallback<'s> = IndexedGetterCallback<'s>; +pub type IndexedPropertyQueryCallback<'s> = IndexedQueryCallback<'s>; /// See [GenericNamedPropertyDeleterCallback]. pub type IndexedPropertyDeleterCallback<'s> = IndexedDeleterCallback<'s>; diff --git a/tests/test_api.rs b/tests/test_api.rs index b63b436d..4766696b 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -2237,7 +2237,7 @@ fn object_template_set_named_property_handler() { let query = |scope: &mut v8::HandleScope, key: v8::Local, args: v8::PropertyCallbackArguments, - mut rv: v8::ReturnValue| { + mut rv: v8::ReturnValue| { let fallthrough_key = v8::String::new(scope, "fallthrough").unwrap(); if key.strict_equals(fallthrough_key.into()) { return v8::Intercepted::No; @@ -2690,7 +2690,7 @@ fn object_template_set_indexed_property_handler() { let query = |_scope: &mut v8::HandleScope, index: u32, _args: v8::PropertyCallbackArguments, - mut rv: v8::ReturnValue| { + mut rv: v8::ReturnValue| { if index == 12 { return v8::Intercepted::No; }