From decab712ba14b8ec577025a57b8ab460fd3b8ec5 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Sat, 25 Nov 2017 13:26:28 -0500 Subject: events: remove reaches into _events internals Refactor lib & src code to eliminate all deep reaches into the internal _events dictionary object, instead use available APIs and add an extra method to EventEmitter: rawListeners. PR-URL: https://github.com/nodejs/node/pull/17440 Reviewed-By: Anna Henningsen Reviewed-By: Timothy Gu Reviewed-By: Ruben Bridgewater Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- lib/vm.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'lib/vm.js') diff --git a/lib/vm.js b/lib/vm.js index 2f110b2db2..82f140923a 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -56,7 +56,7 @@ const realRunInThisContext = Script.prototype.runInThisContext; const realRunInContext = Script.prototype.runInContext; Script.prototype.runInThisContext = function(options) { - if (options && options.breakOnSigint && process._events.SIGINT) { + if (options && options.breakOnSigint && process.listenerCount('SIGINT') > 0) { return sigintHandlersWrap(realRunInThisContext, this, [options]); } else { return realRunInThisContext.call(this, options); @@ -64,7 +64,7 @@ Script.prototype.runInThisContext = function(options) { }; Script.prototype.runInContext = function(contextifiedSandbox, options) { - if (options && options.breakOnSigint && process._events.SIGINT) { + if (options && options.breakOnSigint && process.listenerCount('SIGINT') > 0) { return sigintHandlersWrap(realRunInContext, this, [contextifiedSandbox, options]); } else { @@ -95,14 +95,7 @@ function createScript(code, options) { // Remove all SIGINT listeners and re-attach them after the wrapped function // has executed, so that caught SIGINT are handled by the listeners again. function sigintHandlersWrap(fn, thisArg, argsArray) { - // Using the internal list here to make sure `.once()` wrappers are used, - // not the original ones. - let sigintListeners = process._events.SIGINT; - - if (Array.isArray(sigintListeners)) - sigintListeners = sigintListeners.slice(); - else - sigintListeners = [sigintListeners]; + const sigintListeners = process.rawListeners('SIGINT'); process.removeAllListeners('SIGINT'); -- cgit v1.2.3