11#include < cstdlib>
2+ #include " env_properties.h"
23#include " node.h"
34#include " node_builtins.h"
45#include " node_context_data.h"
@@ -602,7 +603,8 @@ std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
602603 page_allocator);
603604}
604605
605- MaybeLocal<Object> GetPerContextExports (Local<Context> context) {
606+ MaybeLocal<Object> GetPerContextExports (Local<Context> context,
607+ IsolateData* isolate_data) {
606608 Isolate* isolate = context->GetIsolate ();
607609 EscapableHandleScope handle_scope (isolate);
608610
@@ -616,10 +618,14 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
616618 if (existing_value->IsObject ())
617619 return handle_scope.Escape (existing_value.As <Object>());
618620
621+ // To initialize the per-context binding exports, a non-nullptr isolate_data
622+ // is needed
623+ CHECK (isolate_data);
619624 Local<Object> exports = Object::New (isolate);
620625 if (context->Global ()->SetPrivate (context, key, exports).IsNothing () ||
621- InitializePrimordials (context).IsNothing ())
626+ InitializePrimordials (context, isolate_data ).IsNothing ()) {
622627 return MaybeLocal<Object>();
628+ }
623629 return handle_scope.Escape (exports);
624630}
625631
@@ -764,7 +770,32 @@ Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
764770 return JustVoid ();
765771}
766772
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) {
768799 // Run per-context JS files.
769800 Isolate* isolate = context->GetIsolate ();
770801 Context::Scope context_scope (context);
@@ -785,6 +816,12 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
785816 return Nothing<void >();
786817 }
787818
819+ Local<Object> private_symbols;
820+ if (!InitializePrivateSymbols (context, isolate_data)
821+ .ToLocal (&private_symbols)) {
822+ return Nothing<void >();
823+ }
824+
788825 static const char * context_files[] = {" internal/per_context/primordials" ,
789826 " internal/per_context/domexception" ,
790827 " internal/per_context/messageport" ,
@@ -800,7 +837,8 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
800837 builtin_loader.SetEagerCompile ();
801838
802839 for (const char ** module = context_files; *module != nullptr ; module ++) {
803- Local<Value> arguments[] = {exports, primordials};
840+ Local<Value> arguments[] = {exports, primordials, private_symbols};
841+
804842 if (builtin_loader
805843 .CompileAndCall (
806844 context, *module , arraysize (arguments), arguments, nullptr )
0 commit comments