Skip to content

Commit c21a52f

Browse files
addaleaxMylesBorins
authored andcommitted
src: access ContextifyContext* more directly in property cbs
PR-URL: #20455 Fixes: #18897 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
1 parent c0f1535 commit c21a52f

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/node_contextify.cc

+20-23
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Local<Value> ContextifyContext::CreateDataWrapper(Environment* env) {
120120
if (wrapper.IsEmpty())
121121
return scope.Escape(Local<Value>::New(env->isolate(), Local<Value>()));
122122

123-
Wrap(wrapper, this);
123+
wrapper->SetAlignedPointerInInternalField(0, this);
124124
return scope.Escape(wrapper);
125125
}
126126

@@ -290,12 +290,19 @@ ContextifyContext* ContextifyContext::ContextFromContextifiedSandbox(
290290
return 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
294302
void ContextifyContext::PropertyGetterCallback(
295303
Local<Name> property,
296304
const 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
301308
if (ctx->context_.IsEmpty())
@@ -324,8 +331,7 @@ void ContextifyContext::PropertySetterCallback(
324331
Local<Name> property,
325332
Local<Value> value,
326333
const 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
331337
if (ctx->context_.IsEmpty())
@@ -385,8 +391,7 @@ void ContextifyContext::PropertySetterCallback(
385391
void ContextifyContext::PropertyDescriptorCallback(
386392
Local<Name> property,
387393
const 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
392397
if (ctx->context_.IsEmpty())
@@ -408,8 +413,7 @@ void ContextifyContext::PropertyDefinerCallback(
408413
Local<Name> property,
409414
const PropertyDescriptor& desc,
410415
const 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
415419
if (ctx->context_.IsEmpty())
@@ -471,8 +475,7 @@ void ContextifyContext::PropertyDefinerCallback(
471475
void ContextifyContext::PropertyDeleterCallback(
472476
Local<Name> property,
473477
const 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
478481
if (ctx->context_.IsEmpty())
@@ -491,8 +494,7 @@ void ContextifyContext::PropertyDeleterCallback(
491494
// static
492495
void ContextifyContext::PropertyEnumeratorCallback(
493496
const 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
498500
if (ctx->context_.IsEmpty())
@@ -505,8 +507,7 @@ void ContextifyContext::PropertyEnumeratorCallback(
505507
void ContextifyContext::IndexedPropertyGetterCallback(
506508
uint32_t index,
507509
const 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
512513
if (ctx->context_.IsEmpty())
@@ -521,8 +522,7 @@ void ContextifyContext::IndexedPropertySetterCallback(
521522
uint32_t index,
522523
Local<Value> value,
523524
const 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
528528
if (ctx->context_.IsEmpty())
@@ -536,8 +536,7 @@ void ContextifyContext::IndexedPropertySetterCallback(
536536
void ContextifyContext::IndexedPropertyDescriptorCallback(
537537
uint32_t index,
538538
const 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
543542
if (ctx->context_.IsEmpty())
@@ -552,8 +551,7 @@ void ContextifyContext::IndexedPropertyDefinerCallback(
552551
uint32_t index,
553552
const PropertyDescriptor& desc,
554553
const 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
559557
if (ctx->context_.IsEmpty())
@@ -567,8 +565,7 @@ void ContextifyContext::IndexedPropertyDefinerCallback(
567565
void ContextifyContext::IndexedPropertyDeleterCallback(
568566
uint32_t index,
569567
const 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
574571
if (ctx->context_.IsEmpty())

src/node_contextify.h

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class ContextifyContext {
5555
context()->GetEmbedderData(ContextEmbedderIndex::kSandboxObject));
5656
}
5757

58+
template <typename T>
59+
static ContextifyContext* Get(const v8::PropertyCallbackInfo<T>& args);
60+
5861
private:
5962
static void MakeContext(const v8::FunctionCallbackInfo<v8::Value>& args);
6063
static void IsContext(const v8::FunctionCallbackInfo<v8::Value>& args);

0 commit comments

Comments
 (0)