@@ -179,13 +179,28 @@ class PropertyCallbackInfo {
179179};
180180
181181namespace imp {
182+
183+ // v8::External::Value() gained an ExternalPointerTypeTag parameter in V8 13.
184+ // Centralize the version split here so the trampolines below can call the
185+ // accessor uniformly without scattering preprocessor blocks across every
186+ // callsite. Externals created by nan use kExternalPointerTypeTagDefault
187+ // (see imp::NewExternal in nan_implementation_12_inl.h), so the same tag
188+ // is used here on read.
189+ inline void * GetExternalPointer (v8::Local<v8::External> ext) {
190+ #if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >= 13
191+ return ext->Value (v8::kExternalPointerTypeTagDefault );
192+ #else
193+ return ext->Value ();
194+ #endif
195+ }
196+
182197static
183198void FunctionCallbackWrapper (const v8::FunctionCallbackInfo<v8::Value> &info) {
184199 v8::Local<v8::Object> obj = info.Data ().As <v8::Object>();
185200 FunctionCallback callback = reinterpret_cast <FunctionCallback>(
186201 reinterpret_cast <intptr_t >(
187- obj->GetInternalField (kFunctionIndex )
188- .As <v8::Value>().As <v8::External>()-> Value ( )));
202+ imp::GetExternalPointer ( obj->GetInternalField (kFunctionIndex )
203+ .As <v8::Value>().As <v8::External>())));
189204 FunctionCallbackInfo<v8::Value>
190205 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
191206 callback (cbinfo);
@@ -203,8 +218,8 @@ void GetterCallbackWrapper(
203218 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
204219 GetterCallback callback = reinterpret_cast <GetterCallback>(
205220 reinterpret_cast <intptr_t >(
206- obj->GetInternalField (kGetterIndex )
207- .As <v8::Value>().As <v8::External>()-> Value ( )));
221+ imp::GetExternalPointer ( obj->GetInternalField (kGetterIndex )
222+ .As <v8::Value>().As <v8::External>())));
208223 callback (property.As <v8::String>(), cbinfo);
209224}
210225
@@ -221,8 +236,8 @@ void SetterCallbackWrapper(
221236 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
222237 SetterCallback callback = reinterpret_cast <SetterCallback>(
223238 reinterpret_cast <intptr_t >(
224- obj->GetInternalField (kSetterIndex )
225- .As <v8::Value>().As <v8::External>()-> Value ( )));
239+ imp::GetExternalPointer ( obj->GetInternalField (kSetterIndex )
240+ .As <v8::Value>().As <v8::External>())));
226241 callback (property.As <v8::String>(), value, cbinfo);
227242}
228243
@@ -240,8 +255,8 @@ void GetterCallbackWrapper(
240255 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
241256 GetterCallback callback = reinterpret_cast <GetterCallback>(
242257 reinterpret_cast <intptr_t >(
243- obj->GetInternalField (kGetterIndex )
244- .As <v8::Value>().As <v8::External>()-> Value ( )));
258+ imp::GetExternalPointer ( obj->GetInternalField (kGetterIndex )
259+ .As <v8::Value>().As <v8::External>())));
245260 callback (property, cbinfo);
246261}
247262
@@ -258,8 +273,8 @@ void SetterCallbackWrapper(
258273 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
259274 SetterCallback callback = reinterpret_cast <SetterCallback>(
260275 reinterpret_cast <intptr_t >(
261- obj->GetInternalField (kSetterIndex )
262- .As <v8::Value>().As <v8::External>()-> Value ( )));
276+ imp::GetExternalPointer ( obj->GetInternalField (kSetterIndex )
277+ .As <v8::Value>().As <v8::External>())));
263278 callback (property, value, cbinfo);
264279}
265280
@@ -282,8 +297,8 @@ v8::Intercepted PropertyGetterCallbackWrapper(
282297 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
283298 PropertyGetterCallback callback = reinterpret_cast <PropertyGetterCallback>(
284299 reinterpret_cast <intptr_t >(
285- obj->GetInternalField (kPropertyGetterIndex )
286- .As <v8::Value>().As <v8::External>()-> Value ( )));
300+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyGetterIndex )
301+ .As <v8::Value>().As <v8::External>())));
287302 return callback (property.As <v8::String>(), cbinfo);
288303}
289304
@@ -300,8 +315,8 @@ v8::Intercepted PropertySetterCallbackWrapper(
300315 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
301316 PropertySetterCallback callback = reinterpret_cast <PropertySetterCallback>(
302317 reinterpret_cast <intptr_t >(
303- obj->GetInternalField (kPropertySetterIndex )
304- .As <v8::Value>().As <v8::External>()-> Value ( )));
318+ imp::GetExternalPointer ( obj->GetInternalField (kPropertySetterIndex )
319+ .As <v8::Value>().As <v8::External>())));
305320 return callback (property.As <v8::String>(), value, cbinfo);
306321}
307322
@@ -320,8 +335,8 @@ void PropertyGetterCallbackWrapper(
320335 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
321336 PropertyGetterCallback callback = reinterpret_cast <PropertyGetterCallback>(
322337 reinterpret_cast <intptr_t >(
323- obj->GetInternalField (kPropertyGetterIndex )
324- .As <v8::Value>().As <v8::External>()-> Value ( )));
338+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyGetterIndex )
339+ .As <v8::Value>().As <v8::External>())));
325340 callback (property.As <v8::String>(), cbinfo);
326341}
327342
@@ -338,8 +353,8 @@ void PropertySetterCallbackWrapper(
338353 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
339354 PropertySetterCallback callback = reinterpret_cast <PropertySetterCallback>(
340355 reinterpret_cast <intptr_t >(
341- obj->GetInternalField (kPropertySetterIndex )
342- .As <v8::Value>().As <v8::External>()-> Value ( )));
356+ imp::GetExternalPointer ( obj->GetInternalField (kPropertySetterIndex )
357+ .As <v8::Value>().As <v8::External>())));
343358 callback (property.As <v8::String>(), value, cbinfo);
344359}
345360
@@ -357,8 +372,8 @@ void PropertyEnumeratorCallbackWrapper(
357372 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
358373 PropertyEnumeratorCallback callback =
359374 reinterpret_cast <PropertyEnumeratorCallback>(reinterpret_cast <intptr_t >(
360- obj->GetInternalField (kPropertyEnumeratorIndex )
361- .As <v8::Value>().As <v8::External>()-> Value ( )));
375+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyEnumeratorIndex )
376+ .As <v8::Value>().As <v8::External>())));
362377 callback (cbinfo);
363378}
364379
@@ -376,8 +391,8 @@ v8::Intercepted PropertyDeleterCallbackWrapper(
376391 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
377392 PropertyDeleterCallback callback = reinterpret_cast <PropertyDeleterCallback>(
378393 reinterpret_cast <intptr_t >(
379- obj->GetInternalField (kPropertyDeleterIndex )
380- .As <v8::Value>().As <v8::External>()-> Value ( )));
394+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyDeleterIndex )
395+ .As <v8::Value>().As <v8::External>())));
381396 return callback (property.As <v8::String>(), cbinfo);
382397}
383398
@@ -394,8 +409,8 @@ v8::Intercepted PropertyQueryCallbackWrapper(
394409 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
395410 PropertyQueryCallback callback = reinterpret_cast <PropertyQueryCallback>(
396411 reinterpret_cast <intptr_t >(
397- obj->GetInternalField (kPropertyQueryIndex )
398- .As <v8::Value>().As <v8::External>()-> Value ( )));
412+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyQueryIndex )
413+ .As <v8::Value>().As <v8::External>())));
399414 return callback (property.As <v8::String>(), cbinfo);
400415}
401416
@@ -411,8 +426,8 @@ void PropertyDeleterCallbackWrapper(
411426 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
412427 PropertyDeleterCallback callback = reinterpret_cast <PropertyDeleterCallback>(
413428 reinterpret_cast <intptr_t >(
414- obj->GetInternalField (kPropertyDeleterIndex )
415- .As <v8::Value>().As <v8::External>()-> Value ( )));
429+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyDeleterIndex )
430+ .As <v8::Value>().As <v8::External>())));
416431 callback (property.As <v8::String>(), cbinfo);
417432}
418433
@@ -428,8 +443,8 @@ void PropertyQueryCallbackWrapper(
428443 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
429444 PropertyQueryCallback callback = reinterpret_cast <PropertyQueryCallback>(
430445 reinterpret_cast <intptr_t >(
431- obj->GetInternalField (kPropertyQueryIndex )
432- .As <v8::Value>().As <v8::External>()-> Value ( )));
446+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyQueryIndex )
447+ .As <v8::Value>().As <v8::External>())));
433448 callback (property.As <v8::String>(), cbinfo);
434449}
435450
@@ -446,8 +461,8 @@ void PropertyGetterCallbackWrapper(
446461 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
447462 PropertyGetterCallback callback = reinterpret_cast <PropertyGetterCallback>(
448463 reinterpret_cast <intptr_t >(
449- obj->GetInternalField (kPropertyGetterIndex )
450- .As <v8::Value>().As <v8::External>()-> Value ( )));
464+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyGetterIndex )
465+ .As <v8::Value>().As <v8::External>())));
451466 callback (property, cbinfo);
452467}
453468
@@ -464,8 +479,8 @@ void PropertySetterCallbackWrapper(
464479 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
465480 PropertySetterCallback callback = reinterpret_cast <PropertySetterCallback>(
466481 reinterpret_cast <intptr_t >(
467- obj->GetInternalField (kPropertySetterIndex )
468- .As <v8::Value>().As <v8::External>()-> Value ( )));
482+ imp::GetExternalPointer ( obj->GetInternalField (kPropertySetterIndex )
483+ .As <v8::Value>().As <v8::External>())));
469484 callback (property, value, cbinfo);
470485}
471486
@@ -482,8 +497,8 @@ void PropertyEnumeratorCallbackWrapper(
482497 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
483498 PropertyEnumeratorCallback callback =
484499 reinterpret_cast <PropertyEnumeratorCallback>(reinterpret_cast <intptr_t >(
485- obj->GetInternalField (kPropertyEnumeratorIndex )
486- .As <v8::Value>().As <v8::External>()-> Value ( )));
500+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyEnumeratorIndex )
501+ .As <v8::Value>().As <v8::External>())));
487502 callback (cbinfo);
488503}
489504
@@ -499,8 +514,8 @@ void PropertyDeleterCallbackWrapper(
499514 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
500515 PropertyDeleterCallback callback = reinterpret_cast <PropertyDeleterCallback>(
501516 reinterpret_cast <intptr_t >(
502- obj->GetInternalField (kPropertyDeleterIndex )
503- .As <v8::Value>().As <v8::External>()-> Value ( )));
517+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyDeleterIndex )
518+ .As <v8::Value>().As <v8::External>())));
504519 callback (property, cbinfo);
505520}
506521
@@ -516,8 +531,8 @@ void PropertyQueryCallbackWrapper(
516531 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
517532 PropertyQueryCallback callback = reinterpret_cast <PropertyQueryCallback>(
518533 reinterpret_cast <intptr_t >(
519- obj->GetInternalField (kPropertyQueryIndex )
520- .As <v8::Value>().As <v8::External>()-> Value ( )));
534+ imp::GetExternalPointer ( obj->GetInternalField (kPropertyQueryIndex )
535+ .As <v8::Value>().As <v8::External>())));
521536 callback (property, cbinfo);
522537}
523538
@@ -535,8 +550,8 @@ v8::Intercepted IndexGetterCallbackWrapper(
535550 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
536551 IndexGetterCallback callback = reinterpret_cast <IndexGetterCallback>(
537552 reinterpret_cast <intptr_t >(
538- obj->GetInternalField (kIndexPropertyGetterIndex )
539- .As <v8::Value>().As <v8::External>()-> Value ( )));
553+ imp::GetExternalPointer ( obj->GetInternalField (kIndexPropertyGetterIndex )
554+ .As <v8::Value>().As <v8::External>())));
540555 return callback (index, cbinfo);
541556}
542557
@@ -553,8 +568,8 @@ v8::Intercepted IndexSetterCallbackWrapper(
553568 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
554569 IndexSetterCallback callback = reinterpret_cast <IndexSetterCallback>(
555570 reinterpret_cast <intptr_t >(
556- obj->GetInternalField (kIndexPropertySetterIndex )
557- .As <v8::Value>().As <v8::External>()-> Value ( )));
571+ imp::GetExternalPointer ( obj->GetInternalField (kIndexPropertySetterIndex )
572+ .As <v8::Value>().As <v8::External>())));
558573 return callback (index, value, cbinfo);
559574}
560575
@@ -572,8 +587,8 @@ void IndexGetterCallbackWrapper(
572587 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
573588 IndexGetterCallback callback = reinterpret_cast <IndexGetterCallback>(
574589 reinterpret_cast <intptr_t >(
575- obj->GetInternalField (kIndexPropertyGetterIndex )
576- .As <v8::Value>().As <v8::External>()-> Value ( )));
590+ imp::GetExternalPointer ( obj->GetInternalField (kIndexPropertyGetterIndex )
591+ .As <v8::Value>().As <v8::External>())));
577592 callback (index, cbinfo);
578593}
579594
@@ -589,8 +604,8 @@ void IndexSetterCallbackWrapper(
589604 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
590605 IndexSetterCallback callback = reinterpret_cast <IndexSetterCallback>(
591606 reinterpret_cast <intptr_t >(
592- obj->GetInternalField (kIndexPropertySetterIndex )
593- .As <v8::Value>().As <v8::External>()-> Value ( )));
607+ imp::GetExternalPointer ( obj->GetInternalField (kIndexPropertySetterIndex )
608+ .As <v8::Value>().As <v8::External>())));
594609 callback (index, value, cbinfo);
595610}
596611
@@ -609,9 +624,9 @@ void IndexEnumeratorCallbackWrapper(
609624 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
610625 IndexEnumeratorCallback callback = reinterpret_cast <IndexEnumeratorCallback>(
611626 reinterpret_cast <intptr_t >(
612- obj->GetInternalField (
627+ imp::GetExternalPointer ( obj->GetInternalField (
613628 kIndexPropertyEnumeratorIndex )
614- .As <v8::Value>().As <v8::External>()-> Value ( )));
629+ .As <v8::Value>().As <v8::External>())));
615630 callback (cbinfo);
616631}
617632
@@ -628,8 +643,8 @@ v8::Intercepted IndexDeleterCallbackWrapper(
628643 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
629644 IndexDeleterCallback callback = reinterpret_cast <IndexDeleterCallback>(
630645 reinterpret_cast <intptr_t >(
631- obj->GetInternalField (kIndexPropertyDeleterIndex )
632- .As <v8::Value>().As <v8::External>()-> Value ( )));
646+ imp::GetExternalPointer ( obj->GetInternalField (kIndexPropertyDeleterIndex )
647+ .As <v8::Value>().As <v8::External>())));
633648 return callback (index, cbinfo);
634649}
635650
@@ -644,8 +659,8 @@ v8::Intercepted IndexQueryCallbackWrapper(
644659 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
645660 IndexQueryCallback callback = reinterpret_cast <IndexQueryCallback>(
646661 reinterpret_cast <intptr_t >(
647- obj->GetInternalField (kIndexPropertyQueryIndex )
648- .As <v8::Value>().As <v8::External>()-> Value ( )));
662+ imp::GetExternalPointer ( obj->GetInternalField (kIndexPropertyQueryIndex )
663+ .As <v8::Value>().As <v8::External>())));
649664 return callback (index, cbinfo);
650665}
651666
@@ -660,8 +675,8 @@ void IndexDeleterCallbackWrapper(
660675 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
661676 IndexDeleterCallback callback = reinterpret_cast <IndexDeleterCallback>(
662677 reinterpret_cast <intptr_t >(
663- obj->GetInternalField (kIndexPropertyDeleterIndex )
664- .As <v8::Value>().As <v8::External>()-> Value ( )));
678+ imp::GetExternalPointer ( obj->GetInternalField (kIndexPropertyDeleterIndex )
679+ .As <v8::Value>().As <v8::External>())));
665680 callback (index, cbinfo);
666681}
667682
@@ -676,8 +691,8 @@ void IndexQueryCallbackWrapper(
676691 cbinfo (info, obj->GetInternalField (kDataIndex ).As <v8::Value>());
677692 IndexQueryCallback callback = reinterpret_cast <IndexQueryCallback>(
678693 reinterpret_cast <intptr_t >(
679- obj->GetInternalField (kIndexPropertyQueryIndex )
680- .As <v8::Value>().As <v8::External>()-> Value ( )));
694+ imp::GetExternalPointer ( obj->GetInternalField (kIndexPropertyQueryIndex )
695+ .As <v8::Value>().As <v8::External>())));
681696 callback (index, cbinfo);
682697}
683698
0 commit comments