Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 323f95d

Browse filesBrowse files
committed
src: migrate to new V8 interceptors API
Refs: v8#180 PR-URL: #52745 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent fce31fc commit 323f95d
Copy full SHA for 323f95d

File tree

Expand file treeCollapse file tree

4 files changed

+152
-103
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+152
-103
lines changed
Open diff view settings
Collapse file

‎src/node_contextify.cc‎

Copy file name to clipboardExpand all lines: src/node_contextify.cc
+91-54Lines changed: 91 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ using v8::FunctionTemplate;
5151
using v8::HandleScope;
5252
using v8::IndexedPropertyHandlerConfiguration;
5353
using v8::Int32;
54+
using v8::Intercepted;
5455
using v8::Isolate;
5556
using v8::Just;
5657
using v8::Local;
@@ -458,14 +459,15 @@ bool ContextifyContext::IsStillInitializing(const ContextifyContext* ctx) {
458459
}
459460

460461
// static
461-
void ContextifyContext::PropertyGetterCallback(
462-
Local<Name> property,
463-
const PropertyCallbackInfo<Value>& args) {
462+
Intercepted ContextifyContext::PropertyGetterCallback(
463+
Local<Name> property, const PropertyCallbackInfo<Value>& args) {
464464
Environment* env = Environment::GetCurrent(args);
465465
ContextifyContext* ctx = ContextifyContext::Get(args);
466466

467467
// Still initializing
468-
if (IsStillInitializing(ctx)) return;
468+
if (IsStillInitializing(ctx)) {
469+
return Intercepted::kNo;
470+
}
469471

470472
Local<Context> context = ctx->context();
471473
Local<Object> sandbox = ctx->sandbox();
@@ -487,18 +489,22 @@ void ContextifyContext::PropertyGetterCallback(
487489
rv = ctx->global_proxy();
488490

489491
args.GetReturnValue().Set(rv);
492+
return Intercepted::kYes;
490493
}
494+
return Intercepted::kNo;
491495
}
492496

493497
// static
494-
void ContextifyContext::PropertySetterCallback(
498+
Intercepted ContextifyContext::PropertySetterCallback(
495499
Local<Name> property,
496500
Local<Value> value,
497-
const PropertyCallbackInfo<Value>& args) {
501+
const PropertyCallbackInfo<void>& args) {
498502
ContextifyContext* ctx = ContextifyContext::Get(args);
499503

500504
// Still initializing
501-
if (IsStillInitializing(ctx)) return;
505+
if (IsStillInitializing(ctx)) {
506+
return Intercepted::kNo;
507+
}
502508

503509
Local<Context> context = ctx->context();
504510
PropertyAttribute attributes = PropertyAttribute::None;
@@ -516,8 +522,9 @@ void ContextifyContext::PropertySetterCallback(
516522
(static_cast<int>(attributes) &
517523
static_cast<int>(PropertyAttribute::ReadOnly));
518524

519-
if (read_only)
520-
return;
525+
if (read_only) {
526+
return Intercepted::kNo;
527+
}
521528

522529
// true for x = 5
523530
// false for this.x = 5
@@ -536,11 +543,16 @@ void ContextifyContext::PropertySetterCallback(
536543

537544
bool is_declared = is_declared_on_global_proxy || is_declared_on_sandbox;
538545
if (!is_declared && args.ShouldThrowOnError() && is_contextual_store &&
539-
!is_function)
540-
return;
546+
!is_function) {
547+
return Intercepted::kNo;
548+
}
541549

542-
if (!is_declared && property->IsSymbol()) return;
543-
if (ctx->sandbox()->Set(context, property, value).IsNothing()) return;
550+
if (!is_declared && property->IsSymbol()) {
551+
return Intercepted::kNo;
552+
}
553+
if (ctx->sandbox()->Set(context, property, value).IsNothing()) {
554+
return Intercepted::kNo;
555+
}
544556

545557
Local<Value> desc;
546558
if (is_declared_on_sandbox &&
@@ -554,19 +566,23 @@ void ContextifyContext::PropertySetterCallback(
554566
// We have to specify the return value for any contextual or get/set
555567
// property
556568
if (desc_obj->HasOwnProperty(context, env->get_string()).FromMaybe(false) ||
557-
desc_obj->HasOwnProperty(context, env->set_string()).FromMaybe(false))
569+
desc_obj->HasOwnProperty(context, env->set_string()).FromMaybe(false)) {
558570
args.GetReturnValue().Set(value);
571+
return Intercepted::kYes;
572+
}
559573
}
574+
return Intercepted::kNo;
560575
}
561576

562577
// static
563-
void ContextifyContext::PropertyDescriptorCallback(
564-
Local<Name> property,
565-
const PropertyCallbackInfo<Value>& args) {
578+
Intercepted ContextifyContext::PropertyDescriptorCallback(
579+
Local<Name> property, const PropertyCallbackInfo<Value>& args) {
566580
ContextifyContext* ctx = ContextifyContext::Get(args);
567581

568582
// Still initializing
569-
if (IsStillInitializing(ctx)) return;
583+
if (IsStillInitializing(ctx)) {
584+
return Intercepted::kNo;
585+
}
570586

571587
Local<Context> context = ctx->context();
572588

@@ -576,19 +592,23 @@ void ContextifyContext::PropertyDescriptorCallback(
576592
Local<Value> desc;
577593
if (sandbox->GetOwnPropertyDescriptor(context, property).ToLocal(&desc)) {
578594
args.GetReturnValue().Set(desc);
595+
return Intercepted::kYes;
579596
}
580597
}
598+
return Intercepted::kNo;
581599
}
582600

583601
// static
584-
void ContextifyContext::PropertyDefinerCallback(
602+
Intercepted ContextifyContext::PropertyDefinerCallback(
585603
Local<Name> property,
586604
const PropertyDescriptor& desc,
587-
const PropertyCallbackInfo<Value>& args) {
605+
const PropertyCallbackInfo<void>& args) {
588606
ContextifyContext* ctx = ContextifyContext::Get(args);
589607

590608
// Still initializing
591-
if (IsStillInitializing(ctx)) return;
609+
if (IsStillInitializing(ctx)) {
610+
return Intercepted::kNo;
611+
}
592612

593613
Local<Context> context = ctx->context();
594614
Isolate* isolate = context->GetIsolate();
@@ -607,7 +627,7 @@ void ContextifyContext::PropertyDefinerCallback(
607627
// If the property is set on the global as neither writable nor
608628
// configurable, don't change it on the global or sandbox.
609629
if (is_declared && read_only && dont_delete) {
610-
return;
630+
return Intercepted::kNo;
611631
}
612632

613633
Local<Object> sandbox = ctx->sandbox();
@@ -630,6 +650,9 @@ void ContextifyContext::PropertyDefinerCallback(
630650
desc.has_set() ? desc.set() : Undefined(isolate).As<Value>());
631651

632652
define_prop_on_sandbox(&desc_for_sandbox);
653+
// TODO(https://github.com/nodejs/node/issues/52634): this should return
654+
// kYes to behave according to the expected semantics.
655+
return Intercepted::kNo;
633656
} else {
634657
Local<Value> value =
635658
desc.has_value() ? desc.value() : Undefined(isolate).As<Value>();
@@ -641,26 +664,33 @@ void ContextifyContext::PropertyDefinerCallback(
641664
PropertyDescriptor desc_for_sandbox(value);
642665
define_prop_on_sandbox(&desc_for_sandbox);
643666
}
667+
// TODO(https://github.com/nodejs/node/issues/52634): this should return
668+
// kYes to behave according to the expected semantics.
669+
return Intercepted::kNo;
644670
}
671+
return Intercepted::kNo;
645672
}
646673

647674
// static
648-
void ContextifyContext::PropertyDeleterCallback(
649-
Local<Name> property,
650-
const PropertyCallbackInfo<Boolean>& args) {
675+
Intercepted ContextifyContext::PropertyDeleterCallback(
676+
Local<Name> property, const PropertyCallbackInfo<Boolean>& args) {
651677
ContextifyContext* ctx = ContextifyContext::Get(args);
652678

653679
// Still initializing
654-
if (IsStillInitializing(ctx)) return;
680+
if (IsStillInitializing(ctx)) {
681+
return Intercepted::kNo;
682+
}
655683

656684
Maybe<bool> success = ctx->sandbox()->Delete(ctx->context(), property);
657685

658-
if (success.FromMaybe(false))
659-
return;
686+
if (success.FromMaybe(false)) {
687+
return Intercepted::kNo;
688+
}
660689

661690
// Delete failed on the sandbox, intercept and do not delete on
662691
// the global object.
663692
args.GetReturnValue().Set(false);
693+
return Intercepted::kYes;
664694
}
665695

666696
// static
@@ -680,76 +710,83 @@ void ContextifyContext::PropertyEnumeratorCallback(
680710
}
681711

682712
// static
683-
void ContextifyContext::IndexedPropertyGetterCallback(
684-
uint32_t index,
685-
const PropertyCallbackInfo<Value>& args) {
713+
Intercepted ContextifyContext::IndexedPropertyGetterCallback(
714+
uint32_t index, const PropertyCallbackInfo<Value>& args) {
686715
ContextifyContext* ctx = ContextifyContext::Get(args);
687716

688717
// Still initializing
689-
if (IsStillInitializing(ctx)) return;
718+
if (IsStillInitializing(ctx)) {
719+
return Intercepted::kNo;
720+
}
690721

691-
ContextifyContext::PropertyGetterCallback(
722+
return ContextifyContext::PropertyGetterCallback(
692723
Uint32ToName(ctx->context(), index), args);
693724
}
694725

695-
696-
void ContextifyContext::IndexedPropertySetterCallback(
726+
Intercepted ContextifyContext::IndexedPropertySetterCallback(
697727
uint32_t index,
698728
Local<Value> value,
699-
const PropertyCallbackInfo<Value>& args) {
729+
const PropertyCallbackInfo<void>& args) {
700730
ContextifyContext* ctx = ContextifyContext::Get(args);
701731

702732
// Still initializing
703-
if (IsStillInitializing(ctx)) return;
733+
if (IsStillInitializing(ctx)) {
734+
return Intercepted::kNo;
735+
}
704736

705-
ContextifyContext::PropertySetterCallback(
737+
return ContextifyContext::PropertySetterCallback(
706738
Uint32ToName(ctx->context(), index), value, args);
707739
}
708740

709741
// static
710-
void ContextifyContext::IndexedPropertyDescriptorCallback(
711-
uint32_t index,
712-
const PropertyCallbackInfo<Value>& args) {
742+
Intercepted ContextifyContext::IndexedPropertyDescriptorCallback(
743+
uint32_t index, const PropertyCallbackInfo<Value>& args) {
713744
ContextifyContext* ctx = ContextifyContext::Get(args);
714745

715746
// Still initializing
716-
if (IsStillInitializing(ctx)) return;
747+
if (IsStillInitializing(ctx)) {
748+
return Intercepted::kNo;
749+
}
717750

718-
ContextifyContext::PropertyDescriptorCallback(
751+
return ContextifyContext::PropertyDescriptorCallback(
719752
Uint32ToName(ctx->context(), index), args);
720753
}
721754

722-
723-
void ContextifyContext::IndexedPropertyDefinerCallback(
755+
Intercepted ContextifyContext::IndexedPropertyDefinerCallback(
724756
uint32_t index,
725757
const PropertyDescriptor& desc,
726-
const PropertyCallbackInfo<Value>& args) {
758+
const PropertyCallbackInfo<void>& args) {
727759
ContextifyContext* ctx = ContextifyContext::Get(args);
728760

729761
// Still initializing
730-
if (IsStillInitializing(ctx)) return;
762+
if (IsStillInitializing(ctx)) {
763+
return Intercepted::kNo;
764+
}
731765

732-
ContextifyContext::PropertyDefinerCallback(
766+
return ContextifyContext::PropertyDefinerCallback(
733767
Uint32ToName(ctx->context(), index), desc, args);
734768
}
735769

736770
// static
737-
void ContextifyContext::IndexedPropertyDeleterCallback(
738-
uint32_t index,
739-
const PropertyCallbackInfo<Boolean>& args) {
771+
Intercepted ContextifyContext::IndexedPropertyDeleterCallback(
772+
uint32_t index, const PropertyCallbackInfo<Boolean>& args) {
740773
ContextifyContext* ctx = ContextifyContext::Get(args);
741774

742775
// Still initializing
743-
if (IsStillInitializing(ctx)) return;
776+
if (IsStillInitializing(ctx)) {
777+
return Intercepted::kNo;
778+
}
744779

745780
Maybe<bool> success = ctx->sandbox()->Delete(ctx->context(), index);
746781

747-
if (success.FromMaybe(false))
748-
return;
782+
if (success.FromMaybe(false)) {
783+
return Intercepted::kNo;
784+
}
749785

750786
// Delete failed on the sandbox, intercept and do not delete on
751787
// the global object.
752788
args.GetReturnValue().Set(false);
789+
return Intercepted::kYes;
753790
}
754791

755792
void ContextifyScript::CreatePerIsolateProperties(
Collapse file

‎src/node_contextify.h‎

Copy file name to clipboardExpand all lines: src/node_contextify.h
+17-20Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,42 +96,39 @@ class ContextifyContext : public BaseObject {
9696
const errors::TryCatchScope& try_catch);
9797
static void WeakCallback(
9898
const v8::WeakCallbackInfo<ContextifyContext>& data);
99-
static void PropertyGetterCallback(
99+
static v8::Intercepted PropertyGetterCallback(
100100
v8::Local<v8::Name> property,
101101
const v8::PropertyCallbackInfo<v8::Value>& args);
102-
static void PropertySetterCallback(
102+
static v8::Intercepted PropertySetterCallback(
103103
v8::Local<v8::Name> property,
104104
v8::Local<v8::Value> value,
105-
const v8::PropertyCallbackInfo<v8::Value>& args);
106-
static void PropertyDescriptorCallback(
105+
const v8::PropertyCallbackInfo<void>& args);
106+
static v8::Intercepted PropertyDescriptorCallback(
107107
v8::Local<v8::Name> property,
108108
const v8::PropertyCallbackInfo<v8::Value>& args);
109-
static void PropertyDefinerCallback(
109+
static v8::Intercepted PropertyDefinerCallback(
110110
v8::Local<v8::Name> property,
111111
const v8::PropertyDescriptor& desc,
112-
const v8::PropertyCallbackInfo<v8::Value>& args);
113-
static void PropertyDeleterCallback(
112+
const v8::PropertyCallbackInfo<void>& args);
113+
static v8::Intercepted PropertyDeleterCallback(
114114
v8::Local<v8::Name> property,
115115
const v8::PropertyCallbackInfo<v8::Boolean>& args);
116116
static void PropertyEnumeratorCallback(
117117
const v8::PropertyCallbackInfo<v8::Array>& args);
118-
static void IndexedPropertyGetterCallback(
119-
uint32_t index,
120-
const v8::PropertyCallbackInfo<v8::Value>& args);
121-
static void IndexedPropertySetterCallback(
118+
static v8::Intercepted IndexedPropertyGetterCallback(
119+
uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& args);
120+
static v8::Intercepted IndexedPropertySetterCallback(
122121
uint32_t index,
123122
v8::Local<v8::Value> value,
124-
const v8::PropertyCallbackInfo<v8::Value>& args);
125-
static void IndexedPropertyDescriptorCallback(
126-
uint32_t index,
127-
const v8::PropertyCallbackInfo<v8::Value>& args);
128-
static void IndexedPropertyDefinerCallback(
123+
const v8::PropertyCallbackInfo<void>& args);
124+
static v8::Intercepted IndexedPropertyDescriptorCallback(
125+
uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& args);
126+
static v8::Intercepted IndexedPropertyDefinerCallback(
129127
uint32_t index,
130128
const v8::PropertyDescriptor& desc,
131-
const v8::PropertyCallbackInfo<v8::Value>& args);
132-
static void IndexedPropertyDeleterCallback(
133-
uint32_t index,
134-
const v8::PropertyCallbackInfo<v8::Boolean>& args);
129+
const v8::PropertyCallbackInfo<void>& args);
130+
static v8::Intercepted IndexedPropertyDeleterCallback(
131+
uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& args);
135132

136133
v8::Global<v8::Context> context_;
137134
std::unique_ptr<v8::MicrotaskQueue> microtask_queue_;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.