Skip to content

Commit 19e3e02

Browse files
committed
src: move SIGINT watchdog utils to the contextify binding
These are used when evaluating scripts so it makes more sense to put them in the contextify binding whose other methods are going to be used together. PR-URL: #27290 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7c816b7 commit 19e3e02

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

lib/repl.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ const {
8787
propertyFilter: {
8888
ALL_PROPERTIES,
8989
SKIP_SYMBOLS
90-
},
90+
}
91+
} = internalBinding('util');
92+
const {
9193
startSigintWatchdog,
9294
stopSigintWatchdog
93-
} = internalBinding('util');
95+
} = internalBinding('contextify');
96+
9497
const history = require('internal/repl/history');
9598

9699
// Lazy-loaded.

src/node_contextify.cc

+20
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,20 @@ void ContextifyContext::CompileFunction(
11411141
args.GetReturnValue().Set(fn);
11421142
}
11431143

1144+
static void StartSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
1145+
int ret = SigintWatchdogHelper::GetInstance()->Start();
1146+
args.GetReturnValue().Set(ret == 0);
1147+
}
1148+
1149+
static void StopSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
1150+
bool had_pending_signals = SigintWatchdogHelper::GetInstance()->Stop();
1151+
args.GetReturnValue().Set(had_pending_signals);
1152+
}
1153+
1154+
static void WatchdogHasPendingSigint(const FunctionCallbackInfo<Value>& args) {
1155+
bool ret = SigintWatchdogHelper::GetInstance()->HasPendingSignal();
1156+
args.GetReturnValue().Set(ret);
1157+
}
11441158

11451159
void Initialize(Local<Object> target,
11461160
Local<Value> unused,
@@ -1149,6 +1163,12 @@ void Initialize(Local<Object> target,
11491163
Environment* env = Environment::GetCurrent(context);
11501164
ContextifyContext::Init(env, target);
11511165
ContextifyScript::Init(env, target);
1166+
1167+
env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog);
1168+
env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog);
1169+
// Used in tests.
1170+
env->SetMethodNoSideEffect(
1171+
target, "watchdogHasPendingSigint", WatchdogHasPendingSigint);
11521172
}
11531173

11541174
} // namespace contextify

src/node_util.cc

-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "node_errors.h"
2-
#include "node_watchdog.h"
32
#include "util.h"
43
#include "base_object-inl.h"
54

@@ -157,24 +156,6 @@ static void SetHiddenValue(const FunctionCallbackInfo<Value>& args) {
157156
args.GetReturnValue().Set(maybe_value.FromJust());
158157
}
159158

160-
161-
void StartSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
162-
int ret = SigintWatchdogHelper::GetInstance()->Start();
163-
args.GetReturnValue().Set(ret == 0);
164-
}
165-
166-
167-
void StopSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
168-
bool had_pending_signals = SigintWatchdogHelper::GetInstance()->Stop();
169-
args.GetReturnValue().Set(had_pending_signals);
170-
}
171-
172-
173-
void WatchdogHasPendingSigint(const FunctionCallbackInfo<Value>& args) {
174-
bool ret = SigintWatchdogHelper::GetInstance()->HasPendingSignal();
175-
args.GetReturnValue().Set(ret);
176-
}
177-
178159
void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) {
179160
CHECK(args[0]->IsArrayBufferView());
180161
args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer());
@@ -281,11 +262,6 @@ void Initialize(Local<Object> target,
281262
env->SetMethodNoSideEffect(target, "getOwnNonIndexProperties",
282263
GetOwnNonIndexProperties);
283264

284-
env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog);
285-
env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog);
286-
env->SetMethodNoSideEffect(target, "watchdogHasPendingSigint",
287-
WatchdogHasPendingSigint);
288-
289265
env->SetMethod(target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer);
290266
Local<Object> constants = Object::New(env->isolate());
291267
NODE_DEFINE_CONSTANT(constants, ALL_PROPERTIES);

test/parallel/test-util-sigint-watchdog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (common.isWindows) {
88

99
const assert = require('assert');
1010
const { internalBinding } = require('internal/test/binding');
11-
const binding = internalBinding('util');
11+
const binding = internalBinding('contextify');
1212

1313
[(next) => {
1414
// Test with no signal observed.

0 commit comments

Comments
 (0)