Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ This file documents various terms and definitions used throughout the Node.js co
* **VM**: [The Node.js VM module][] - Provides a way of executing code within V8 Virtual Machine contexts.
* **W3C**: [World Wide Web Consortium][] - An international community that develops standards and guidelines for
various aspects of the web ecosystem.
* **WASI**: [Web Assembly System Interface][] - Interface for WebAssembly.
* **WASM**: Web Assembly - Binary instruction format for a stack-based virtual machine.
* **WASI**: [WebAssembly System Interface][] - Interface for WebAssembly.
* **WASM**: WebAssembly - Binary instruction format for a stack-based virtual machine.
* **WDYT**: What Do You Think?
* **WG**: Working Group - Autonomous teams in the project with specific focus areas.
* **WHATWG**: [Web Hypertext Application Technology Working Group][] - Community developing web standards.
Expand Down Expand Up @@ -148,8 +148,8 @@ This file documents various terms and definitions used throughout the Node.js co
[Unicode Transformation Format - 8-bit]: https://en.wikipedia.org/wiki/UTF-8
[Uniform Resource Locator]: https://en.wikipedia.org/wiki/URL
[User Interface]: https://en.wikipedia.org/wiki/User_interface
[Web Assembly System Interface]: https://github.com/WebAssembly/WASI
[Web Hypertext Application Technology Working Group]: https://en.wikipedia.org/wiki/WHATWG
[WebAssembly System Interface]: https://github.com/WebAssembly/WASI
[World Wide Web Consortium]: https://www.w3.org/
[specification document for **ECMAScript**]: https://ecma-international.org/publications-and-standards/standards/ecma-262/
[web-platform-tests]: https://github.com/web-platform-tests/wpt
29 changes: 11 additions & 18 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,15 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
bool timed_out = false;
bool received_signal = false;
MaybeLocal<Value> result;
auto run = [&]() {
MaybeLocal<Value> result = module->Evaluate(context);
{
auto wd = timeout != -1
? std::make_optional<Watchdog>(isolate, timeout, &timed_out)
: std::nullopt;
auto swd = break_on_sigint ? std::make_optional<SigintWatchdog>(
isolate, &received_signal)
: std::nullopt;

result = module->Evaluate(context);

Local<Value> res;
if (result.ToLocal(&res) && microtask_queue) {
Expand Down Expand Up @@ -792,29 +799,15 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
Local<Context> outer_context = isolate->GetCurrentContext();
Local<Promise::Resolver> resolver;
if (!Promise::Resolver::New(outer_context).ToLocal(&resolver)) {
return MaybeLocal<Value>();
result = {};
}
if (resolver->Resolve(outer_context, res).IsNothing()) {
return MaybeLocal<Value>();
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()) {
Expand Down
25 changes: 9 additions & 16 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1296,24 +1296,17 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
MaybeLocal<Value> result;
bool timed_out = false;
bool received_signal = false;
auto run = [&]() {
MaybeLocal<Value> result = script->Run(context);
{
auto wd = timeout != -1 ? std::make_optional<Watchdog>(
env->isolate(), timeout, &timed_out)
: std::nullopt;
auto swd = break_on_sigint ? std::make_optional<SigintWatchdog>(
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.
Expand Down
10 changes: 10 additions & 0 deletions src/node_watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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_;
};
Expand Down
Loading