@@ -258,130 +258,32 @@ void php_v8_bucket_gc(php_v8_callbacks_bucket_t *bucket, zval **gc_data, int * g
258
258
*n = *gc_data_count;
259
259
}
260
260
261
- void php_v8_callback_set_retval_from_callback_info (v8::ReturnValue<void > retval, php_v8_return_value_t *return_value) {
262
- if (!return_value->type ) {
263
- return ;
264
- }
265
-
266
- switch (return_value->type ) {
267
- default :
268
- // should never get here, just in case new types will be added in future
269
- PHP_V8_THROW_EXCEPTION (" Failed to set returned value: unsupported type" );
270
- return ;
271
- break ;
272
- }
261
+ static inline void php_v8_callback_set_retval_from_callback_info (v8::ReturnValue<void > *rv, php_v8_return_value_t *php_v8_return_value) {
262
+ php_v8_return_value->accepts = PHP_V8_RETVAL_ACCEPTS_VOID;
263
+ php_v8_return_value->rv_void = rv;
273
264
}
274
265
275
- void php_v8_callback_set_retval_from_callback_info (v8::ReturnValue<v8::Value> retval, php_v8_return_value_t *return_value) {
276
- if (!return_value->type ) {
277
- return ;
278
- }
279
-
280
- switch (return_value->type ) {
281
- case PHP_V8_RETVAL_UNDEFINED:
282
- retval.SetUndefined ();
283
- break ;
284
- case PHP_V8_RETVAL_NULL:
285
- retval.SetNull ();
286
- break ;
287
- case PHP_V8_RETVAL_EMPTY_STRING:
288
- retval.SetEmptyString ();
289
- break ;
290
- case PHP_V8_RETVAL_BOOL:
291
- retval.Set (return_value->value .set_bool );
292
- break ;
293
- case PHP_V8_RETVAL_INT32:
294
- retval.Set (return_value->value .set_int32 );
295
- break ;
296
- case PHP_V8_RETVAL_UINT32:
297
- retval.Set (return_value->value .set_uint32 );
298
- break ;
299
- case PHP_V8_RETVAL_LONG:
300
- retval.Set (static_cast <double >(return_value->value .set_long ));
301
-
302
- break ;
303
- case PHP_V8_RETVAL_DOUBLE:
304
- retval.Set (return_value->value .set_double );
305
- break ;
306
- case PHP_V8_RETVAL_V8_VALUE:
307
- retval.Set (php_v8_value_get_value_local (retval.GetIsolate (),
308
- PHP_V8_VALUE_FETCH (&return_value->value .php_v8_value_zv )));
309
- break ;
310
- default :
311
- // should never get here, just in case new types will be added in future
312
-
313
- // TODO: maybe value exception?
314
- PHP_V8_THROW_EXCEPTION (" Failed to set returned value: unsupported type" );
315
- return ;
316
- break ;
317
- }
266
+ static inline void php_v8_callback_set_retval_from_callback_info (v8::ReturnValue<v8::Value> *rv, php_v8_return_value_t *php_v8_return_value) {
267
+ php_v8_return_value->accepts = PHP_V8_RETVAL_ACCEPTS_ANY;
268
+ php_v8_return_value->rv_any = rv;
318
269
}
319
270
320
- void php_v8_callback_set_retval_from_callback_info (v8::ReturnValue<v8::Array> retval, php_v8_return_value_t *return_value) {
321
- if (!return_value->type ) {
322
- return ;
323
- }
324
-
325
- switch (return_value->type ) {
326
- case PHP_V8_RETVAL_V8_VALUE:
327
- retval.Set (php_v8_value_get_array_local (retval.GetIsolate (),
328
- PHP_V8_VALUE_FETCH (&return_value->value .php_v8_value_zv )));
329
- break ;
330
- default :
331
- // should never get here, just in case new types will be added in future
332
- PHP_V8_THROW_EXCEPTION (" Failed to set returned value: unsupported type" );
333
- return ;
334
- break ;
335
- }
271
+ static inline void php_v8_callback_set_retval_from_callback_info (v8::ReturnValue<v8::Integer> *rv, php_v8_return_value_t *php_v8_return_value) {
272
+ php_v8_return_value->accepts = PHP_V8_RETVAL_ACCEPTS_INTEGER;
273
+ php_v8_return_value->rv_integer = rv;
336
274
}
337
275
338
- void php_v8_callback_set_retval_from_callback_info (v8::ReturnValue<v8::Integer> retval, php_v8_return_value_t *return_value) {
339
- if (!return_value->type ) {
340
- return ;
341
- }
342
-
343
- switch (return_value->type ) {
344
- case PHP_V8_RETVAL_INT32:
345
- retval.Set (return_value->value .set_int32 );
346
- break ;
347
- case PHP_V8_RETVAL_UINT32:
348
- retval.Set (return_value->value .set_uint32 );
349
- break ;
350
- case PHP_V8_RETVAL_V8_VALUE:
351
- retval.Set (php_v8_value_get_integer_local (retval.GetIsolate (),
352
- PHP_V8_VALUE_FETCH (&return_value->value .php_v8_value_zv )));
353
- break ;
354
- default :
355
- // should never get here, just in case new types will be added in future
356
- PHP_V8_THROW_EXCEPTION (" Failed to set returned value: unsupported type" );
357
- return ;
358
- break ;
359
- }
276
+ static inline void php_v8_callback_set_retval_from_callback_info (v8::ReturnValue<v8::Boolean> *rv, php_v8_return_value_t *php_v8_return_value) {
277
+ php_v8_return_value->accepts = PHP_V8_RETVAL_ACCEPTS_BOOLEAN;
278
+ php_v8_return_value->rv_boolean = rv;
360
279
}
361
280
362
- void php_v8_callback_set_retval_from_callback_info (v8::ReturnValue<v8::Boolean> retval, php_v8_return_value_t *return_value) {
363
- if (!return_value->type ) {
364
- return ;
365
- }
366
-
367
- switch (return_value->type ) {
368
- case PHP_V8_RETVAL_BOOL:
369
- retval.Set (return_value->value .set_bool );
370
- break ;
371
- case PHP_V8_RETVAL_V8_VALUE:
372
- retval.Set (php_v8_value_get_boolean_local (retval.GetIsolate (),
373
- PHP_V8_VALUE_FETCH (&return_value->value .php_v8_value_zv )));
374
- break ;
375
- default :
376
- // should never get here, just in case new types will be added in future
377
- PHP_V8_THROW_EXCEPTION (" Failed to set returned value: unsupported type" );
378
- return ;
379
- break ;
380
- }
281
+ static inline void php_v8_callback_set_retval_from_callback_info (v8::ReturnValue<v8::Array> *rv, php_v8_return_value_t *php_v8_return_value) {
282
+ php_v8_return_value->accepts = PHP_V8_RETVAL_ACCEPTS_ARRAY;
283
+ php_v8_return_value->rv_array = rv;
381
284
}
382
285
383
286
384
-
385
287
void php_v8_callback_call_from_bucket_with_zargs (size_t index, v8::Local<v8::Value> data, zval *args, zval *retval) {
386
288
php_v8_callbacks_bucket_t *bucket;
387
289
@@ -416,8 +318,8 @@ void php_v8_callback_call_from_bucket_with_zargs(size_t index, v8::Local<v8::Val
416
318
zend_fcall_info_args_clear (&fci, 1 );
417
319
}
418
320
419
- template <class T >
420
- void php_v8_callback_call_from_bucket_with_zargs (size_t index, const T &info, zval *args) {
321
+ template <class T , class M >
322
+ void php_v8_callback_call_from_bucket_with_zargs (size_t index, const T &info, M rv, zval *args) {
421
323
zval callback_info;
422
324
php_v8_callback_info_t *php_v8_callback_info;
423
325
// Wrap callback info
@@ -429,15 +331,14 @@ void php_v8_callback_call_from_bucket_with_zargs(size_t index, const T &info, zv
429
331
430
332
add_next_index_zval (args, &callback_info);
431
333
432
- php_v8_callback_call_from_bucket_with_zargs (index, info. Data (), args, NULL );
334
+ php_v8_callback_set_retval_from_callback_info (&rv, php_v8_callback_info-> php_v8_return_value );
433
335
434
- php_v8_callback_set_retval_from_callback_info ( info.GetReturnValue (), php_v8_callback_info-> php_v8_return_value );
336
+ php_v8_callback_call_from_bucket_with_zargs (index, info.Data (), args, NULL );
435
337
436
338
php_v8_callback_info_invalidate (php_v8_callback_info);
437
339
}
438
340
439
341
440
-
441
342
void php_v8_callback_function (const v8::FunctionCallbackInfo<v8::Value> &info) {
442
343
PHP_V8_DECLARE_ISOLATE_LOCAL_ALIAS (info.GetIsolate ());
443
344
@@ -446,7 +347,7 @@ void php_v8_callback_function(const v8::FunctionCallbackInfo<v8::Value> &info) {
446
347
/* Build the parameter array */
447
348
array_init_size (&args, 1 );
448
349
449
- php_v8_callback_call_from_bucket_with_zargs (0 , info, &args);
350
+ php_v8_callback_call_from_bucket_with_zargs (0 , info, info. GetReturnValue (), &args);
450
351
451
352
zval_ptr_dtor (&args);
452
353
}
@@ -463,7 +364,7 @@ void php_v8_callback_accessor_name_getter(v8::Local<v8::Name> property, const v8
463
364
php_v8_get_or_create_value (&property_name, property, isolate);
464
365
add_index_zval (&args, 0 , &property_name);
465
366
466
- php_v8_callback_call_from_bucket_with_zargs (0 , info, &args);
367
+ php_v8_callback_call_from_bucket_with_zargs (0 , info, info. GetReturnValue (), &args);
467
368
468
369
zval_ptr_dtor (&args);
469
370
}
@@ -484,7 +385,7 @@ void php_v8_callback_accessor_name_setter(v8::Local<v8::Name> property, v8::Loca
484
385
add_index_zval (&args, 0 , &property_name);
485
386
add_index_zval (&args, 1 , &property_value);
486
387
487
- php_v8_callback_call_from_bucket_with_zargs (1 , info, &args);
388
+ php_v8_callback_call_from_bucket_with_zargs (1 , info, info. GetReturnValue (), &args);
488
389
489
390
zval_ptr_dtor (&args);
490
391
}
@@ -502,7 +403,7 @@ void php_v8_callback_generic_named_property_getter(v8::Local<v8::Name> property,
502
403
php_v8_get_or_create_value (&property_name, property, isolate);
503
404
add_index_zval (&args, 0 , &property_name);
504
405
505
- php_v8_callback_call_from_bucket_with_zargs (0 , info, &args);
406
+ php_v8_callback_call_from_bucket_with_zargs (0 , info, info. GetReturnValue (), &args);
506
407
507
408
zval_ptr_dtor (&args);
508
409
}
@@ -523,7 +424,7 @@ void php_v8_callback_generic_named_property_setter(v8::Local<v8::Name> property,
523
424
add_index_zval (&args, 0 , &property_name);
524
425
add_index_zval (&args, 1 , &property_value);
525
426
526
- php_v8_callback_call_from_bucket_with_zargs (1 , info, &args);
427
+ php_v8_callback_call_from_bucket_with_zargs (1 , info, info. GetReturnValue (), &args);
527
428
528
429
zval_ptr_dtor (&args);
529
430
}
@@ -540,7 +441,7 @@ void php_v8_callback_generic_named_property_query(v8::Local<v8::Name> property,
540
441
php_v8_get_or_create_value (&property_name, property, isolate);
541
442
add_index_zval (&args, 0 , &property_name);
542
443
543
- php_v8_callback_call_from_bucket_with_zargs (2 , info, &args);
444
+ php_v8_callback_call_from_bucket_with_zargs (2 , info, info. GetReturnValue (), &args);
544
445
545
446
zval_ptr_dtor (&args);
546
447
}
@@ -557,7 +458,7 @@ void php_v8_callback_generic_named_property_deleter(v8::Local<v8::Name> property
557
458
php_v8_get_or_create_value (&property_name, property, isolate);
558
459
add_index_zval (&args, 0 , &property_name);
559
460
560
- php_v8_callback_call_from_bucket_with_zargs (3 , info, &args);
461
+ php_v8_callback_call_from_bucket_with_zargs (3 , info, info. GetReturnValue (), &args);
561
462
562
463
zval_ptr_dtor (&args);
563
464
}
@@ -570,7 +471,7 @@ void php_v8_callback_generic_named_property_enumerator(const v8::PropertyCallbac
570
471
/* Build the parameter array */
571
472
array_init_size (&args, 1 );
572
473
573
- php_v8_callback_call_from_bucket_with_zargs (4 , info, &args);
474
+ php_v8_callback_call_from_bucket_with_zargs (4 , info, info. GetReturnValue (), &args);
574
475
575
476
zval_ptr_dtor (&args);
576
477
}
@@ -589,7 +490,7 @@ void php_v8_callback_indexed_property_getter(uint32_t index, const v8::PropertyC
589
490
ZVAL_LONG (&property_name, index);
590
491
add_index_zval (&args, 0 , &property_name);
591
492
592
- php_v8_callback_call_from_bucket_with_zargs (0 , info, &args);
493
+ php_v8_callback_call_from_bucket_with_zargs (0 , info, info. GetReturnValue (), &args);
593
494
594
495
zval_ptr_dtor (&args);
595
496
}
@@ -610,7 +511,7 @@ void php_v8_callback_indexed_property_setter(uint32_t index, v8::Local<v8::Value
610
511
add_index_zval (&args, 0 , &property_name);
611
512
add_index_zval (&args, 1 , &property_value);
612
513
613
- php_v8_callback_call_from_bucket_with_zargs (1 , info, &args);
514
+ php_v8_callback_call_from_bucket_with_zargs (1 , info, info. GetReturnValue (), &args);
614
515
615
516
zval_ptr_dtor (&args);
616
517
}
@@ -627,7 +528,7 @@ void php_v8_callback_indexed_property_query(uint32_t index, const v8::PropertyCa
627
528
ZVAL_LONG (&property_name, index);
628
529
add_index_zval (&args, 0 , &property_name);
629
530
630
- php_v8_callback_call_from_bucket_with_zargs (2 , info, &args);
531
+ php_v8_callback_call_from_bucket_with_zargs (2 , info, info. GetReturnValue (), &args);
631
532
632
533
zval_ptr_dtor (&args);
633
534
}
@@ -644,7 +545,7 @@ void php_v8_callback_indexed_property_deleter(uint32_t index, const v8::Property
644
545
ZVAL_LONG (&property_name, index);
645
546
add_index_zval (&args, 0 , &property_name);
646
547
647
- php_v8_callback_call_from_bucket_with_zargs (3 , info, &args);
548
+ php_v8_callback_call_from_bucket_with_zargs (3 , info, info. GetReturnValue (), &args);
648
549
649
550
zval_ptr_dtor (&args);
650
551
}
@@ -657,7 +558,7 @@ void php_v8_callback_indexed_property_enumerator(const v8::PropertyCallbackInfo<
657
558
/* Build the parameter array */
658
559
array_init_size (&args, 1 );
659
560
660
- php_v8_callback_call_from_bucket_with_zargs (4 , info, &args);
561
+ php_v8_callback_call_from_bucket_with_zargs (4 , info, info. GetReturnValue (), &args);
661
562
662
563
zval_ptr_dtor (&args);
663
564
}
0 commit comments