0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-01 16:51:32 -05:00

Make function signature of 'AccessorNameGetterCallback' match C++ (#214)

This commit is contained in:
Bert Belder 2020-01-17 07:39:05 +01:00
parent 7862af65e0
commit bed0088550
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
3 changed files with 7 additions and 11 deletions

View file

@ -5,9 +5,9 @@ use crate::FunctionCallback;
use crate::MessageCallback; use crate::MessageCallback;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub union ExternalReference { pub union ExternalReference<'s> {
pub function: FunctionCallback, pub function: FunctionCallback,
pub getter: AccessorNameGetterCallback, pub getter: AccessorNameGetterCallback<'s>,
pub message: MessageCallback, pub message: MessageCallback,
} }

View file

@ -246,13 +246,10 @@ where
/// AccessorNameGetterCallback is used as callback functions when getting a /// AccessorNameGetterCallback is used as callback functions when getting a
/// particular property. See Object and ObjectTemplate's method SetAccessor. /// particular property. See Object and ObjectTemplate's method SetAccessor.
// TODO(piscisaureus): The actual signature of this callback is pub type AccessorNameGetterCallback<'s> =
// `extern "C" fn(Local<Name>, *const PropertyCallbackInfo)`. This works in extern "C" fn(Local<'s, Name>, *const PropertyCallbackInfo);
// practice but is not strictly correct, and should be fixed.
pub type AccessorNameGetterCallback =
extern "C" fn(*mut Name, *const PropertyCallbackInfo);
impl<F> MapFnFrom<F> for AccessorNameGetterCallback impl<F> MapFnFrom<F> for AccessorNameGetterCallback<'_>
where where
F: UnitType F: UnitType
+ Fn( + Fn(
@ -263,11 +260,10 @@ where
), ),
{ {
fn mapping() -> Self { fn mapping() -> Self {
let f = |key: *mut Name, info: *const PropertyCallbackInfo| { let f = |key: Local<Name>, info: *const PropertyCallbackInfo| {
let scope: PropertyCallbackScope = unsafe { let scope: PropertyCallbackScope = unsafe {
&mut *(info as *const _ as *mut Entered<PropertyCallbackInfo>) &mut *(info as *const _ as *mut Entered<PropertyCallbackInfo>)
}; };
let key = unsafe { scope.to_local(key) }.unwrap();
let args = PropertyCallbackArguments::from_property_callback_info(info); let args = PropertyCallbackArguments::from_property_callback_info(info);
let rv = ReturnValue::from_property_callback_info(info); let rv = ReturnValue::from_property_callback_info(info);
(F::get())(scope, key, args, rv); (F::get())(scope, key, args, rv);

View file

@ -137,7 +137,7 @@ impl Object {
&mut self, &mut self,
context: Local<Context>, context: Local<Context>,
name: Local<Name>, name: Local<Name>,
getter: impl MapFnTo<AccessorNameGetterCallback>, getter: impl for<'s> MapFnTo<AccessorNameGetterCallback<'s>>,
) -> MaybeBool { ) -> MaybeBool {
unsafe { unsafe {
v8__Object__SetAccessor(self, &*context, &*name, getter.map_fn_to()) v8__Object__SetAccessor(self, &*context, &*name, getter.map_fn_to())