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

@ -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());