From 3a6bc90c29edd69e84ca97cd986125f29b9f085a Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Mon, 16 Sep 2019 16:05:20 -0500 Subject: [PATCH] src: re-delete Atomics.wake PR-URL: https://github.com/nodejs/node/pull/29586 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Joyee Cheung Reviewed-By: Colin Ihrig Reviewed-By: David Carlier --- lib/internal/bootstrap/node.js | 2 -- lib/internal/per_context/setup.js | 15 ------------- node.gyp | 1 - src/api/environment.cc | 34 +++++++++++++++++++++++++++++- src/node_internals.h | 2 ++ src/node_main_instance.cc | 1 + test/parallel/test-atomics-wake.js | 7 ++++++ 7 files changed, 43 insertions(+), 19 deletions(-) delete mode 100644 lib/internal/per_context/setup.js create mode 100644 test/parallel/test-atomics-wake.js diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 86b2164bb0d74a..18acd9d2b64774 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -15,8 +15,6 @@ // many dependencies are invoked lazily. // // Scripts run before this file: -// - `lib/internal/per_context/setup.js`: to setup the v8::Context with -// Node.js-specific tweaks - this is also done in vm contexts. // - `lib/internal/per_context/primordials.js`: to save copies of JavaScript // builtins that won't be affected by user land monkey-patching for internal // modules to use. diff --git a/lib/internal/per_context/setup.js b/lib/internal/per_context/setup.js deleted file mode 100644 index 16bd7db586b156..00000000000000 --- a/lib/internal/per_context/setup.js +++ /dev/null @@ -1,15 +0,0 @@ -// This file is compiled as if it's wrapped in a function with arguments -// passed by node::NewContext() -/* global global */ - -'use strict'; - -// https://github.com/nodejs/node/issues/14909 -if (global.Intl) { - delete global.Intl.v8BreakIterator; -} - -// https://github.com/nodejs/node/issues/21219 -if (global.Atomics) { - delete global.Atomics.wake; -} diff --git a/node.gyp b/node.gyp index 1d45f5117144b0..d50ec1c36b82d5 100644 --- a/node.gyp +++ b/node.gyp @@ -30,7 +30,6 @@ 'lib/internal/bootstrap/node.js', 'lib/internal/bootstrap/pre_execution.js', 'lib/internal/per_context/primordials.js', - 'lib/internal/per_context/setup.js', 'lib/internal/per_context/domexception.js', 'lib/async_hooks.js', 'lib/assert.js', diff --git a/src/api/environment.cc b/src/api/environment.cc index 7fd219d6e8fcfe..2c0fe1306319b2 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -357,9 +357,42 @@ Local NewContext(Isolate* isolate, if (!InitializeContext(context)) { return Local(); } + + InitializeContextRuntime(context); + return context; } +// This runs at runtime, regardless of whether the context +// is created from a snapshot. +void 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) && + intl_v->IsObject()) { + Local intl = intl_v.As(); + intl->Delete(context, break_iter_string).FromJust(); + } + + // 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) && + atomics_v->IsObject()) { + Local atomics = atomics_v.As(); + atomics->Delete(context, wake_string).FromJust(); + } +} + bool InitializeContext(Local context) { Isolate* isolate = context->GetIsolate(); HandleScope handle_scope(isolate); @@ -386,7 +419,6 @@ bool InitializeContext(Local context) { } static const char* context_files[] = {"internal/per_context/primordials", - "internal/per_context/setup", "internal/per_context/domexception", nullptr}; diff --git a/src/node_internals.h b/src/node_internals.h index 621ed0225ba674..85d2c5c1f18db0 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -102,6 +102,8 @@ void RegisterSignalHandler(int signal, std::string GetHumanReadableProcessName(); void GetHumanReadableProcessName(char (*name)[1024]); +void InitializeContextRuntime(v8::Local); + namespace task_queue { void PromiseRejectCallback(v8::PromiseRejectMessage message); } // namespace task_queue diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index 05ff8d55267511..630933cec8a4d7 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -179,6 +179,7 @@ std::unique_ptr NodeMainInstance::CreateMainEnvironment( if (deserialize_mode_) { context = Context::FromSnapshot(isolate_, kNodeContextIndex).ToLocalChecked(); + InitializeContextRuntime(context); SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers); } else { context = NewContext(isolate_); diff --git a/test/parallel/test-atomics-wake.js b/test/parallel/test-atomics-wake.js new file mode 100644 index 00000000000000..0f387001764da2 --- /dev/null +++ b/test/parallel/test-atomics-wake.js @@ -0,0 +1,7 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); + +// https://github.com/nodejs/node/issues/21219 +assert.strictEqual(Atomics.wake, undefined);