@@ -158,12 +158,13 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
158158 Context::Scope context_scope (context);
159159 ScriptCompiler::Source source (source_text, origin);
160160 if (!ScriptCompiler::CompileModule (isolate, &source).ToLocal (&module )) {
161- CHECK (try_catch.HasCaught ());
162- CHECK (!try_catch.Message ().IsEmpty ());
163- CHECK (!try_catch.Exception ().IsEmpty ());
164- AppendExceptionLine (env, try_catch.Exception (), try_catch.Message (),
165- ErrorHandlingMode::MODULE_ERROR);
166- try_catch.ReThrow ();
161+ if (try_catch.HasCaught () && !try_catch.HasTerminated ()) {
162+ CHECK (!try_catch.Message ().IsEmpty ());
163+ CHECK (!try_catch.Exception ().IsEmpty ());
164+ AppendExceptionLine (env, try_catch.Exception (), try_catch.Message (),
165+ ErrorHandlingMode::MODULE_ERROR);
166+ try_catch.ReThrow ();
167+ }
167168 return ;
168169 }
169170 }
@@ -245,13 +246,12 @@ void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) {
245246 Local<Context> context = obj->context_ .Get (isolate);
246247 Local<Module> module = obj->module_ .Get (isolate);
247248 TryCatchScope try_catch (env);
248- Maybe< bool > ok = module ->InstantiateModule (context, ResolveCallback);
249+ USE ( module ->InstantiateModule (context, ResolveCallback) );
249250
250251 // clear resolve cache on instantiate
251252 obj->resolve_cache_ .clear ();
252253
253- if (!ok.FromMaybe (false )) {
254- CHECK (try_catch.HasCaught ());
254+ if (try_catch.HasCaught () && !try_catch.HasTerminated ()) {
255255 CHECK (!try_catch.Message ().IsEmpty ());
256256 CHECK (!try_catch.Exception ().IsEmpty ());
257257 AppendExceptionLine (env, try_catch.Exception (), try_catch.Message (),
@@ -300,6 +300,8 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
300300
301301 // Convert the termination exception into a regular exception.
302302 if (timed_out || received_signal) {
303+ if (!env->is_main_thread () && env->is_stopping_worker ())
304+ return ;
303305 env->isolate ()->CancelTerminateExecution ();
304306 // It is possible that execution was terminated by another timeout in
305307 // which this timeout is nested, so check whether one of the watchdogs
@@ -312,7 +314,8 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
312314 }
313315
314316 if (try_catch.HasCaught ()) {
315- try_catch.ReThrow ();
317+ if (!try_catch.HasTerminated ())
318+ try_catch.ReThrow ();
316319 return ;
317320 }
318321
@@ -375,7 +378,6 @@ void ModuleWrap::GetError(const FunctionCallbackInfo<Value>& args) {
375378 ASSIGN_OR_RETURN_UNWRAP (&obj, args.This ());
376379
377380 Local<Module> module = obj->module_ .Get (isolate);
378-
379381 args.GetReturnValue ().Set (module ->GetException ());
380382}
381383
0 commit comments