mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-26 09:13:46 -05:00
fix: QueryCallback should use Integer (#1545)
This commit is contained in:
parent
634b1b99d9
commit
c9383c2184
4 changed files with 63 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -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<Integer>,
|
||||
) -> Intercepted;
|
||||
|
||||
impl<F> MapFnFrom<F> for NamedQueryCallback<'_>
|
||||
where
|
||||
F: UnitType
|
||||
+ for<'s> Fn(
|
||||
&mut HandleScope<'s>,
|
||||
Local<'s, Name>,
|
||||
PropertyCallbackArguments<'s>,
|
||||
ReturnValue<Integer>,
|
||||
) -> Intercepted,
|
||||
{
|
||||
fn mapping() -> Self {
|
||||
let f = |key: Local<Name>, info: *const PropertyCallbackInfo<Integer>| {
|
||||
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<Integer>) -> Intercepted;
|
||||
|
||||
impl<F> MapFnFrom<F> for IndexedQueryCallback<'_>
|
||||
where
|
||||
F: UnitType
|
||||
+ for<'s> Fn(
|
||||
&mut HandleScope<'s>,
|
||||
u32,
|
||||
PropertyCallbackArguments<'s>,
|
||||
ReturnValue<Integer>,
|
||||
) -> Intercepted,
|
||||
{
|
||||
fn mapping() -> Self {
|
||||
let f = |key: u32, info: *const PropertyCallbackInfo<Integer>| {
|
||||
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>,
|
||||
|
|
|
@ -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>;
|
||||
|
|
|
@ -2237,7 +2237,7 @@ fn object_template_set_named_property_handler() {
|
|||
let query = |scope: &mut v8::HandleScope,
|
||||
key: v8::Local<v8::Name>,
|
||||
args: v8::PropertyCallbackArguments,
|
||||
mut rv: v8::ReturnValue<v8::Value>| {
|
||||
mut rv: v8::ReturnValue<v8::Integer>| {
|
||||
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<v8::Value>| {
|
||||
mut rv: v8::ReturnValue<v8::Integer>| {
|
||||
if index == 12 {
|
||||
return v8::Intercepted::No;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue