@@ -16,13 +16,14 @@ namespace coro {
1616// on_resume() already provides a HandleScope and will drain microtasks
1717// and nextTick on close (in on_suspend / final_suspend).
1818//
19- // When used inside an untracked UvTask (no InternalCallbackScope),
20- // these create their own HandleScope .
19+ // These guard against calling V8 APIs when the environment is shutting
20+ // down (can_call_into_js() is false) .
2121// ---------------------------------------------------------------------------
2222
2323inline void ResolvePromise (Environment* env,
2424 v8::Global<v8::Promise::Resolver>& resolver,
2525 v8::Local<v8::Value> value) {
26+ if (!env->can_call_into_js ()) return ;
2627 v8::HandleScope scope (env->isolate ());
2728 auto local = resolver.Get (env->isolate ());
2829 USE (local->Resolve (env->context (), value));
@@ -39,6 +40,7 @@ inline void RejectPromiseWithUVError(
3940 int uv_err,
4041 const char * syscall,
4142 const char * path = nullptr ) {
43+ if (!env->can_call_into_js ()) return ;
4244 v8::HandleScope scope (env->isolate ());
4345 auto local = resolver.Get (env->isolate ());
4446 v8::Local<v8::Value> exception =
@@ -49,11 +51,6 @@ inline void RejectPromiseWithUVError(
4951// ---------------------------------------------------------------------------
5052// MakePromise — Creates a v8::Promise::Resolver, sets the return value
5153// on `args`, and returns a Global handle for use in the coroutine.
52- //
53- // Usage from a binding function:
54- // auto resolver = MakePromise(env, args);
55- // auto task = my_coroutine(env, std::move(resolver), ...);
56- // task.Start();
5754// ---------------------------------------------------------------------------
5855
5956inline v8::Global<v8::Promise::Resolver> MakePromise (
0 commit comments