fix: don't run environment bootstrapper (#22342)

This commit is contained in:
Shelley Vohr 2020-02-25 16:46:08 +00:00 committed by GitHub
parent 2aa734385e
commit 79270e30a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 79 additions and 158 deletions

View file

@ -142,17 +142,14 @@ int NodeMain(int argc, char* argv[]) {
node::CreateIsolateData(gin_env.isolate(), loop, gin_env.platform());
CHECK_NE(nullptr, isolate_data);
node::Environment* env =
node::CreateEnvironment(isolate_data, gin_env.context(), argc, argv,
exec_argc, exec_argv, false);
node::Environment* env = node::CreateEnvironment(
isolate_data, gin_env.context(), argc, argv, exec_argc, exec_argv);
CHECK_NE(nullptr, env);
// Enable support for v8 inspector.
NodeDebugger node_debugger(env);
node_debugger.Start();
node::BootstrapEnvironment(env);
// TODO(codebytere): we shouldn't have to call this - upstream?
env->InitializeDiagnostics();

View file

@ -296,44 +296,13 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
node_bindings_->Initialize();
// Create the global environment.
node::Environment* env = node_bindings_->CreateEnvironment(
js_env_->context(), js_env_->platform(), false);
js_env_->context(), js_env_->platform());
node_env_ = std::make_unique<NodeEnvironment>(env);
/**
* 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨
* UNSAFE ENVIRONMENT BLOCK BEGINS
*
* DO NOT USE node::Environment inside this block, bad things will happen
* and you won't be able to figure out why. Just don't touch it, the only
* thing that can use it is NodeDebugger and that is ONLY allowed to access
* the inspector agent.
*
* This is unsafe because the environment is not yet bootstrapped, it's a race
* condition where we can't bootstrap before intializing the inspector agent.
*
* Long term we should figure out how to get node to initialize the inspector
* agent in the correct place without us splitting the bootstrap up, but for
* now this works.
* 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨
*/
// Enable support for v8 inspector
node_debugger_ = std::make_unique<NodeDebugger>(env);
node_debugger_->Start();
// Only run the node bootstrapper after we have initialized the inspector
// TODO(MarshallOfSound): Figured out a better way to init the inspector
// before bootstrapping
node::BootstrapEnvironment(env);
/**
*
* UNSAFE ENVIRONMENT BLOCK ENDS
*
* Do whatever you want now with that env, it's safe again
*
*/
// Add Electron extended APIs.
electron_bindings_->BindTo(js_env_->isolate(), env->process_object());

View file

@ -349,8 +349,7 @@ void NodeBindings::Initialize() {
node::Environment* NodeBindings::CreateEnvironment(
v8::Handle<v8::Context> context,
node::MultiIsolatePlatform* platform,
bool bootstrap_env) {
node::MultiIsolatePlatform* platform) {
#if defined(OS_WIN)
auto& atom_args = ElectronCommandLine::argv();
std::vector<std::string> args(atom_args.size());
@ -389,9 +388,8 @@ node::Environment* NodeBindings::CreateEnvironment(
std::unique_ptr<const char*[]> c_argv = StringVectorToArgArray(args);
isolate_data_ =
node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform);
node::Environment* env =
node::CreateEnvironment(isolate_data_, context, args.size(), c_argv.get(),
0, nullptr, bootstrap_env);
node::Environment* env = node::CreateEnvironment(
isolate_data_, context, args.size(), c_argv.get(), 0, nullptr);
DCHECK(env);
// Clean up the global _noBrowserGlobals that we unironically injected into
@ -399,7 +397,6 @@ node::Environment* NodeBindings::CreateEnvironment(
if (browser_env_ != BrowserEnvironment::BROWSER) {
// We need to bootstrap the env in non-browser processes so that
// _noBrowserGlobals is read correctly before we remove it
DCHECK(bootstrap_env);
global.Delete("_noBrowserGlobals");
}

View file

@ -43,8 +43,7 @@ class NodeBindings {
// Create the environment and load node.js.
node::Environment* CreateEnvironment(v8::Handle<v8::Context> context,
node::MultiIsolatePlatform* platform,
bool bootstrap_env);
node::MultiIsolatePlatform* platform);
// Load node.js in the environment.
void LoadEnvironment(node::Environment* env);

View file

@ -125,7 +125,7 @@ void ElectronRendererClient::DidCreateScriptContext(
CHECK(initialized);
node::Environment* env =
node_bindings_->CreateEnvironment(renderer_context, nullptr, true);
node_bindings_->CreateEnvironment(renderer_context, nullptr);
// If we have disabled the site instance overrides we should prevent loading
// any non-context aware native module

View file

@ -52,7 +52,7 @@ void WebWorkerObserver::ContextCreated(v8::Local<v8::Context> worker_context) {
bool initialized = node::InitializeContext(worker_context);
CHECK(initialized);
node::Environment* env =
node_bindings_->CreateEnvironment(worker_context, nullptr, true);
node_bindings_->CreateEnvironment(worker_context, nullptr);
// Add Electron extended APIs.
electron_bindings_->BindTo(env->isolate(), env->process_object());