@@ -14,6 +14,7 @@ use crate::Local;
1414use crate :: Name ;
1515use crate :: Object ;
1616use crate :: PropertyDescriptor ;
17+ use crate :: ScriptOrigin ;
1718use crate :: SealedLocal ;
1819use crate :: Signature ;
1920use crate :: String ;
@@ -29,7 +30,6 @@ use crate::support::ToCFn;
2930use crate :: support:: UnitType ;
3031use crate :: support:: { Opaque , int} ;
3132use crate :: template:: Intercepted ;
32- use crate :: { ScriptOrigin , undefined} ;
3333
3434unsafe extern "C" {
3535 fn v8__Function__New (
@@ -66,11 +66,30 @@ unsafe extern "C" {
6666 script : * const Function ,
6767 ) -> * mut CachedData < ' static > ;
6868
69- static v8__FunctionCallbackInfo__kArgsLength: int ;
70-
69+ fn v8__FunctionCallbackInfo__GetIsolate (
70+ this : * const FunctionCallbackInfo ,
71+ ) -> * mut RealIsolate ;
7172 fn v8__FunctionCallbackInfo__Data (
7273 this : * const FunctionCallbackInfo ,
7374 ) -> * const Value ;
75+ fn v8__FunctionCallbackInfo__This (
76+ this : * const FunctionCallbackInfo ,
77+ ) -> * const Object ;
78+ fn v8__FunctionCallbackInfo__NewTarget (
79+ this : * const FunctionCallbackInfo ,
80+ ) -> * const Value ;
81+ fn v8__FunctionCallbackInfo__IsConstructCall (
82+ this : * const FunctionCallbackInfo ,
83+ ) -> bool ;
84+ fn v8__FunctionCallbackInfo__Get (
85+ this : * const FunctionCallbackInfo ,
86+ index : int ,
87+ ) -> * const Value ;
88+ fn v8__FunctionCallbackInfo__Length ( this : * const FunctionCallbackInfo )
89+ -> int ;
90+ fn v8__FunctionCallbackInfo__GetReturnValue (
91+ this : * const FunctionCallbackInfo ,
92+ ) -> usize ;
7493
7594 fn v8__PropertyCallbackInfo__GetIsolate (
7695 this : * const RawPropertyCallbackInfo ,
@@ -160,8 +179,10 @@ impl<'cb, T> ReturnValue<'cb, T> {
160179impl < ' cb > ReturnValue < ' cb , Value > {
161180 #[ inline( always) ]
162181 pub fn from_function_callback_info ( info : & ' cb FunctionCallbackInfo ) -> Self {
163- let nn = info. get_return_value_non_null ( ) ;
164- Self ( RawReturnValue ( nn. as_ptr ( ) as _ ) , PhantomData )
182+ Self (
183+ unsafe { RawReturnValue ( v8__FunctionCallbackInfo__GetReturnValue ( info) ) } ,
184+ PhantomData ,
185+ )
165186 }
166187}
167188
@@ -232,54 +253,35 @@ where
232253/// the holder of the function.
233254#[ repr( C ) ]
234255#[ derive( Debug ) ]
235- pub struct FunctionCallbackInfo {
236- // The layout of this struct must match that of `class FunctionCallbackInfo`
237- // as defined in v8.h.
238- implicit_args : * mut * const Opaque ,
239- values : * mut * const Opaque ,
240- length : int ,
241- }
242-
243- // These constants must match those defined on `class FunctionCallbackInfo` in
244- // v8-function-callback.h.
245- #[ allow( dead_code, non_upper_case_globals) ]
246- impl FunctionCallbackInfo {
247- const kHolderIndex: i32 = 0 ;
248- const kIsolateIndex: i32 = 1 ;
249- const kContextIndex: i32 = 2 ;
250- const kReturnValueIndex: i32 = 3 ;
251- const kTargetIndex: i32 = 4 ;
252- const kNewTargetIndex: i32 = 5 ;
253- const kArgsLength: i32 = 6 ;
254- }
256+ pub struct FunctionCallbackInfo ( * mut Opaque ) ;
255257
256258impl FunctionCallbackInfo {
257259 #[ inline( always) ]
258260 pub ( crate ) fn get_isolate_ptr ( & self ) -> * mut RealIsolate {
259- let arg_nn =
260- self . get_implicit_arg_non_null :: < * mut RealIsolate > ( Self :: kIsolateIndex) ;
261- * unsafe { arg_nn. as_ref ( ) }
262- }
263-
264- #[ inline( always) ]
265- pub ( crate ) fn get_return_value_non_null ( & self ) -> NonNull < Value > {
266- self . get_implicit_arg_non_null :: < Value > ( Self :: kReturnValueIndex)
261+ unsafe { v8__FunctionCallbackInfo__GetIsolate ( self ) }
267262 }
268263
269264 #[ inline( always) ]
270265 pub ( crate ) fn new_target ( & self ) -> Local < ' _ , Value > {
271- unsafe { self . get_implicit_arg_local ( Self :: kNewTargetIndex) }
266+ unsafe {
267+ let ptr = v8__FunctionCallbackInfo__NewTarget ( self ) ;
268+ let nn = NonNull :: new_unchecked ( ptr as * mut _ ) ;
269+ Local :: from_non_null ( nn)
270+ }
272271 }
273272
274273 #[ inline( always) ]
275274 pub ( crate ) fn this ( & self ) -> Local < ' _ , Object > {
276- unsafe { self . get_arg_local ( -1 ) }
275+ unsafe {
276+ let ptr = v8__FunctionCallbackInfo__This ( self ) ;
277+ let nn = NonNull :: new_unchecked ( ptr as * mut _ ) ;
278+ Local :: from_non_null ( nn)
279+ }
277280 }
278281
279282 #[ inline]
280283 pub fn is_construct_call ( & self ) -> bool {
281- // The "new.target" value is only set for construct calls.
282- !self . new_target ( ) . is_undefined ( )
284+ unsafe { v8__FunctionCallbackInfo__IsConstructCall ( self ) }
283285 }
284286
285287 #[ inline( always) ]
@@ -292,62 +294,23 @@ impl FunctionCallbackInfo {
292294 }
293295
294296 #[ inline( always) ]
295- pub ( crate ) fn length ( & self ) -> i32 {
296- self . length
297+ pub ( crate ) fn length ( & self ) -> int {
298+ unsafe { v8__FunctionCallbackInfo__Length ( self ) }
297299 }
298300
299301 #[ inline( always) ]
300302 pub ( crate ) fn get ( & self , index : int ) -> Local < ' _ , Value > {
301- if index >= 0 && index < self . length {
302- unsafe { self . get_arg_local ( index) }
303- } else {
304- let isolate = unsafe {
305- crate :: isolate:: Isolate :: from_raw_ptr ( self . get_isolate_ptr ( ) )
306- } ;
307- undefined ( & isolate) . into ( )
303+ unsafe {
304+ let ptr = v8__FunctionCallbackInfo__Get ( self , index) ;
305+ let nn = NonNull :: new_unchecked ( ptr as * mut Value ) ;
306+ Local :: from_non_null ( nn)
308307 }
309308 }
310-
311- #[ inline( always) ]
312- fn get_implicit_arg_non_null < T > ( & self , index : i32 ) -> NonNull < T > {
313- // In debug builds, check that `FunctionCallbackInfo::kArgsLength` matches
314- // the C++ definition. Unfortunately we can't check the other constants
315- // because they are declared protected in the C++ header.
316- debug_assert_eq ! (
317- unsafe { v8__FunctionCallbackInfo__kArgsLength } ,
318- Self :: kArgsLength
319- ) ;
320- // Assert that `index` is in bounds.
321- assert ! ( index >= 0 ) ;
322- assert ! ( index < Self :: kArgsLength) ;
323- // Compute the address of the implicit argument and cast to `NonNull<T>`.
324- let ptr = unsafe { self . implicit_args . offset ( index as isize ) as * mut T } ;
325- debug_assert ! ( !ptr. is_null( ) ) ;
326- unsafe { NonNull :: new_unchecked ( ptr) }
327- }
328-
329- // SAFETY: caller must guarantee that the implicit argument at `index`
330- // contains a valid V8 handle.
331- #[ inline( always) ]
332- unsafe fn get_implicit_arg_local < T > ( & self , index : i32 ) -> Local < ' _ , T > {
333- let nn = self . get_implicit_arg_non_null :: < T > ( index) ;
334- unsafe { Local :: from_non_null ( nn) }
335- }
336-
337- // SAFETY: caller must guarantee that the `index` value lies between -1 and
338- // self.length.
339- #[ inline( always) ]
340- unsafe fn get_arg_local < T > ( & self , index : i32 ) -> Local < ' _ , T > {
341- let ptr = unsafe { self . values . offset ( index as _ ) } as * mut T ;
342- debug_assert ! ( !ptr. is_null( ) ) ;
343- let nn = unsafe { NonNull :: new_unchecked ( ptr) } ;
344- unsafe { Local :: from_non_null ( nn) }
345- }
346309}
347310
348311#[ repr( C ) ]
349312#[ derive( Debug ) ]
350- struct RawPropertyCallbackInfo ( Opaque ) ;
313+ struct RawPropertyCallbackInfo ( * mut Opaque ) ;
351314
352315/// The information passed to a property callback about the context
353316/// of the property access.
0 commit comments