Skip to content

Commit ed33a72

Browse files
authored
chore: ensure correct scopes are in place (electron#22397)
1 parent 02cf5ba commit ed33a72

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

shell/app/node_main.cc

+11-8
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,16 @@ int NodeMain(int argc, char* argv[]) {
138138
// Initialize gin::IsolateHolder.
139139
JavascriptEnvironment gin_env(loop);
140140

141+
v8::Isolate* isolate = gin_env.isolate();
142+
141143
node::IsolateData* isolate_data =
142-
node::CreateIsolateData(gin_env.isolate(), loop, gin_env.platform());
144+
node::CreateIsolateData(isolate, loop, gin_env.platform());
143145
CHECK_NE(nullptr, isolate_data);
144146

147+
v8::Locker locker(isolate);
148+
v8::Isolate::Scope isolate_scope(isolate);
149+
v8::HandleScope handle_scope(isolate);
150+
145151
node::Environment* env = node::CreateEnvironment(
146152
isolate_data, gin_env.context(), argc, argv, exec_argc, exec_argv);
147153
CHECK_NE(nullptr, env);
@@ -155,18 +161,17 @@ int NodeMain(int argc, char* argv[]) {
155161

156162
// This is needed in order to enable v8 host weakref hooks.
157163
// TODO(codebytere): we shouldn't have to call this - upstream?
158-
gin_env.isolate()->SetHostCleanupFinalizationGroupCallback(
164+
isolate->SetHostCleanupFinalizationGroupCallback(
159165
HostCleanupFinalizationGroupCallback);
160166

161-
gin_helper::Dictionary process(gin_env.isolate(), env->process_object());
167+
gin_helper::Dictionary process(isolate, env->process_object());
162168
#if defined(OS_WIN)
163169
process.SetMethod("log", &ElectronBindings::Log);
164170
#endif
165171
process.SetMethod("crash", &ElectronBindings::Crash);
166172

167173
// Setup process.crashReporter.start in child node processes
168-
gin_helper::Dictionary reporter =
169-
gin::Dictionary::CreateEmpty(gin_env.isolate());
174+
gin_helper::Dictionary reporter = gin::Dictionary::CreateEmpty(isolate);
170175
reporter.SetMethod("start", &crash_reporter::CrashReporter::StartInstance);
171176

172177
#if !defined(OS_LINUX)
@@ -190,15 +195,13 @@ int NodeMain(int argc, char* argv[]) {
190195
node::LoadEnvironment(env);
191196
}
192197

193-
v8::Isolate* isolate = env->isolate();
194-
195198
{
196199
v8::SealHandleScope seal(isolate);
197200
bool more;
198201
do {
199202
uv_run(env->event_loop(), UV_RUN_DEFAULT);
200203

201-
gin_env.platform()->DrainTasks(env->isolate());
204+
gin_env.platform()->DrainTasks(isolate);
202205

203206
more = uv_loop_alive(env->event_loop());
204207
if (more && !env->is_stopping())

0 commit comments

Comments
 (0)