diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 3fbdd7e7c7d7b8..5783728da28942 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -757,8 +757,15 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo& args) { bool timed_out = false; bool received_signal = false; MaybeLocal result; - auto run = [&]() { - MaybeLocal result = module->Evaluate(context); + { + auto wd = timeout != -1 + ? std::make_optional(isolate, timeout, &timed_out) + : std::nullopt; + auto swd = break_on_sigint ? std::make_optional( + isolate, &received_signal) + : std::nullopt; + + result = module->Evaluate(context); Local res; if (result.ToLocal(&res) && microtask_queue) { @@ -792,29 +799,15 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo& args) { Local outer_context = isolate->GetCurrentContext(); Local resolver; if (!Promise::Resolver::New(outer_context).ToLocal(&resolver)) { - return MaybeLocal(); + result = {}; } if (resolver->Resolve(outer_context, res).IsNothing()) { - return MaybeLocal(); + result = {}; } result = resolver->GetPromise(); microtask_queue->PerformCheckpoint(isolate); } - return result; - }; - if (break_on_sigint && timeout != -1) { - Watchdog wd(isolate, timeout, &timed_out); - SigintWatchdog swd(isolate, &received_signal); - result = run(); - } else if (break_on_sigint) { - SigintWatchdog swd(isolate, &received_signal); - result = run(); - } else if (timeout != -1) { - Watchdog wd(isolate, timeout, &timed_out); - result = run(); - } else { - result = run(); } if (result.IsEmpty()) { diff --git a/src/node_contextify.cc b/src/node_contextify.cc index ef4bc0085404b7..92c7ba0249778d 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -1296,24 +1296,17 @@ bool ContextifyScript::EvalMachine(Local context, MaybeLocal result; bool timed_out = false; bool received_signal = false; - auto run = [&]() { - MaybeLocal result = script->Run(context); + { + auto wd = timeout != -1 ? std::make_optional( + env->isolate(), timeout, &timed_out) + : std::nullopt; + auto swd = break_on_sigint ? std::make_optional( + env->isolate(), &received_signal) + : std::nullopt; + + result = script->Run(context); if (!result.IsEmpty() && mtask_queue != nullptr) mtask_queue->PerformCheckpoint(env->isolate()); - return result; - }; - if (break_on_sigint && timeout != -1) { - Watchdog wd(env->isolate(), timeout, &timed_out); - SigintWatchdog swd(env->isolate(), &received_signal); - result = run(); - } else if (break_on_sigint) { - SigintWatchdog swd(env->isolate(), &received_signal); - result = run(); - } else if (timeout != -1) { - Watchdog wd(env->isolate(), timeout, &timed_out); - result = run(); - } else { - result = run(); } // Convert the termination exception into a regular exception. diff --git a/src/node_watchdog.h b/src/node_watchdog.h index ae70157224b1c7..096e347d7b3f9f 100644 --- a/src/node_watchdog.h +++ b/src/node_watchdog.h @@ -51,6 +51,11 @@ class Watchdog { v8::Isolate* isolate() { return isolate_; } private: + Watchdog(const Watchdog&) = delete; + Watchdog& operator=(const Watchdog&) = delete; + Watchdog(Watchdog&&) = delete; + Watchdog& operator=(Watchdog&&) = delete; + static void Run(void* arg); static void Timer(uv_timer_t* timer); @@ -77,6 +82,11 @@ class SigintWatchdog : public SigintWatchdogBase { SignalPropagation HandleSigint() override; private: + SigintWatchdog(const SigintWatchdog&) = delete; + SigintWatchdog& operator=(const SigintWatchdog&) = delete; + SigintWatchdog(SigintWatchdog&&) = delete; + SigintWatchdog& operator=(SigintWatchdog&&) = delete; + v8::Isolate* isolate_; bool* received_signal_; };