chore: update to Node.js v12.4.0 (#18924)
* chore: update to node 12.4.0 * chore: fix js2c compilation and usage * update branch reference * chore: roll node * refactor: use the new node::options_parser::Parse method * fix: make node create our context for us so that everything is initialized correctly * fix: let node do it's thing to the all contexts We need to let node know about all the contexts that Chromium creates for the renderer processes so that it does not crash when trying to access primordials. Similar to node::NewContext but with an existing context * chore: roll node * chore: roll node * chore: roll node * chore: roll node * fix: ensure that _noBrowserGlobals is set before the node bootstrapper runs Co-authored-by: Jeremy Apthorp <jeremya@chromium.org>
This commit is contained in:
parent
da672a3b5c
commit
aa211c6c50
10 changed files with 40 additions and 24 deletions
2
BUILD.gn
2
BUILD.gn
|
@ -176,7 +176,7 @@ action("atom_js2c") {
|
||||||
"$target_gen_dir/js2c/asar_init.js",
|
"$target_gen_dir/js2c/asar_init.js",
|
||||||
]
|
]
|
||||||
|
|
||||||
inputs = sources
|
inputs = sources + [ "//third_party/electron_node/tools/js2c.py" ]
|
||||||
outputs = [
|
outputs = [
|
||||||
"$root_gen_dir/atom_natives.cc",
|
"$root_gen_dir/atom_natives.cc",
|
||||||
]
|
]
|
||||||
|
|
2
DEPS
2
DEPS
|
@ -12,7 +12,7 @@ vars = {
|
||||||
'chromium_version':
|
'chromium_version':
|
||||||
'5a48e127c8cb8ae827f4fead0b527079194b9899',
|
'5a48e127c8cb8ae827f4fead0b527079194b9899',
|
||||||
'node_version':
|
'node_version':
|
||||||
'780436005ffc7f317abfba48b236428858284e99',
|
'cbb519597cf085e7d759080c6a6b8f1c4dab85bc',
|
||||||
'nan_version':
|
'nan_version':
|
||||||
'2ee313aaca52e2b478965ac50eb5082520380d1b',
|
'2ee313aaca52e2b478965ac50eb5082520380d1b',
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ JavascriptEnvironment::JavascriptEnvironment(uv_loop_t* event_loop)
|
||||||
isolate_scope_(isolate_),
|
isolate_scope_(isolate_),
|
||||||
locker_(isolate_),
|
locker_(isolate_),
|
||||||
handle_scope_(isolate_),
|
handle_scope_(isolate_),
|
||||||
context_(isolate_, v8::Context::New(isolate_)),
|
context_(isolate_, node::NewContext(isolate_)),
|
||||||
context_scope_(v8::Local<v8::Context>::New(isolate_, context_)) {}
|
context_scope_(v8::Local<v8::Context>::New(isolate_, context_)) {}
|
||||||
|
|
||||||
JavascriptEnvironment::~JavascriptEnvironment() = default;
|
JavascriptEnvironment::~JavascriptEnvironment() = default;
|
||||||
|
|
|
@ -37,13 +37,13 @@ void NodeDebugger::Start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
node::DebugOptions options;
|
node::DebugOptions options;
|
||||||
node::options_parser::DebugOptionsParser options_parser;
|
|
||||||
std::vector<std::string> exec_args;
|
std::vector<std::string> exec_args;
|
||||||
std::vector<std::string> v8_args;
|
std::vector<std::string> v8_args;
|
||||||
std::vector<std::string> errors;
|
std::vector<std::string> errors;
|
||||||
|
|
||||||
options_parser.Parse(&args, &exec_args, &v8_args, &options,
|
node::options_parser::Parse(&args, &exec_args, &v8_args, &options,
|
||||||
node::options_parser::kDisallowedInEnvironment, &errors);
|
node::options_parser::kDisallowedInEnvironment,
|
||||||
|
&errors);
|
||||||
|
|
||||||
if (!errors.empty()) {
|
if (!errors.empty()) {
|
||||||
// TODO(jeremy): what's the appropriate behaviour here?
|
// TODO(jeremy): what's the appropriate behaviour here?
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include "shell/common/native_mate_converters/callback.h"
|
#include "shell/common/native_mate_converters/callback.h"
|
||||||
#include "shell/common/native_mate_converters/file_path_converter.h"
|
#include "shell/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "third_party/electron_node/src/node_native_module.h"
|
#include "third_party/electron_node/src/node_native_module_env.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ void InitAsarSupport(v8::Isolate* isolate, v8::Local<v8::Value> require) {
|
||||||
std::vector<v8::Local<v8::String>> asar_init_params = {
|
std::vector<v8::Local<v8::String>> asar_init_params = {
|
||||||
node::FIXED_ONE_BYTE_STRING(isolate, "require")};
|
node::FIXED_ONE_BYTE_STRING(isolate, "require")};
|
||||||
std::vector<v8::Local<v8::Value>> asar_init_args = {require};
|
std::vector<v8::Local<v8::Value>> asar_init_args = {require};
|
||||||
node::per_process::native_module_loader.CompileAndCall(
|
node::native_module::NativeModuleEnv::CompileAndCall(
|
||||||
isolate->GetCurrentContext(), "electron/js2c/asar_init",
|
isolate->GetCurrentContext(), "electron/js2c/asar_init",
|
||||||
&asar_init_params, &asar_init_args, nullptr);
|
&asar_init_params, &asar_init_args, nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,6 +311,14 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
process_type = "worker";
|
process_type = "worker";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mate::Dictionary global(context->GetIsolate(), context->Global());
|
||||||
|
// Do not set DOM globals for renderer process.
|
||||||
|
// We must set this before the node bootstrapper which is run inside
|
||||||
|
// CreateEnvironment
|
||||||
|
if (browser_env_ != BrowserEnvironment::BROWSER)
|
||||||
|
global.Set("_noBrowserGlobals", true);
|
||||||
|
|
||||||
base::FilePath resources_path = GetResourcesPath();
|
base::FilePath resources_path = GetResourcesPath();
|
||||||
std::string init_script = "electron/js2c/" + process_type + "_init";
|
std::string init_script = "electron/js2c/" + process_type + "_init";
|
||||||
|
|
||||||
|
@ -320,6 +328,12 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
node::Environment* env = node::CreateEnvironment(
|
node::Environment* env = node::CreateEnvironment(
|
||||||
node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform),
|
node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform),
|
||||||
context, args.size(), c_argv.get(), 0, nullptr);
|
context, args.size(), c_argv.get(), 0, nullptr);
|
||||||
|
DCHECK(env);
|
||||||
|
|
||||||
|
// Clean up the global _noBrowserGlobals that we unironically injected into
|
||||||
|
// the global scope
|
||||||
|
if (browser_env_ != BrowserEnvironment::BROWSER)
|
||||||
|
global.Delete("_noBrowserGlobals");
|
||||||
|
|
||||||
if (browser_env_ == BrowserEnvironment::BROWSER) {
|
if (browser_env_ == BrowserEnvironment::BROWSER) {
|
||||||
// SetAutorunMicrotasks is no longer called in node::CreateEnvironment
|
// SetAutorunMicrotasks is no longer called in node::CreateEnvironment
|
||||||
|
@ -334,9 +348,6 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
mate::Dictionary process(context->GetIsolate(), env->process_object());
|
mate::Dictionary process(context->GetIsolate(), env->process_object());
|
||||||
process.SetReadOnly("type", process_type);
|
process.SetReadOnly("type", process_type);
|
||||||
process.Set("resourcesPath", resources_path);
|
process.Set("resourcesPath", resources_path);
|
||||||
// Do not set DOM globals for renderer process.
|
|
||||||
if (browser_env_ != BrowserEnvironment::BROWSER)
|
|
||||||
process.Set("_noBrowserGlobals", true);
|
|
||||||
// The path to helper app.
|
// The path to helper app.
|
||||||
base::FilePath helper_exec_path;
|
base::FilePath helper_exec_path;
|
||||||
base::PathService::Get(content::CHILD_PROCESS_EXE, &helper_exec_path);
|
base::PathService::Get(content::CHILD_PROCESS_EXE, &helper_exec_path);
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "shell/renderer/web_worker_observer.h"
|
#include "shell/renderer/web_worker_observer.h"
|
||||||
#include "third_party/blink/public/web/web_document.h"
|
#include "third_party/blink/public/web/web_document.h"
|
||||||
#include "third_party/blink/public/web/web_local_frame.h"
|
#include "third_party/blink/public/web/web_local_frame.h"
|
||||||
#include "third_party/electron_node/src/node_native_module.h"
|
#include "third_party/electron_node/src/node_native_module_env.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
@ -67,9 +67,9 @@ void AtomRendererClient::RunScriptsAtDocumentEnd(
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomRendererClient::DidCreateScriptContext(
|
void AtomRendererClient::DidCreateScriptContext(
|
||||||
v8::Handle<v8::Context> context,
|
v8::Handle<v8::Context> renderer_context,
|
||||||
content::RenderFrame* render_frame) {
|
content::RenderFrame* render_frame) {
|
||||||
RendererClientBase::DidCreateScriptContext(context, render_frame);
|
RendererClientBase::DidCreateScriptContext(renderer_context, render_frame);
|
||||||
|
|
||||||
// TODO(zcbenz): Do not create Node environment if node integration is not
|
// TODO(zcbenz): Do not create Node environment if node integration is not
|
||||||
// enabled.
|
// enabled.
|
||||||
|
@ -103,6 +103,9 @@ void AtomRendererClient::DidCreateScriptContext(
|
||||||
node::tracing::TraceEventHelper::SetAgent(node::CreateAgent());
|
node::tracing::TraceEventHelper::SetAgent(node::CreateAgent());
|
||||||
|
|
||||||
// Setup node environment for each window.
|
// Setup node environment for each window.
|
||||||
|
v8::Local<v8::Context> context =
|
||||||
|
node::MaybeInitializeContext(renderer_context);
|
||||||
|
DCHECK(!context.IsEmpty());
|
||||||
node::Environment* env = node_bindings_->CreateEnvironment(context);
|
node::Environment* env = node_bindings_->CreateEnvironment(context);
|
||||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||||
// If we have disabled the site instance overrides we should prevent loading
|
// If we have disabled the site instance overrides we should prevent loading
|
||||||
|
@ -209,7 +212,7 @@ void AtomRendererClient::SetupMainWorldOverrides(
|
||||||
env->process_object(),
|
env->process_object(),
|
||||||
GetContext(render_frame->GetWebFrame(), isolate)->Global()};
|
GetContext(render_frame->GetWebFrame(), isolate)->Global()};
|
||||||
|
|
||||||
node::per_process::native_module_loader.CompileAndCall(
|
node::native_module::NativeModuleEnv::CompileAndCall(
|
||||||
context, "electron/js2c/isolated_bundle", &isolated_bundle_params,
|
context, "electron/js2c/isolated_bundle", &isolated_bundle_params,
|
||||||
&isolated_bundle_args, nullptr);
|
&isolated_bundle_args, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -234,7 +237,7 @@ void AtomRendererClient::SetupExtensionWorldOverrides(
|
||||||
GetContext(render_frame->GetWebFrame(), isolate)->Global(),
|
GetContext(render_frame->GetWebFrame(), isolate)->Global(),
|
||||||
v8::Integer::New(isolate, world_id)};
|
v8::Integer::New(isolate, world_id)};
|
||||||
|
|
||||||
node::per_process::native_module_loader.CompileAndCall(
|
node::native_module::NativeModuleEnv::CompileAndCall(
|
||||||
context, "electron/js2c/content_script_bundle", &isolated_bundle_params,
|
context, "electron/js2c/content_script_bundle", &isolated_bundle_params,
|
||||||
&isolated_bundle_args, nullptr);
|
&isolated_bundle_args, nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "third_party/blink/public/web/blink.h"
|
#include "third_party/blink/public/web/blink.h"
|
||||||
#include "third_party/blink/public/web/web_document.h"
|
#include "third_party/blink/public/web/web_document.h"
|
||||||
#include "third_party/electron_node/src/node_binding.h"
|
#include "third_party/electron_node/src/node_binding.h"
|
||||||
#include "third_party/electron_node/src/node_native_module.h"
|
#include "third_party/electron_node/src/node_native_module_env.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
|
||||||
|
|
||||||
std::vector<v8::Local<v8::Value>> sandbox_preload_bundle_args = {binding};
|
std::vector<v8::Local<v8::Value>> sandbox_preload_bundle_args = {binding};
|
||||||
|
|
||||||
node::per_process::native_module_loader.CompileAndCall(
|
node::native_module::NativeModuleEnv::CompileAndCall(
|
||||||
isolate->GetCurrentContext(), "electron/js2c/sandbox_bundle",
|
isolate->GetCurrentContext(), "electron/js2c/sandbox_bundle",
|
||||||
&sandbox_preload_bundle_params, &sandbox_preload_bundle_args, nullptr);
|
&sandbox_preload_bundle_params, &sandbox_preload_bundle_args, nullptr);
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ void AtomSandboxedRendererClient::SetupMainWorldOverrides(
|
||||||
process.GetHandle(),
|
process.GetHandle(),
|
||||||
GetContext(render_frame->GetWebFrame(), isolate)->Global()};
|
GetContext(render_frame->GetWebFrame(), isolate)->Global()};
|
||||||
|
|
||||||
node::per_process::native_module_loader.CompileAndCall(
|
node::native_module::NativeModuleEnv::CompileAndCall(
|
||||||
context, "electron/js2c/isolated_bundle", &isolated_bundle_params,
|
context, "electron/js2c/isolated_bundle", &isolated_bundle_params,
|
||||||
&isolated_bundle_args, nullptr);
|
&isolated_bundle_args, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ void AtomSandboxedRendererClient::SetupExtensionWorldOverrides(
|
||||||
GetContext(render_frame->GetWebFrame(), isolate)->Global(),
|
GetContext(render_frame->GetWebFrame(), isolate)->Global(),
|
||||||
v8::Integer::New(isolate, world_id)};
|
v8::Integer::New(isolate, world_id)};
|
||||||
|
|
||||||
node::per_process::native_module_loader.CompileAndCall(
|
node::native_module::NativeModuleEnv::CompileAndCall(
|
||||||
context, "electron/js2c/content_script_bundle", &isolated_bundle_params,
|
context, "electron/js2c/content_script_bundle", &isolated_bundle_params,
|
||||||
&isolated_bundle_args, nullptr);
|
&isolated_bundle_args, nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,13 +41,15 @@ WebWorkerObserver::~WebWorkerObserver() {
|
||||||
asar::ClearArchives();
|
asar::ClearArchives();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebWorkerObserver::ContextCreated(v8::Local<v8::Context> context) {
|
void WebWorkerObserver::ContextCreated(v8::Local<v8::Context> worker_context) {
|
||||||
v8::Context::Scope context_scope(context);
|
v8::Context::Scope context_scope(worker_context);
|
||||||
|
|
||||||
// Start the embed thread.
|
// Start the embed thread.
|
||||||
node_bindings_->PrepareMessageLoop();
|
node_bindings_->PrepareMessageLoop();
|
||||||
|
|
||||||
// Setup node environment for each window.
|
// Setup node environment for each window.
|
||||||
|
v8::Local<v8::Context> context = node::MaybeInitializeContext(worker_context);
|
||||||
|
DCHECK(!context.IsEmpty());
|
||||||
node::Environment* env = node_bindings_->CreateEnvironment(context);
|
node::Environment* env = node_bindings_->CreateEnvironment(context);
|
||||||
|
|
||||||
// Add Electron extended APIs.
|
// Add Electron extended APIs.
|
||||||
|
|
|
@ -30,9 +30,9 @@ def main():
|
||||||
|
|
||||||
js2c = os.path.join(node_path, 'tools', 'js2c.py')
|
js2c = os.path.join(node_path, 'tools', 'js2c.py')
|
||||||
subprocess.check_call(
|
subprocess.check_call(
|
||||||
[sys.executable, js2c, natives] +
|
[sys.executable, js2c] +
|
||||||
js_source_files +
|
js_source_files +
|
||||||
['-t', TEMPLATE])
|
['--only-js', '--target', natives])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Reference in a new issue