summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-05-01 17:24:41 +0200
committerAnna Henningsen <anna@addaleax.net>2018-05-04 00:57:38 +0200
commita9b0d8235d5ae11a5ae0748f05c4d290a848f1b9 (patch)
treece1f7f8c6e9bcb00b071093b47025c4b8a6e31ad /src
parent5512fff623658bffffb5ef692c57224802545664 (diff)
downloadandroid-node-v8-a9b0d8235d5ae11a5ae0748f05c4d290a848f1b9.tar.gz
android-node-v8-a9b0d8235d5ae11a5ae0748f05c4d290a848f1b9.tar.bz2
android-node-v8-a9b0d8235d5ae11a5ae0748f05c4d290a848f1b9.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/node_contextify.cc43
-rw-r--r--src/node_contextify.h3
2 files changed, 23 insertions, 23 deletions
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index ca58d1897e..651e147617 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -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);
}
@@ -292,11 +292,18 @@ ContextifyContext* ContextifyContext::ContextFromContextifiedSandbox(
}
// 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())
diff --git a/src/node_contextify.h b/src/node_contextify.h
index 565b8ef856..70ce091af3 100644
--- a/src/node_contextify.h
+++ b/src/node_contextify.h
@@ -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);