| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 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" | |
@@ -602,7 +603,8 @@ std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create( | |||
| 602 | 603 | page_allocator); | |
| 603 | 604 | } | |
| 604 | 605 | ||
| 605 | - MaybeLocal<Object> GetPerContextExports(Local<Context> context) { | ||
| 606 | + MaybeLocal<Object> GetPerContextExports(Local<Context> context, | ||
| 607 | + IsolateData* isolate_data) { | ||
| 606 | 608 | Isolate* isolate = context->GetIsolate(); | |
| 607 | 609 | EscapableHandleScope handle_scope(isolate); | |
| 608 | 610 | ||
@@ -616,10 +618,14 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) { | |||
| 616 | 618 | if (existing_value->IsObject()) | |
| 617 | 619 | return handle_scope.Escape(existing_value.As<Object>()); | |
| 618 | 620 | ||
| 621 | + // To initialize the per-context binding exports, a non-nullptr isolate_data | ||
| 622 | + // is needed | ||
| 623 | + CHECK(isolate_data); | ||
| 619 | 624 | Local<Object> exports = Object::New(isolate); | |
| 620 | 625 | if (context->Global()->SetPrivate(context, key, exports).IsNothing() || | |
| 621 | - InitializePrimordials(context).IsNothing()) | ||
| 626 | + InitializePrimordials(context, isolate_data).IsNothing()) { | ||
| 622 | 627 | return MaybeLocal<Object>(); | |
| 628 | + } | ||
| 623 | 629 | return handle_scope.Escape(exports); | |
| 624 | 630 | } | |
| 625 | 631 | ||
@@ -764,7 +770,32 @@ Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) { | |||
| 764 | 770 | return JustVoid(); | |
| 765 | 771 | } | |
| 766 | 772 | ||
| 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) { | ||
| 768 | 799 | // Run per-context JS files. | |
| 769 | 800 | Isolate* isolate = context->GetIsolate(); | |
| 770 | 801 | Context::Scope context_scope(context); | |
@@ -785,6 +816,12 @@ Maybe<void> InitializePrimordials(Local<Context> context) { | |||
| 785 | 816 | return Nothing<void>(); | |
| 786 | 817 | } | |
| 787 | 818 | ||
| 819 | + Local<Object> private_symbols; | ||
| 820 | + if (!InitializePrivateSymbols(context, isolate_data) | ||
| 821 | + .ToLocal(&private_symbols)) { | ||
| 822 | + return Nothing<void>(); | ||
| 823 | + } | ||
| 824 | + | ||
| 788 | 825 | static const char* context_files[] = {"internal/per_context/primordials", | |
| 789 | 826 | "internal/per_context/domexception", | |
| 790 | 827 | "internal/per_context/messageport", | |
@@ -800,7 +837,8 @@ Maybe<void> InitializePrimordials(Local<Context> context) { | |||
| 800 | 837 | builtin_loader.SetEagerCompile(); | |
| 801 | 838 | ||
| 802 | 839 | for (const char** module = context_files; *module != nullptr; module++) { | |
| 803 | - Local<Value> arguments[] = {exports, primordials}; | ||
| 840 | + Local<Value> arguments[] = {exports, primordials, private_symbols}; | ||
| 841 | + | ||
| 804 | 842 | if (builtin_loader | |
| 805 | 843 | .CompileAndCall( | |
| 806 | 844 | context, *module, arraysize(arguments), arguments, nullptr) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -412,6 +412,7 @@ MaybeLocal<Function> BuiltinLoader::LookupAndCompile(Local<Context> context, | |||
| 412 | 412 | parameters = { | |
| 413 | 413 | FIXED_ONE_BYTE_STRING(isolate, "exports"), | |
| 414 | 414 | FIXED_ONE_BYTE_STRING(isolate, "primordials"), | |
| 415 | + FIXED_ONE_BYTE_STRING(isolate, "privateSymbols"), | ||
| 415 | 416 | }; | |
| 416 | 417 | } else if (strncmp(id, "internal/main/", strlen("internal/main/")) == 0 || | |
| 417 | 418 | strncmp(id, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -113,7 +113,10 @@ std::string GetHumanReadableProcessName(); | |||
| 113 | 113 | v8::Maybe<void> InitializeBaseContextForSnapshot( | |
| 114 | 114 | v8::Local<v8::Context> context); | |
| 115 | 115 | v8::Maybe<void> InitializeContextRuntime(v8::Local<v8::Context> context); | |
| 116 | - v8::Maybe<void> InitializePrimordials(v8::Local<v8::Context> context); | ||
| 116 | + v8::Maybe<void> InitializePrimordials(v8::Local<v8::Context> context, | ||
| 117 | + IsolateData* isolate_data); | ||
| 118 | + v8::MaybeLocal<v8::Object> InitializePrivateSymbols( | ||
| 119 | + v8::Local<v8::Context> context, IsolateData* isolate_data); | ||
| 117 | 120 | ||
| 118 | 121 | class NodeArrayBufferAllocator : public ArrayBufferAllocator { | |
| 119 | 122 | public: | |
@@ -340,7 +343,8 @@ v8::Isolate* NewIsolate(v8::Isolate::CreateParams* params, | |||
| 340 | 343 | // was provided by the embedder. | |
| 341 | 344 | v8::MaybeLocal<v8::Value> StartExecution(Environment* env, | |
| 342 | 345 | StartExecutionCallback cb = nullptr); | |
| 343 | - v8::MaybeLocal<v8::Object> GetPerContextExports(v8::Local<v8::Context> context); | ||
| 346 | + v8::MaybeLocal<v8::Object> GetPerContextExports( | ||
| 347 | + v8::Local<v8::Context> context, IsolateData* isolate_data = nullptr); | ||
| 344 | 348 | void MarkBootstrapComplete(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 345 | 349 | ||
| 346 | 350 | class InitializationResultImpl final : public InitializationResult { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -251,14 +251,16 @@ void Message::AdoptSharedValueConveyor(SharedValueConveyor&& conveyor) { | |||
| 251 | 251 | ||
| 252 | 252 | namespace { | |
| 253 | 253 | ||
| 254 | - MaybeLocal<Function> GetEmitMessageFunction(Local<Context> context) { | ||
| 254 | + MaybeLocal<Function> GetEmitMessageFunction(Local<Context> context, | ||
| 255 | + IsolateData* isolate_data) { | ||
| 255 | 256 | Isolate* isolate = context->GetIsolate(); | |
| 256 | 257 | Local<Object> per_context_bindings; | |
| 257 | 258 | Local<Value> emit_message_val; | |
| 258 | - if (!GetPerContextExports(context).ToLocal(&per_context_bindings) || | ||
| 259 | - !per_context_bindings->Get(context, | ||
| 260 | - FIXED_ONE_BYTE_STRING(isolate, "emitMessage")) | ||
| 261 | - .ToLocal(&emit_message_val)) { | ||
| 259 | + if (!GetPerContextExports(context, isolate_data) | ||
| 260 | + .ToLocal(&per_context_bindings) || | ||
| 261 | + !per_context_bindings | ||
| 262 | + ->Get(context, FIXED_ONE_BYTE_STRING(isolate, "emitMessage")) | ||
| 263 | + .ToLocal(&emit_message_val)) { | ||
| 262 | 264 | return MaybeLocal<Function>(); | |
| 263 | 265 | } | |
| 264 | 266 | CHECK(emit_message_val->IsFunction()); | |
@@ -687,7 +689,8 @@ MessagePort::MessagePort(Environment* env, | |||
| 687 | 689 | } | |
| 688 | 690 | ||
| 689 | 691 | Local<Function> emit_message_fn; | |
| 690 | - if (!GetEmitMessageFunction(context).ToLocal(&emit_message_fn)) | ||
| 692 | + if (!GetEmitMessageFunction(context, env->isolate_data()) | ||
| 693 | + .ToLocal(&emit_message_fn)) | ||
| 691 | 694 | return; | |
| 692 | 695 | emit_message_fn_.Reset(env->isolate(), emit_message_fn); | |
| 693 | 696 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,7 +45,7 @@ void Realm::CreateProperties() { | |||
| 45 | 45 | ||
| 46 | 46 | // Store primordials setup by the per-context script in the environment. | |
| 47 | 47 | Local<Object> per_context_bindings = | |
| 48 | - GetPerContextExports(ctx).ToLocalChecked(); | ||
| 48 | + GetPerContextExports(ctx, env_->isolate_data()).ToLocalChecked(); | ||
| 49 | 49 | Local<Value> primordials = | |
| 50 | 50 | per_context_bindings->Get(ctx, env_->primordials_string()) | |
| 51 | 51 | .ToLocalChecked(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments