@@ -158,12 +158,13 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
158
158
Context::Scope context_scope (context);
159
159
ScriptCompiler::Source source (source_text, origin);
160
160
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
+ }
167
168
return ;
168
169
}
169
170
}
@@ -245,13 +246,12 @@ void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) {
245
246
Local<Context> context = obj->context_ .Get (isolate);
246
247
Local<Module> module = obj->module_ .Get (isolate);
247
248
TryCatchScope try_catch (env);
248
- Maybe< bool > ok = module->InstantiateModule (context, ResolveCallback);
249
+ USE ( module->InstantiateModule (context, ResolveCallback) );
249
250
250
251
// clear resolve cache on instantiate
251
252
obj->resolve_cache_ .clear ();
252
253
253
- if (!ok.FromMaybe (false )) {
254
- CHECK (try_catch.HasCaught ());
254
+ if (try_catch.HasCaught () && !try_catch.HasTerminated ()) {
255
255
CHECK (!try_catch.Message ().IsEmpty ());
256
256
CHECK (!try_catch.Exception ().IsEmpty ());
257
257
AppendExceptionLine (env, try_catch.Exception (), try_catch.Message (),
@@ -300,6 +300,8 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
300
300
301
301
// Convert the termination exception into a regular exception.
302
302
if (timed_out || received_signal) {
303
+ if (!env->is_main_thread () && env->is_stopping_worker ())
304
+ return ;
303
305
env->isolate ()->CancelTerminateExecution ();
304
306
// It is possible that execution was terminated by another timeout in
305
307
// which this timeout is nested, so check whether one of the watchdogs
@@ -312,7 +314,8 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
312
314
}
313
315
314
316
if (try_catch.HasCaught ()) {
315
- try_catch.ReThrow ();
317
+ if (!try_catch.HasTerminated ())
318
+ try_catch.ReThrow ();
316
319
return ;
317
320
}
318
321
@@ -375,7 +378,6 @@ void ModuleWrap::GetError(const FunctionCallbackInfo<Value>& args) {
375
378
ASSIGN_OR_RETURN_UNWRAP (&obj, args.This ());
376
379
377
380
Local<Module> module = obj->module_ .Get (isolate);
378
-
379
381
args.GetReturnValue ().Set (module->GetException ());
380
382
}
381
383
0 commit comments