From a9b213c0a80e61e1ce136a1a5b7cbb50b338f5b3 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Wed, 6 Dec 2017 16:52:37 -0500 Subject: [PATCH] fixup: address some of mcollina's feedback --- lib/vm.js | 4 ++-- test/parallel/test-event-emitter-listeners.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/vm.js b/lib/vm.js index e9559d62602898..82f140923a8bce 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.listenerCount('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.listenerCount('SIGINT')) { + if (options && options.breakOnSigint && process.listenerCount('SIGINT') > 0) { return sigintHandlersWrap(realRunInContext, this, [contextifiedSandbox, options]); } else { diff --git a/test/parallel/test-event-emitter-listeners.js b/test/parallel/test-event-emitter-listeners.js index 08a2fa91bf2ab5..9d2892d2e891ae 100644 --- a/test/parallel/test-event-emitter-listeners.js +++ b/test/parallel/test-event-emitter-listeners.js @@ -86,10 +86,18 @@ function listener2() {} { const ee = new events.EventEmitter(); ee.on('foo', listener); + const wrappedListener = ee.rawListeners('foo'); + assert.strictEqual(wrappedListener.length, 1); + assert.strictEqual(wrappedListener[0], listener); + assert.notStrictEqual(wrappedListener, ee.rawListeners('foo')); ee.once('foo', listener); const wrappedListeners = ee.rawListeners('foo'); assert.strictEqual(wrappedListeners.length, 2); assert.strictEqual(wrappedListeners[0], listener); assert.notStrictEqual(wrappedListeners[1], listener); assert.strictEqual(wrappedListeners[1].listener, listener); + assert.notStrictEqual(wrappedListeners, ee.rawListeners('foo')); + ee.emit('foo'); + assert.strictEqual(wrappedListeners.length, 2); + assert.strictEqual(wrappedListeners[1].listener, listener); }