From c21a52f415d89befab572054740589cde9be578b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 1 May 2018 17:24:41 +0200 Subject: [PATCH] src: access `ContextifyContext*` more directly in property cbs PR-URL: https://github.com/nodejs/node/pull/20455 Fixes: https://github.com/nodejs/node/issues/18897 Reviewed-By: Gus Caplan Reviewed-By: Ben Noordhuis Reviewed-By: Daniel Bevenius --- src/node_contextify.cc | 43 ++++++++++++++++++++---------------------- src/node_contextify.h | 3 +++ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/node_contextify.cc b/src/node_contextify.cc index e07d5ebcd29d0d..62a9416d325065 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -120,7 +120,7 @@ Local ContextifyContext::CreateDataWrapper(Environment* env) { if (wrapper.IsEmpty()) return scope.Escape(Local::New(env->isolate(), Local())); - Wrap(wrapper, this); + wrapper->SetAlignedPointerInInternalField(0, this); return scope.Escape(wrapper); } @@ -290,12 +290,19 @@ ContextifyContext* ContextifyContext::ContextFromContextifiedSandbox( return nullptr; } +// static +template +ContextifyContext* ContextifyContext::Get(const PropertyCallbackInfo& args) { + Local data = args.Data(); + return static_cast( + data.As()->GetAlignedPointerFromInternalField(0)); +} + // static void ContextifyContext::PropertyGetterCallback( Local property, const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) @@ -324,8 +331,7 @@ void ContextifyContext::PropertySetterCallback( Local property, Local value, const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) @@ -385,8 +391,7 @@ void ContextifyContext::PropertySetterCallback( void ContextifyContext::PropertyDescriptorCallback( Local property, const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) @@ -408,8 +413,7 @@ void ContextifyContext::PropertyDefinerCallback( Local property, const PropertyDescriptor& desc, const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) @@ -471,8 +475,7 @@ void ContextifyContext::PropertyDefinerCallback( void ContextifyContext::PropertyDeleterCallback( Local property, const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) @@ -491,8 +494,7 @@ void ContextifyContext::PropertyDeleterCallback( // static void ContextifyContext::PropertyEnumeratorCallback( const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) @@ -505,8 +507,7 @@ void ContextifyContext::PropertyEnumeratorCallback( void ContextifyContext::IndexedPropertyGetterCallback( uint32_t index, const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) @@ -521,8 +522,7 @@ void ContextifyContext::IndexedPropertySetterCallback( uint32_t index, Local value, const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) @@ -536,8 +536,7 @@ void ContextifyContext::IndexedPropertySetterCallback( void ContextifyContext::IndexedPropertyDescriptorCallback( uint32_t index, const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) @@ -552,8 +551,7 @@ void ContextifyContext::IndexedPropertyDefinerCallback( uint32_t index, const PropertyDescriptor& desc, const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) @@ -567,8 +565,7 @@ void ContextifyContext::IndexedPropertyDefinerCallback( void ContextifyContext::IndexedPropertyDeleterCallback( uint32_t index, const PropertyCallbackInfo& args) { - ContextifyContext* ctx; - ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As()); + ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing if (ctx->context_.IsEmpty()) diff --git a/src/node_contextify.h b/src/node_contextify.h index 565b8ef856ea49..70ce091af3b58e 100644 --- a/src/node_contextify.h +++ b/src/node_contextify.h @@ -55,6 +55,9 @@ class ContextifyContext { context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject)); } + template + static ContextifyContext* Get(const v8::PropertyCallbackInfo& args); + private: static void MakeContext(const v8::FunctionCallbackInfo& args); static void IsContext(const v8::FunctionCallbackInfo& args);