11#include < cstdlib>
2+ #include " env_properties.h"
23#include " node.h"
34#include " node_builtins.h"
45#include " node_context_data.h"
@@ -599,7 +600,8 @@ std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
599600 page_allocator);
600601}
601602
602- MaybeLocal<Object> GetPerContextExports (Local<Context> context) {
603+ MaybeLocal<Object> GetPerContextExports (Local<Context> context,
604+ IsolateData* isolate_data) {
603605 Isolate* isolate = context->GetIsolate ();
604606 EscapableHandleScope handle_scope (isolate);
605607
@@ -613,10 +615,14 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
613615 if (existing_value->IsObject ())
614616 return handle_scope.Escape (existing_value.As <Object>());
615617
618+ // To initialize the per-context binding exports, a non-nullptr isolate_data
619+ // is needed
620+ CHECK (isolate_data);
616621 Local<Object> exports = Object::New (isolate);
617622 if (context->Global ()->SetPrivate (context, key, exports).IsNothing () ||
618- InitializePrimordials (context).IsNothing ())
623+ InitializePrimordials (context, isolate_data ).IsNothing ()) {
619624 return MaybeLocal<Object>();
625+ }
620626 return handle_scope.Escape (exports);
621627}
622628
@@ -761,7 +767,32 @@ Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
761767 return JustVoid ();
762768}
763769
764- Maybe<void > InitializePrimordials (Local<Context> context) {
770+ MaybeLocal<Object> InitializePrivateSymbols (Local<Context> context,
771+ IsolateData* isolate_data) {
772+ CHECK (isolate_data);
773+ Isolate* isolate = context->GetIsolate ();
774+ EscapableHandleScope scope (isolate);
775+ Context::Scope context_scope (context);
776+
777+ Local<ObjectTemplate> private_symbols = ObjectTemplate::New (isolate);
778+ Local<Object> private_symbols_object;
779+ #define V (PropertyName, _ ) \
780+ private_symbols->Set (isolate, #PropertyName, isolate_data->PropertyName ());
781+
782+ PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES (V)
783+ #undef V
784+
785+ if (!private_symbols->NewInstance (context).ToLocal (&private_symbols_object) ||
786+ private_symbols_object->SetPrototypeV2 (context, Null (isolate))
787+ .IsNothing ()) {
788+ return MaybeLocal<Object>();
789+ }
790+
791+ return scope.Escape (private_symbols_object);
792+ }
793+
794+ Maybe<void > InitializePrimordials (Local<Context> context,
795+ IsolateData* isolate_data) {
765796 // Run per-context JS files.
766797 Isolate* isolate = context->GetIsolate ();
767798 Context::Scope context_scope (context);
@@ -783,6 +814,12 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
783814 return Nothing<void >();
784815 }
785816
817+ Local<Object> private_symbols;
818+ if (!InitializePrivateSymbols (context, isolate_data)
819+ .ToLocal (&private_symbols)) {
820+ return Nothing<void >();
821+ }
822+
786823 static const char * context_files[] = {" internal/per_context/primordials" ,
787824 " internal/per_context/domexception" ,
788825 " internal/per_context/messageport" ,
@@ -798,7 +835,8 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
798835 builtin_loader.SetEagerCompile ();
799836
800837 for (const char ** module = context_files; *module != nullptr ; module ++) {
801- Local<Value> arguments[] = {exports, primordials};
838+ Local<Value> arguments[] = {exports, primordials, private_symbols};
839+
802840 if (builtin_loader
803841 .CompileAndCall (
804842 context, *module , arraysize (arguments), arguments, nullptr )
0 commit comments