★ wanayoo — archive 1999 https://github.com/nodejs/node/commit/19e3e02a2dNouvelle recherche | Portail wanayoo
Skip to content
Permalink
Browse files
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 <daniel.bevenius@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung committed Apr 22, 2019
1 parent 7c816b7 commit 19e3e02a2db996a3df36e00df6c6b57cec516c9e
Showing with 26 additions and 27 deletions.
  1. +5 −2 lib/repl.js
  2. +20 −0 src/node_contextify.cc
  3. +0 −24 src/node_util.cc
  4. +1 −1 test/parallel/test-util-sigint-watchdog.js
@@ -87,10 +87,13 @@ const {
propertyFilter: {
ALL_PROPERTIES,
SKIP_SYMBOLS
},
}
} = internalBinding('util');
const {
startSigintWatchdog,
stopSigintWatchdog
} = internalBinding('util');
} = internalBinding('contextify');

const history = require('internal/repl/history');

// Lazy-loaded.
@@ -1141,6 +1141,20 @@ void ContextifyContext::CompileFunction(
args.GetReturnValue().Set(fn);
}

static void StartSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
int ret = SigintWatchdogHelper::GetInstance()->Start();
args.GetReturnValue().Set(ret == 0);
}

static void StopSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
bool had_pending_signals = SigintWatchdogHelper::GetInstance()->Stop();
args.GetReturnValue().Set(had_pending_signals);
}

static void WatchdogHasPendingSigint(const FunctionCallbackInfo<Value>& args) {
bool ret = SigintWatchdogHelper::GetInstance()->HasPendingSignal();
args.GetReturnValue().Set(ret);
}

void Initialize(Local<Object> target,
Local<Value> unused,
@@ -1149,6 +1163,12 @@ void Initialize(Local<Object> target,
Environment* env = Environment::GetCurrent(context);
ContextifyContext::Init(env, target);
ContextifyScript::Init(env, target);

env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog);
env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog);
// Used in tests.
env->SetMethodNoSideEffect(
target, "watchdogHasPendingSigint", WatchdogHasPendingSigint);
}

} // namespace contextify
@@ -1,5 +1,4 @@
#include "node_errors.h"
#include "node_watchdog.h"
#include "util.h"
#include "base_object-inl.h"

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


void StartSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
int ret = SigintWatchdogHelper::GetInstance()->Start();
args.GetReturnValue().Set(ret == 0);
}


void StopSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
bool had_pending_signals = SigintWatchdogHelper::GetInstance()->Stop();
args.GetReturnValue().Set(had_pending_signals);
}


void WatchdogHasPendingSigint(const FunctionCallbackInfo<Value>& args) {
bool ret = SigintWatchdogHelper::GetInstance()->HasPendingSignal();
args.GetReturnValue().Set(ret);
}

void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsArrayBufferView());
args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer());
@@ -281,11 +262,6 @@ void Initialize(Local<Object> target,
env->SetMethodNoSideEffect(target, "getOwnNonIndexProperties",
GetOwnNonIndexProperties);

env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog);
env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog);
env->SetMethodNoSideEffect(target, "watchdogHasPendingSigint",
WatchdogHasPendingSigint);

env->SetMethod(target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer);
Local<Object> constants = Object::New(env->isolate());
NODE_DEFINE_CONSTANT(constants, ALL_PROPERTIES);
@@ -8,7 +8,7 @@ if (common.isWindows) {

const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
const binding = internalBinding('util');
const binding = internalBinding('contextify');

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

0 comments on commit 19e3e02

Please sign in to comment.