From ed33a72c23253aebcb20da83dcabca6cc9531cd7 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 28 Feb 2020 23:08:27 +0000 Subject: [PATCH] chore: ensure correct scopes are in place (#22397) --- shell/app/node_main.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/shell/app/node_main.cc b/shell/app/node_main.cc index 7dfee16f401e..25f293f64d66 100644 --- a/shell/app/node_main.cc +++ b/shell/app/node_main.cc @@ -138,10 +138,16 @@ int NodeMain(int argc, char* argv[]) { // Initialize gin::IsolateHolder. JavascriptEnvironment gin_env(loop); + v8::Isolate* isolate = gin_env.isolate(); + node::IsolateData* isolate_data = - node::CreateIsolateData(gin_env.isolate(), loop, gin_env.platform()); + node::CreateIsolateData(isolate, loop, gin_env.platform()); CHECK_NE(nullptr, isolate_data); + v8::Locker locker(isolate); + v8::Isolate::Scope isolate_scope(isolate); + v8::HandleScope handle_scope(isolate); + node::Environment* env = node::CreateEnvironment( isolate_data, gin_env.context(), argc, argv, exec_argc, exec_argv); CHECK_NE(nullptr, env); @@ -155,18 +161,17 @@ int NodeMain(int argc, char* argv[]) { // This is needed in order to enable v8 host weakref hooks. // TODO(codebytere): we shouldn't have to call this - upstream? - gin_env.isolate()->SetHostCleanupFinalizationGroupCallback( + isolate->SetHostCleanupFinalizationGroupCallback( HostCleanupFinalizationGroupCallback); - gin_helper::Dictionary process(gin_env.isolate(), env->process_object()); + gin_helper::Dictionary process(isolate, env->process_object()); #if defined(OS_WIN) process.SetMethod("log", &ElectronBindings::Log); #endif process.SetMethod("crash", &ElectronBindings::Crash); // Setup process.crashReporter.start in child node processes - gin_helper::Dictionary reporter = - gin::Dictionary::CreateEmpty(gin_env.isolate()); + gin_helper::Dictionary reporter = gin::Dictionary::CreateEmpty(isolate); reporter.SetMethod("start", &crash_reporter::CrashReporter::StartInstance); #if !defined(OS_LINUX) @@ -190,15 +195,13 @@ int NodeMain(int argc, char* argv[]) { node::LoadEnvironment(env); } - v8::Isolate* isolate = env->isolate(); - { v8::SealHandleScope seal(isolate); bool more; do { uv_run(env->event_loop(), UV_RUN_DEFAULT); - gin_env.platform()->DrainTasks(env->isolate()); + gin_env.platform()->DrainTasks(isolate); more = uv_loop_alive(env->event_loop()); if (more && !env->is_stopping())