|
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 |
|
@@ -613,10 +615,14 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) { |
613 | 615 | if (existing_value->IsObject()) |
614 | 616 | return handle_scope.Escape(existing_value.As<Object>()); |
615 | 617 |
|
| 618 | + // To initialize the per-context binding exports, a non-nullptr isolate_data |
| 619 | + // is needed |
| 620 | + CHECK(isolate_data); |
616 | 621 | Local<Object> exports = Object::New(isolate); |
617 | 622 | if (context->Global()->SetPrivate(context, key, exports).IsNothing() || |
618 | | - InitializePrimordials(context).IsNothing()) |
| 623 | + InitializePrimordials(context, isolate_data).IsNothing()) { |
619 | 624 | return MaybeLocal<Object>(); |
| 625 | + } |
620 | 626 | return handle_scope.Escape(exports); |
621 | 627 | } |
622 | 628 |
|
@@ -761,7 +767,32 @@ Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) { |
761 | 767 | return JustVoid(); |
762 | 768 | } |
763 | 769 |
|
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) { |
765 | 796 | // Run per-context JS files. |
766 | 797 | Isolate* isolate = context->GetIsolate(); |
767 | 798 | Context::Scope context_scope(context); |
@@ -783,6 +814,12 @@ Maybe<void> InitializePrimordials(Local<Context> context) { |
783 | 814 | return Nothing<void>(); |
784 | 815 | } |
785 | 816 |
|
| 817 | + Local<Object> private_symbols; |
| 818 | + if (!InitializePrivateSymbols(context, isolate_data) |
| 819 | + .ToLocal(&private_symbols)) { |
| 820 | + return Nothing<void>(); |
| 821 | + } |
| 822 | + |
786 | 823 | static const char* context_files[] = {"internal/per_context/primordials", |
787 | 824 | "internal/per_context/domexception", |
788 | 825 | "internal/per_context/messageport", |
@@ -798,7 +835,8 @@ Maybe<void> InitializePrimordials(Local<Context> context) { |
798 | 835 | builtin_loader.SetEagerCompile(); |
799 | 836 |
|
800 | 837 | for (const char** module = context_files; *module != nullptr; module++) { |
801 | | - Local<Value> arguments[] = {exports, primordials}; |
| 838 | + Local<Value> arguments[] = {exports, primordials, private_symbols}; |
| 839 | + |
802 | 840 | if (builtin_loader |
803 | 841 | .CompileAndCall( |
804 | 842 | context, *module, arraysize(arguments), arguments, nullptr) |
|