1
1
#include < cstdlib>
2
+ #include " env_properties.h"
2
3
#include " node.h"
3
4
#include " node_builtins.h"
4
5
#include " node_context_data.h"
@@ -602,7 +603,8 @@ std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
602
603
page_allocator);
603
604
}
604
605
605
- MaybeLocal<Object> GetPerContextExports (Local<Context> context) {
606
+ MaybeLocal<Object> GetPerContextExports (Local<Context> context,
607
+ IsolateData* isolate_data) {
606
608
Isolate* isolate = context->GetIsolate ();
607
609
EscapableHandleScope handle_scope (isolate);
608
610
@@ -616,10 +618,14 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
616
618
if (existing_value->IsObject ())
617
619
return handle_scope.Escape (existing_value.As <Object>());
618
620
621
+ // To initialize the per-context binding exports, a non-nullptr isolate_data
622
+ // is needed
623
+ CHECK (isolate_data);
619
624
Local<Object> exports = Object::New (isolate);
620
625
if (context->Global ()->SetPrivate (context, key, exports).IsNothing () ||
621
- InitializePrimordials (context).IsNothing ())
626
+ InitializePrimordials (context, isolate_data ).IsNothing ()) {
622
627
return MaybeLocal<Object>();
628
+ }
623
629
return handle_scope.Escape (exports);
624
630
}
625
631
@@ -764,7 +770,32 @@ Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
764
770
return JustVoid ();
765
771
}
766
772
767
- Maybe<void > InitializePrimordials (Local<Context> context) {
773
+ MaybeLocal<Object> InitializePrivateSymbols (Local<Context> context,
774
+ IsolateData* isolate_data) {
775
+ CHECK (isolate_data);
776
+ Isolate* isolate = context->GetIsolate ();
777
+ EscapableHandleScope scope (isolate);
778
+ Context::Scope context_scope (context);
779
+
780
+ Local<ObjectTemplate> private_symbols = ObjectTemplate::New (isolate);
781
+ Local<Object> private_symbols_object;
782
+ #define V (PropertyName, _ ) \
783
+ private_symbols->Set (isolate, #PropertyName, isolate_data->PropertyName ());
784
+
785
+ PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES (V)
786
+ #undef V
787
+
788
+ if (!private_symbols->NewInstance (context).ToLocal (&private_symbols_object) ||
789
+ private_symbols_object->SetPrototype (context, Null (isolate))
790
+ .IsNothing ()) {
791
+ return MaybeLocal<Object>();
792
+ }
793
+
794
+ return scope.Escape (private_symbols_object);
795
+ }
796
+
797
+ Maybe<void > InitializePrimordials (Local<Context> context,
798
+ IsolateData* isolate_data) {
768
799
// Run per-context JS files.
769
800
Isolate* isolate = context->GetIsolate ();
770
801
Context::Scope context_scope (context);
@@ -785,6 +816,12 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
785
816
return Nothing<void >();
786
817
}
787
818
819
+ Local<Object> private_symbols;
820
+ if (!InitializePrivateSymbols (context, isolate_data)
821
+ .ToLocal (&private_symbols)) {
822
+ return Nothing<void >();
823
+ }
824
+
788
825
static const char * context_files[] = {" internal/per_context/primordials" ,
789
826
" internal/per_context/domexception" ,
790
827
" internal/per_context/messageport" ,
@@ -800,7 +837,8 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
800
837
builtin_loader.SetEagerCompile ();
801
838
802
839
for (const char ** module = context_files; *module != nullptr ; module++) {
803
- Local<Value> arguments[] = {exports, primordials};
840
+ Local<Value> arguments[] = {exports, primordials, private_symbols};
841
+
804
842
if (builtin_loader
805
843
.CompileAndCall (
806
844
context, *module, arraysize (arguments), arguments, nullptr )
0 commit comments