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"
@@ -599,7 +600,8 @@ std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
599
600
page_allocator);
600
601
}
601
602
602
- MaybeLocal<Object> GetPerContextExports (Local<Context> context) {
603
+ MaybeLocal<Object> GetPerContextExports (Local<Context> context,
604
+ IsolateData* isolate_data) {
603
605
Isolate* isolate = context->GetIsolate ();
604
606
EscapableHandleScope handle_scope (isolate);
605
607
@@ -615,8 +617,9 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
615
617
616
618
Local<Object> exports = Object::New (isolate);
617
619
if (context->Global ()->SetPrivate (context, key, exports).IsNothing () ||
618
- InitializePrimordials (context).IsNothing ())
620
+ InitializePrimordials (context, isolate_data ).IsNothing ()) {
619
621
return MaybeLocal<Object>();
622
+ }
620
623
return handle_scope.Escape (exports);
621
624
}
622
625
@@ -761,7 +764,34 @@ Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
761
764
return JustVoid ();
762
765
}
763
766
764
- Maybe<void > InitializePrimordials (Local<Context> context) {
767
+ Local<Object> InitializePrivateSymbols (Local<Context> context,
768
+ IsolateData* isolate_data) {
769
+ if (isolate_data == nullptr ) {
770
+ return Local<Object>();
771
+ }
772
+ Isolate* isolate = context->GetIsolate ();
773
+ EscapableHandleScope scope (isolate);
774
+ Context::Scope context_scope (context);
775
+
776
+ Local<ObjectTemplate> private_symbols = ObjectTemplate::New (isolate);
777
+ Local<Object> private_symbols_object;
778
+ #define V (PropertyName, _ ) \
779
+ private_symbols->Set (isolate, #PropertyName, isolate_data->PropertyName ());
780
+
781
+ PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES (V)
782
+ #undef V
783
+
784
+ if (!private_symbols->NewInstance (context).ToLocal (&private_symbols_object) ||
785
+ private_symbols_object->SetPrototypeV2 (context, Null (isolate))
786
+ .IsNothing ()) {
787
+ return Local<Object>();
788
+ }
789
+
790
+ return scope.Escape (private_symbols_object);
791
+ }
792
+
793
+ Maybe<void > InitializePrimordials (Local<Context> context,
794
+ IsolateData* isolate_data) {
765
795
// Run per-context JS files.
766
796
Isolate* isolate = context->GetIsolate ();
767
797
Context::Scope context_scope (context);
@@ -783,6 +813,9 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
783
813
return Nothing<void >();
784
814
}
785
815
816
+ Local<Object> private_symbols =
817
+ InitializePrivateSymbols (context, isolate_data);
818
+
786
819
static const char * context_files[] = {" internal/per_context/primordials" ,
787
820
" internal/per_context/domexception" ,
788
821
" internal/per_context/messageport" ,
@@ -798,7 +831,12 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
798
831
builtin_loader.SetEagerCompile ();
799
832
800
833
for (const char ** module = context_files; *module != nullptr ; module ++) {
801
- Local<Value> arguments[] = {exports, primordials};
834
+ Local<Value> arguments[3 ];
835
+ arguments[0 ] = exports;
836
+ arguments[1 ] = primordials;
837
+ arguments[2 ] = private_symbols.IsEmpty () ? Local<Value>(Undefined (isolate))
838
+ : Local<Value>(private_symbols);
839
+
802
840
if (builtin_loader
803
841
.CompileAndCall (
804
842
context, *module , arraysize (arguments), arguments, nullptr )
0 commit comments