@@ -120,7 +120,7 @@ Local<Value> ContextifyContext::CreateDataWrapper(Environment* env) {
120120if (wrapper.IsEmpty ())
121121return scope.Escape (Local<Value>::New (env->isolate (), Local<Value>()));
122122
123- Wrap ( wrapper, this );
123+ wrapper-> SetAlignedPointerInInternalField ( 0 , this );
124124return scope.Escape (wrapper);
125125}
126126
@@ -290,12 +290,19 @@ ContextifyContext* ContextifyContext::ContextFromContextifiedSandbox(
290290return nullptr ;
291291}
292292
293+ // static
294+ template <typename T>
295+ ContextifyContext* ContextifyContext::Get (const PropertyCallbackInfo<T>& args) {
296+ Local<Value> data = args.Data ();
297+ return static_cast <ContextifyContext*>(
298+ data.As <Object>()->GetAlignedPointerFromInternalField (0 ));
299+ }
300+
293301// static
294302void ContextifyContext::PropertyGetterCallback (
295303 Local<Name> property,
296304const PropertyCallbackInfo<Value>& args) {
297- ContextifyContext* ctx;
298- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
305+ ContextifyContext* ctx = ContextifyContext::Get (args);
299306
300307// Still initializing
301308if (ctx->context_ .IsEmpty ())
@@ -324,8 +331,7 @@ void ContextifyContext::PropertySetterCallback(
324331 Local<Name> property,
325332 Local<Value> value,
326333const PropertyCallbackInfo<Value>& args) {
327- ContextifyContext* ctx;
328- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
334+ ContextifyContext* ctx = ContextifyContext::Get (args);
329335
330336// Still initializing
331337if (ctx->context_ .IsEmpty ())
@@ -385,8 +391,7 @@ void ContextifyContext::PropertySetterCallback(
385391void ContextifyContext::PropertyDescriptorCallback (
386392 Local<Name> property,
387393const PropertyCallbackInfo<Value>& args) {
388- ContextifyContext* ctx;
389- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
394+ ContextifyContext* ctx = ContextifyContext::Get (args);
390395
391396// Still initializing
392397if (ctx->context_ .IsEmpty ())
@@ -408,8 +413,7 @@ void ContextifyContext::PropertyDefinerCallback(
408413 Local<Name> property,
409414const PropertyDescriptor& desc,
410415const PropertyCallbackInfo<Value>& args) {
411- ContextifyContext* ctx;
412- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
416+ ContextifyContext* ctx = ContextifyContext::Get (args);
413417
414418// Still initializing
415419if (ctx->context_ .IsEmpty ())
@@ -471,8 +475,7 @@ void ContextifyContext::PropertyDefinerCallback(
471475void ContextifyContext::PropertyDeleterCallback (
472476 Local<Name> property,
473477const PropertyCallbackInfo<Boolean>& args) {
474- ContextifyContext* ctx;
475- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
478+ ContextifyContext* ctx = ContextifyContext::Get (args);
476479
477480// Still initializing
478481if (ctx->context_ .IsEmpty ())
@@ -491,8 +494,7 @@ void ContextifyContext::PropertyDeleterCallback(
491494// static
492495void ContextifyContext::PropertyEnumeratorCallback (
493496const PropertyCallbackInfo<Array>& args) {
494- ContextifyContext* ctx;
495- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
497+ ContextifyContext* ctx = ContextifyContext::Get (args);
496498
497499// Still initializing
498500if (ctx->context_ .IsEmpty ())
@@ -505,8 +507,7 @@ void ContextifyContext::PropertyEnumeratorCallback(
505507void ContextifyContext::IndexedPropertyGetterCallback (
506508uint32_t index,
507509const PropertyCallbackInfo<Value>& args) {
508- ContextifyContext* ctx;
509- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
510+ ContextifyContext* ctx = ContextifyContext::Get (args);
510511
511512// Still initializing
512513if (ctx->context_ .IsEmpty ())
@@ -521,8 +522,7 @@ void ContextifyContext::IndexedPropertySetterCallback(
521522uint32_t index,
522523 Local<Value> value,
523524const PropertyCallbackInfo<Value>& args) {
524- ContextifyContext* ctx;
525- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
525+ ContextifyContext* ctx = ContextifyContext::Get (args);
526526
527527// Still initializing
528528if (ctx->context_ .IsEmpty ())
@@ -536,8 +536,7 @@ void ContextifyContext::IndexedPropertySetterCallback(
536536void ContextifyContext::IndexedPropertyDescriptorCallback (
537537uint32_t index,
538538const PropertyCallbackInfo<Value>& args) {
539- ContextifyContext* ctx;
540- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
539+ ContextifyContext* ctx = ContextifyContext::Get (args);
541540
542541// Still initializing
543542if (ctx->context_ .IsEmpty ())
@@ -552,8 +551,7 @@ void ContextifyContext::IndexedPropertyDefinerCallback(
552551uint32_t index,
553552const PropertyDescriptor& desc,
554553const PropertyCallbackInfo<Value>& args) {
555- ContextifyContext* ctx;
556- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
554+ ContextifyContext* ctx = ContextifyContext::Get (args);
557555
558556// Still initializing
559557if (ctx->context_ .IsEmpty ())
@@ -567,8 +565,7 @@ void ContextifyContext::IndexedPropertyDefinerCallback(
567565void ContextifyContext::IndexedPropertyDeleterCallback (
568566uint32_t index,
569567const PropertyCallbackInfo<Boolean>& args) {
570- ContextifyContext* ctx;
571- ASSIGN_OR_RETURN_UNWRAP (&ctx, args.Data ().As <Object>());
568+ ContextifyContext* ctx = ContextifyContext::Get (args);
572569
573570// Still initializing
574571if (ctx->context_ .IsEmpty ())
0 commit comments