@@ -56,9 +56,11 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
5656 return ;
5757 }
5858
59- HandleScope handle_scope (env->isolate ());
59+ Isolate* isolate = env->isolate ();
60+
61+ HandleScope handle_scope (isolate);
6062 // If you hit this assertion, you forgot to enter the v8::Context first.
61- CHECK_EQ (Environment::GetCurrent (env-> isolate () ), env);
63+ CHECK_EQ (Environment::GetCurrent (isolate), env);
6264
6365 env->isolate ()->SetIdle (false );
6466
@@ -83,7 +85,8 @@ void InternalCallbackScope::Close() {
8385 if (closed_) return ;
8486 closed_ = true ;
8587
86- auto idle = OnScopeLeave ([&]() { env_->isolate ()->SetIdle (true ); });
88+ Isolate* isolate = env_->isolate ();
89+ auto idle = OnScopeLeave ([&]() { isolate->SetIdle (true ); });
8790
8891 if (!env_->can_call_into_js ()) return ;
8992 auto perform_stopping_check = [&]() {
@@ -113,8 +116,9 @@ void InternalCallbackScope::Close() {
113116
114117 auto weakref_cleanup = OnScopeLeave ([&]() { env_->RunWeakRefCleanup (); });
115118
119+ Local<Context> context = env_->context ();
116120 if (!tick_info->has_tick_scheduled ()) {
117- env_-> context () ->GetMicrotaskQueue ()->PerformCheckpoint (env_-> isolate () );
121+ context->GetMicrotaskQueue ()->PerformCheckpoint (isolate);
118122
119123 perform_stopping_check ();
120124 }
@@ -130,7 +134,7 @@ void InternalCallbackScope::Close() {
130134 return ;
131135 }
132136
133- HandleScope handle_scope (env_-> isolate () );
137+ HandleScope handle_scope (isolate);
134138 Local<Object> process = env_->process_object ();
135139
136140 if (!env_->can_call_into_js ()) return ;
@@ -141,7 +145,7 @@ void InternalCallbackScope::Close() {
141145 // to initializes the tick callback during bootstrap.
142146 CHECK (!tick_callback.IsEmpty ());
143147
144- if (tick_callback->Call (env_-> context () , process, 0 , nullptr ).IsEmpty ()) {
148+ if (tick_callback->Call (context, process, 0 , nullptr ).IsEmpty ()) {
145149 failed_ = true ;
146150 }
147151 perform_stopping_check ();
@@ -181,6 +185,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,
181185
182186 MaybeLocal<Value> ret;
183187
188+ Local<Context> context = env->context ();
184189 if (use_async_hooks_trampoline) {
185190 MaybeStackBuffer<Local<Value>, 16 > args (3 + argc);
186191 args[0 ] = v8::Number::New (env->isolate (), asyncContext.async_id );
@@ -189,9 +194,9 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,
189194 for (int i = 0 ; i < argc; i++) {
190195 args[i + 3 ] = argv[i];
191196 }
192- ret = hook_cb->Call (env-> context () , recv, args.length (), &args[0 ]);
197+ ret = hook_cb->Call (context, recv, args.length (), &args[0 ]);
193198 } else {
194- ret = callback->Call (env-> context () , recv, argc, argv);
199+ ret = callback->Call (context, recv, argc, argv);
195200 }
196201
197202 if (ret.IsEmpty ()) {
@@ -266,7 +271,7 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
266271 if (ret.IsEmpty () && env->async_callback_scope_depth () == 0 ) {
267272 // This is only for legacy compatibility and we may want to look into
268273 // removing/adjusting it.
269- return Undefined (env-> isolate () );
274+ return Undefined (isolate);
270275 }
271276 return ret;
272277}
@@ -285,11 +290,12 @@ MaybeLocal<Value> MakeSyncCallback(Isolate* isolate,
285290 CHECK_NOT_NULL (env);
286291 if (!env->can_call_into_js ()) return Local<Value>();
287292
288- Context::Scope context_scope (env->context ());
293+ Local<Context> context = env->context ();
294+ Context::Scope context_scope (context);
289295 if (env->async_callback_scope_depth ()) {
290296 // There's another MakeCallback() on the stack, piggy back on it.
291297 // In particular, retain the current async_context.
292- return callback->Call (env-> context () , recv, argc, argv);
298+ return callback->Call (context, recv, argc, argv);
293299 }
294300
295301 // This is a toplevel invocation and the caller (intentionally)
0 commit comments