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
@@ -745,7 +748,8 @@ Maybe<void> InitializeBaseContextForSnapshot(Local<Context> context) {
745
748
return JustVoid ();
746
749
}
747
750
748
- Maybe<void > InitializeMainContextForSnapshot (Local<Context> context) {
751
+ Maybe<void > InitializeMainContextForSnapshot (Local<Context> context,
752
+ IsolateData* isolate_data) {
749
753
Isolate* isolate = context->GetIsolate ();
750
754
HandleScope handle_scope (isolate);
751
755
@@ -761,7 +765,34 @@ Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
761
765
return JustVoid ();
762
766
}
763
767
764
- Maybe<void > InitializePrimordials (Local<Context> context) {
768
+ Local<Object> InitializePrivateSymbols (Local<Context> context,
769
+ IsolateData* isolate_data) {
770
+ if (isolate_data == nullptr ) {
771
+ return Local<Object>();
772
+ }
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 Local<Object>();
789
+ }
790
+
791
+ return scope.Escape (private_symbols_object);
792
+ }
793
+
794
+ Maybe<void > InitializePrimordials (Local<Context> context,
795
+ IsolateData* isolate_data) {
765
796
// Run per-context JS files.
766
797
Isolate* isolate = context->GetIsolate ();
767
798
Context::Scope context_scope (context);
@@ -783,6 +814,9 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
783
814
return Nothing<void >();
784
815
}
785
816
817
+ Local<Object> private_symbols =
818
+ InitializePrivateSymbols (context, isolate_data);
819
+
786
820
static const char * context_files[] = {" internal/per_context/primordials" ,
787
821
" internal/per_context/domexception" ,
788
822
" internal/per_context/messageport" ,
@@ -798,7 +832,12 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
798
832
builtin_loader.SetEagerCompile ();
799
833
800
834
for (const char ** module = context_files; *module != nullptr ; module ++) {
801
- Local<Value> arguments[] = {exports, primordials};
835
+ Local<Value> arguments[3 ];
836
+ arguments[0 ] = exports;
837
+ arguments[1 ] = primordials;
838
+ arguments[2 ] = private_symbols.IsEmpty () ? Local<Value>(Undefined (isolate))
839
+ : Local<Value>(private_symbols);
840
+
802
841
if (builtin_loader
803
842
.CompileAndCall (
804
843
context, *module , arraysize (arguments), arguments, nullptr )
@@ -812,8 +851,9 @@ Maybe<void> InitializePrimordials(Local<Context> context) {
812
851
}
813
852
814
853
// This initializes the main context (i.e. vm contexts are not included).
815
- Maybe<bool > InitializeContext (Local<Context> context) {
816
- if (InitializeMainContextForSnapshot (context).IsNothing ()) {
854
+ Maybe<bool > InitializeContext (Local<Context> context,
855
+ IsolateData* isolate_data) {
856
+ if (InitializeMainContextForSnapshot (context, isolate_data).IsNothing ()) {
817
857
return Nothing<bool >();
818
858
}
819
859
0 commit comments