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 <me@gus.host>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit is contained in:
Anna Henningsen 2018-05-01 17:24:41 +02:00
parent 5512fff623
commit a9b0d8235d
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 23 additions and 23 deletions

View File

@ -121,7 +121,7 @@ Local<Value> ContextifyContext::CreateDataWrapper(Environment* env) {
if (wrapper.IsEmpty())
return scope.Escape(Local<Value>::New(env->isolate(), Local<Value>()));
Wrap(wrapper, this);
wrapper->SetAlignedPointerInInternalField(0, this);
return scope.Escape(wrapper);
}
@ -291,12 +291,19 @@ ContextifyContext* ContextifyContext::ContextFromContextifiedSandbox(
return nullptr;
}
// static
template <typename T>
ContextifyContext* ContextifyContext::Get(const PropertyCallbackInfo<T>& args) {
Local<Value> data = args.Data();
return static_cast<ContextifyContext*>(
data.As<Object>()->GetAlignedPointerFromInternalField(0));
}
// static
void ContextifyContext::PropertyGetterCallback(
Local<Name> property,
const PropertyCallbackInfo<Value>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())
@ -325,8 +332,7 @@ void ContextifyContext::PropertySetterCallback(
Local<Name> property,
Local<Value> value,
const PropertyCallbackInfo<Value>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())
@ -386,8 +392,7 @@ void ContextifyContext::PropertySetterCallback(
void ContextifyContext::PropertyDescriptorCallback(
Local<Name> property,
const PropertyCallbackInfo<Value>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())
@ -409,8 +414,7 @@ void ContextifyContext::PropertyDefinerCallback(
Local<Name> property,
const PropertyDescriptor& desc,
const PropertyCallbackInfo<Value>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())
@ -472,8 +476,7 @@ void ContextifyContext::PropertyDefinerCallback(
void ContextifyContext::PropertyDeleterCallback(
Local<Name> property,
const PropertyCallbackInfo<Boolean>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())
@ -492,8 +495,7 @@ void ContextifyContext::PropertyDeleterCallback(
// static
void ContextifyContext::PropertyEnumeratorCallback(
const PropertyCallbackInfo<Array>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())
@ -506,8 +508,7 @@ void ContextifyContext::PropertyEnumeratorCallback(
void ContextifyContext::IndexedPropertyGetterCallback(
uint32_t index,
const PropertyCallbackInfo<Value>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())
@ -522,8 +523,7 @@ void ContextifyContext::IndexedPropertySetterCallback(
uint32_t index,
Local<Value> value,
const PropertyCallbackInfo<Value>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())
@ -537,8 +537,7 @@ void ContextifyContext::IndexedPropertySetterCallback(
void ContextifyContext::IndexedPropertyDescriptorCallback(
uint32_t index,
const PropertyCallbackInfo<Value>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())
@ -553,8 +552,7 @@ void ContextifyContext::IndexedPropertyDefinerCallback(
uint32_t index,
const PropertyDescriptor& desc,
const PropertyCallbackInfo<Value>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())
@ -568,8 +566,7 @@ void ContextifyContext::IndexedPropertyDefinerCallback(
void ContextifyContext::IndexedPropertyDeleterCallback(
uint32_t index,
const PropertyCallbackInfo<Boolean>& args) {
ContextifyContext* ctx;
ASSIGN_OR_RETURN_UNWRAP(&ctx, args.Data().As<Object>());
ContextifyContext* ctx = ContextifyContext::Get(args);
// Still initializing
if (ctx->context_.IsEmpty())

View File

@ -55,6 +55,9 @@ class ContextifyContext {
context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject));
}
template <typename T>
static ContextifyContext* Get(const v8::PropertyCallbackInfo<T>& args);
private:
static void MakeContext(const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsContext(const v8::FunctionCallbackInfo<v8::Value>& args);