refactor: node::Environment self-cleanup (#39604)

* chore: savepoint

* chore: turn raw_ptr tests back off
This commit is contained in:
Charles Kerr 2023-08-23 08:56:16 -05:00 committed by GitHub
parent a8999bc529
commit 35969939a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 95 additions and 83 deletions

View file

@ -266,26 +266,25 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
node_bindings_->Initialize(js_env_->isolate()->GetCurrentContext());
// Create the global environment.
node::Environment* env = node_bindings_->CreateEnvironment(
node_env_ = node_bindings_->CreateEnvironment(
js_env_->isolate()->GetCurrentContext(), js_env_->platform());
node_env_ = std::make_unique<NodeEnvironment>(env);
env->set_trace_sync_io(env->options()->trace_sync_io);
node_env_->set_trace_sync_io(node_env_->options()->trace_sync_io);
// We do not want to crash the main process on unhandled rejections.
env->options()->unhandled_rejections = "warn-with-error-code";
node_env_->options()->unhandled_rejections = "warn-with-error-code";
// Add Electron extended APIs.
electron_bindings_->BindTo(js_env_->isolate(), env->process_object());
electron_bindings_->BindTo(js_env_->isolate(), node_env_->process_object());
// Create explicit microtasks runner.
js_env_->CreateMicrotasksRunner();
// Wrap the uv loop with global env.
node_bindings_->set_uv_env(env);
node_bindings_->set_uv_env(node_env_.get());
// Load everything.
node_bindings_->LoadEnvironment(env);
node_bindings_->LoadEnvironment(node_env_.get());
// We already initialized the feature list in PreEarlyInitialization(), but
// the user JS script would not have had a chance to alter the command-line
@ -627,9 +626,9 @@ void ElectronBrowserMainParts::PostMainMessageLoopRun() {
// Destroy node platform after all destructors_ are executed, as they may
// invoke Node/V8 APIs inside them.
node_env_->env()->set_trace_sync_io(false);
node_env_->set_trace_sync_io(false);
js_env_->DestroyMicrotasksRunner();
node::Stop(node_env_->env(), node::StopFlags::kDoNotTerminateIsolate);
node::Stop(node_env_.get(), node::StopFlags::kDoNotTerminateIsolate);
node_env_.reset();
auto default_context_key = ElectronBrowserContext::PartitionKey("", false);