diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2017-11-25 13:26:28 -0500 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2017-12-14 08:43:00 -0500 |
commit | decab712ba14b8ec577025a57b8ab460fd3b8ec5 (patch) | |
tree | 0899c36bdbeed5fc9cea552e109f9081548f9c94 /lib/vm.js | |
parent | e24ad97832979b945ccb2af6e2cf67caf7524cb1 (diff) | |
download | android-node-v8-decab712ba14b8ec577025a57b8ab460fd3b8ec5.tar.gz android-node-v8-decab712ba14b8ec577025a57b8ab460fd3b8ec5.tar.bz2 android-node-v8-decab712ba14b8ec577025a57b8ab460fd3b8ec5.zip |
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 <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/vm.js')
-rw-r--r-- | lib/vm.js | 13 |
1 files changed, 3 insertions, 10 deletions
@@ -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'); |