From 3cffe05a190085d141d97ce6ac1c35128a88ea62 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 29 Jun 2018 09:50:45 -0700 Subject: [PATCH] Revert "src: move context bootstrap to js" This reverts commit d13cdd9c485a2f167f9901f238b4412f2b8bb3e0. --- lib/internal/per_context.js | 52 ------------------------------------- node.gyp | 1 - src/node.cc | 36 ++++++++++++++++++------- src/node.h | 4 ++- src/node_javascript.h | 1 - tools/js2c.py | 4 --- 6 files changed, 29 insertions(+), 69 deletions(-) delete mode 100644 lib/internal/per_context.js diff --git a/lib/internal/per_context.js b/lib/internal/per_context.js deleted file mode 100644 index bdbad5344ff430..00000000000000 --- a/lib/internal/per_context.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -// node::NewContext calls this script - -(function(global) { - // https://github.com/nodejs/node/issues/14909 - delete global.Intl.v8BreakIterator; - - // https://github.com/nodejs/node/issues/21219 - // Adds Atomics.notify and warns on first usage of Atomics.wake - - const AtomicsWake = global.Atomics.wake; - const ReflectApply = global.Reflect.apply; - - // wrap for function.name - function notify(...args) { - return ReflectApply(AtomicsWake, this, args); - } - - const warning = 'Atomics.wake will be removed in a future version, ' + - 'use Atomics.notify instead.'; - - let wakeWarned = false; - function wake(...args) { - if (!wakeWarned) { - wakeWarned = true; - - if (global.process !== undefined) { - global.process.emitWarning(warning, 'Atomics'); - } else { - global.console.error(`Atomics: ${warning}`); - } - } - - return ReflectApply(AtomicsWake, this, args); - } - - global.Object.defineProperties(global.Atomics, { - notify: { - value: notify, - writable: true, - enumerable: false, - configurable: true, - }, - wake: { - value: wake, - writable: true, - enumerable: false, - configurable: true, - }, - }); -}(this)); diff --git a/node.gyp b/node.gyp index a1f7255fe86363..f11b022e6790e0 100644 --- a/node.gyp +++ b/node.gyp @@ -25,7 +25,6 @@ 'node_lib_target_name%': 'node_lib', 'node_intermediate_lib_type%': 'static_library', 'library_files': [ - 'lib/internal/per_context.js', 'lib/internal/bootstrap/cache.js', 'lib/internal/bootstrap/loaders.js', 'lib/internal/bootstrap/node.js', diff --git a/src/node.cc b/src/node.cc index 0db313fd36b81e..acc5ab3a1e78e9 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3497,19 +3497,35 @@ Local NewContext(Isolate* isolate, auto context = Context::New(isolate, nullptr, object_template); if (context.IsEmpty()) return context; HandleScope handle_scope(isolate); - context->SetEmbedderData( ContextEmbedderIndex::kAllowWasmCodeGeneration, True(isolate)); - { - // Run lib/internal/per_context.js - Context::Scope context_scope(context); - Local per_context = NodePerContextSource(isolate); - v8::ScriptCompiler::Source per_context_src(per_context, nullptr); - Local s = v8::ScriptCompiler::Compile( - context, - &per_context_src).ToLocalChecked(); - s->Run(context).ToLocalChecked(); + auto intl_key = FIXED_ONE_BYTE_STRING(isolate, "Intl"); + auto break_iter_key = FIXED_ONE_BYTE_STRING(isolate, "v8BreakIterator"); + Local intl_v; + if (context->Global()->Get(context, intl_key).ToLocal(&intl_v) && + intl_v->IsObject()) { + Local intl = intl_v.As(); + intl->Delete(context, break_iter_key).FromJust(); + } + + // https://github.com/nodejs/node/issues/21219 + // TODO(devsnek): remove when v8 supports Atomics.notify + auto atomics_key = FIXED_ONE_BYTE_STRING(isolate, "Atomics"); + Local atomics_v; + if (context->Global()->Get(context, atomics_key).ToLocal(&atomics_v) && + atomics_v->IsObject()) { + Local atomics = atomics_v.As(); + auto wake_key = FIXED_ONE_BYTE_STRING(isolate, "wake"); + + Local wake = atomics->Get(context, wake_key).ToLocalChecked(); + auto notify_key = FIXED_ONE_BYTE_STRING(isolate, "notify"); + + v8::PropertyDescriptor desc(wake, true); + desc.set_enumerable(false); + desc.set_configurable(true); + + atomics->DefineProperty(context, notify_key, desc).ToChecked(); } return context; diff --git a/src/node.h b/src/node.h index b551c8bb09baf9..90b2a8cbf690ce 100644 --- a/src/node.h +++ b/src/node.h @@ -241,7 +241,9 @@ class MultiIsolatePlatform : public v8::Platform { // Creates a new isolate with Node.js-specific settings. NODE_EXTERN v8::Isolate* NewIsolate(ArrayBufferAllocator* allocator); -// Creates a new context with Node.js-specific tweaks. +// Creates a new context with Node.js-specific tweaks. Currently, it removes +// the `v8BreakIterator` property from the global `Intl` object if present. +// See https://github.com/nodejs/node/issues/14909 for more info. NODE_EXTERN v8::Local NewContext( v8::Isolate* isolate, v8::Local object_template = diff --git a/src/node_javascript.h b/src/node_javascript.h index 00cdc0c0b6c13e..d1ad9a25745e9b 100644 --- a/src/node_javascript.h +++ b/src/node_javascript.h @@ -29,7 +29,6 @@ namespace node { void DefineJavaScript(Environment* env, v8::Local target); -v8::Local NodePerContextSource(v8::Isolate* isolate); v8::Local LoadersBootstrapperSource(Environment* env); v8::Local NodeBootstrapperSource(Environment* env); diff --git a/tools/js2c.py b/tools/js2c.py index 249df58085dd96..38cf39f81677dd 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -189,10 +189,6 @@ def ReadMacros(lines): }} // anonymous namespace -v8::Local NodePerContextSource(v8::Isolate* isolate) {{ - return internal_per_context_value.ToStringChecked(isolate); -}} - v8::Local LoadersBootstrapperSource(Environment* env) {{ return internal_bootstrap_loaders_value.ToStringChecked(env->isolate()); }}