diff --git a/src/api/environment.cc b/src/api/environment.cc index bdf67521cbf80c..e35da6f3b39d61 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -555,50 +555,8 @@ Maybe InitializeContextRuntime(Local context) { Isolate* isolate = context->GetIsolate(); HandleScope handle_scope(isolate); - // Delete `Intl.v8BreakIterator` - // https://github.com/nodejs/node/issues/14909 - { - Local intl_string = - FIXED_ONE_BYTE_STRING(isolate, "Intl"); - Local break_iter_string = - FIXED_ONE_BYTE_STRING(isolate, "v8BreakIterator"); - - Local intl_v; - if (!context->Global() - ->Get(context, intl_string) - .ToLocal(&intl_v)) { - return Nothing(); - } - - if (intl_v->IsObject() && - intl_v.As() - ->Delete(context, break_iter_string) - .IsNothing()) { - return Nothing(); - } - } - - // Delete `Atomics.wake` - // https://github.com/nodejs/node/issues/21219 - { - Local atomics_string = - FIXED_ONE_BYTE_STRING(isolate, "Atomics"); - Local wake_string = - FIXED_ONE_BYTE_STRING(isolate, "wake"); - - Local atomics_v; - if (!context->Global() - ->Get(context, atomics_string) - .ToLocal(&atomics_v)) { - return Nothing(); - } - - if (atomics_v->IsObject() && - atomics_v.As() - ->Delete(context, wake_string) - .IsNothing()) { - return Nothing(); - } + if (per_process::cli_options->disable_proto == "") { + return Just(true); } // Remove __proto__ @@ -660,7 +618,32 @@ Maybe InitializeContextRuntime(Local context) { return Just(true); } -Maybe InitializeContextForSnapshot(Local context) { +Maybe InitializeBaseContextForSnapshot(Local context) { + Isolate* isolate = context->GetIsolate(); + HandleScope handle_scope(isolate); + + // Delete `Intl.v8BreakIterator` + // https://github.com/nodejs/node/issues/14909 + { + Context::Scope context_scope(context); + Local intl_string = FIXED_ONE_BYTE_STRING(isolate, "Intl"); + Local break_iter_string = + FIXED_ONE_BYTE_STRING(isolate, "v8BreakIterator"); + + Local intl_v; + if (!context->Global()->Get(context, intl_string).ToLocal(&intl_v)) { + return Nothing(); + } + + if (intl_v->IsObject() && + intl_v.As()->Delete(context, break_iter_string).IsNothing()) { + return Nothing(); + } + } + return Just(true); +} + +Maybe InitializeMainContextForSnapshot(Local context) { Isolate* isolate = context->GetIsolate(); HandleScope handle_scope(isolate); @@ -670,6 +653,9 @@ Maybe InitializeContextForSnapshot(Local context) { context->SetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration, True(isolate)); + if (InitializeBaseContextForSnapshot(context).IsNothing()) { + return Nothing(); + } return InitializePrimordials(context); } @@ -716,8 +702,9 @@ Maybe InitializePrimordials(Local context) { return Just(true); } +// This initializes the main context (i.e. vm contexts are not included). Maybe InitializeContext(Local context) { - if (InitializeContextForSnapshot(context).IsNothing()) { + if (InitializeMainContextForSnapshot(context).IsNothing()) { return Nothing(); } diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 9fd99f3e396fb0..72856f123b0cdb 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -206,14 +206,16 @@ MaybeLocal ContextifyContext::CreateV8Context( {}, // global object {}, // deserialization callback queue); - if (ctx.IsEmpty()) return MaybeLocal(); + if (ctx.IsEmpty() || InitializeBaseContextForSnapshot(ctx).IsNothing()) { + return MaybeLocal(); + } } else if (!Context::FromSnapshot(isolate, - SnapshotData::kNodeVMContextIndex, - {}, // deserialization callback - nullptr, // extensions - {}, // global object - queue) - .ToLocal(&ctx)) { + SnapshotData::kNodeVMContextIndex, + {}, // deserialization callback + nullptr, // extensions + {}, // global object + queue) + .ToLocal(&ctx)) { return MaybeLocal(); } return scope.Escape(ctx); diff --git a/src/node_internals.h b/src/node_internals.h index 1876452035caf0..de81fbee07c30f 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -92,6 +92,8 @@ void SignalExit(int signal, siginfo_t* info, void* ucontext); std::string GetProcessTitle(const char* default_title); std::string GetHumanReadableProcessName(); +v8::Maybe InitializeBaseContextForSnapshot( + v8::Local context); v8::Maybe InitializeContextRuntime(v8::Local context); v8::Maybe InitializePrimordials(v8::Local context);