| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 49747a5 commit f14ed5a
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -757,8 +757,15 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) { | |||
| 757 | 757 | bool timed_out = false; | |
| 758 | 758 | bool received_signal = false; | |
| 759 | 759 | MaybeLocal<Value> result; | |
| 760 | - auto run = [&]() { | ||
| 761 | - MaybeLocal<Value> result = module->Evaluate(context); | ||
| 760 | + { | ||
| 761 | + auto wd = timeout != -1 | ||
| 762 | + ? std::make_optional<Watchdog>(isolate, timeout, &timed_out) | ||
| 763 | + : std::nullopt; | ||
| 764 | + auto swd = break_on_sigint ? std::make_optional<SigintWatchdog>( | ||
| 765 | + isolate, &received_signal) | ||
| 766 | + : std::nullopt; | ||
| 767 | + | ||
| 768 | + result = module->Evaluate(context); | ||
| 762 | 769 | ||
| 763 | 770 | Local<Value> res; | |
| 764 | 771 | if (result.ToLocal(&res) && microtask_queue) { | |
@@ -792,29 +799,15 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) { | |||
| 792 | 799 | Local<Context> outer_context = isolate->GetCurrentContext(); | |
| 793 | 800 | Local<Promise::Resolver> resolver; | |
| 794 | 801 | if (!Promise::Resolver::New(outer_context).ToLocal(&resolver)) { | |
| 795 | - return MaybeLocal<Value>(); | ||
| 802 | + result = {}; | ||
| 796 | 803 | } | |
| 797 | 804 | if (resolver->Resolve(outer_context, res).IsNothing()) { | |
| 798 | - return MaybeLocal<Value>(); | ||
| 805 | + result = {}; | ||
| 799 | 806 | } | |
| 800 | 807 | result = resolver->GetPromise(); | |
| 801 | 808 | ||
| 802 | 809 | microtask_queue->PerformCheckpoint(isolate); | |
| 803 | 810 | } | |
| 804 | - return result; | ||
| 805 | - }; | ||
| 806 | - if (break_on_sigint && timeout != -1) { | ||
| 807 | - Watchdog wd(isolate, timeout, &timed_out); | ||
| 808 | - SigintWatchdog swd(isolate, &received_signal); | ||
| 809 | - result = run(); | ||
| 810 | - } else if (break_on_sigint) { | ||
| 811 | - SigintWatchdog swd(isolate, &received_signal); | ||
| 812 | - result = run(); | ||
| 813 | - } else if (timeout != -1) { | ||
| 814 | - Watchdog wd(isolate, timeout, &timed_out); | ||
| 815 | - result = run(); | ||
| 816 | - } else { | ||
| 817 | - result = run(); | ||
| 818 | 811 | } | |
| 819 | 812 | ||
| 820 | 813 | if (result.IsEmpty()) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1296,24 +1296,17 @@ bool ContextifyScript::EvalMachine(Local<Context> context, | |||
| 1296 | 1296 | MaybeLocal<Value> result; | |
| 1297 | 1297 | bool timed_out = false; | |
| 1298 | 1298 | bool received_signal = false; | |
| 1299 | - auto run = [&]() { | ||
| 1300 | - MaybeLocal<Value> result = script->Run(context); | ||
| 1299 | + { | ||
| 1300 | + auto wd = timeout != -1 ? std::make_optional<Watchdog>( | ||
| 1301 | + env->isolate(), timeout, &timed_out) | ||
| 1302 | + : std::nullopt; | ||
| 1303 | + auto swd = break_on_sigint ? std::make_optional<SigintWatchdog>( | ||
| 1304 | + env->isolate(), &received_signal) | ||
| 1305 | + : std::nullopt; | ||
| 1306 | + | ||
| 1307 | + result = script->Run(context); | ||
| 1301 | 1308 | if (!result.IsEmpty() && mtask_queue != nullptr) | |
| 1302 | 1309 | mtask_queue->PerformCheckpoint(env->isolate()); | |
| 1303 | - return result; | ||
| 1304 | - }; | ||
| 1305 | - if (break_on_sigint && timeout != -1) { | ||
| 1306 | - Watchdog wd(env->isolate(), timeout, &timed_out); | ||
| 1307 | - SigintWatchdog swd(env->isolate(), &received_signal); | ||
| 1308 | - result = run(); | ||
| 1309 | - } else if (break_on_sigint) { | ||
| 1310 | - SigintWatchdog swd(env->isolate(), &received_signal); | ||
| 1311 | - result = run(); | ||
| 1312 | - } else if (timeout != -1) { | ||
| 1313 | - Watchdog wd(env->isolate(), timeout, &timed_out); | ||
| 1314 | - result = run(); | ||
| 1315 | - } else { | ||
| 1316 | - result = run(); | ||
| 1317 | 1310 | } | |
| 1318 | 1311 | ||
| 1319 | 1312 | // Convert the termination exception into a regular exception. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,6 +51,11 @@ class Watchdog { | |||
| 51 | 51 | v8::Isolate* isolate() { return isolate_; } | |
| 52 | 52 | ||
| 53 | 53 | private: | |
| 54 | + Watchdog(const Watchdog&) = delete; | ||
| 55 | + Watchdog& operator=(const Watchdog&) = delete; | ||
| 56 | + Watchdog(Watchdog&&) = delete; | ||
| 57 | + Watchdog& operator=(Watchdog&&) = delete; | ||
| 58 | + | ||
| 54 | 59 | static void Run(void* arg); | |
| 55 | 60 | static void Timer(uv_timer_t* timer); | |
| 56 | 61 | ||
@@ -77,6 +82,11 @@ class SigintWatchdog : public SigintWatchdogBase { | |||
| 77 | 82 | SignalPropagation HandleSigint() override; | |
| 78 | 83 | ||
| 79 | 84 | private: | |
| 85 | + SigintWatchdog(const SigintWatchdog&) = delete; | ||
| 86 | + SigintWatchdog& operator=(const SigintWatchdog&) = delete; | ||
| 87 | + SigintWatchdog(SigintWatchdog&&) = delete; | ||
| 88 | + SigintWatchdog& operator=(SigintWatchdog&&) = delete; | ||
| 89 | + | ||
| 80 | 90 | v8::Isolate* isolate_; | |
| 81 | 91 | bool* received_signal_; | |
| 82 | 92 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments