diff --git a/lib/events.js b/lib/events.js index 3fce38f881b9fb..4ee96024895f45 100644 --- a/lib/events.js +++ b/lib/events.js @@ -274,7 +274,7 @@ function onceWrapper(...args) { if (!this.fired) { this.target.removeListener(this.type, this.wrapFn); this.fired = true; - Reflect.apply(this.listener, this.target, args); + return Reflect.apply(this.listener, this.target, args); } } diff --git a/test/parallel/test-event-emitter-listeners.js b/test/parallel/test-event-emitter-listeners.js index 9d2892d2e891ae..52a108ad0e29b6 100644 --- a/test/parallel/test-event-emitter-listeners.js +++ b/test/parallel/test-event-emitter-listeners.js @@ -27,6 +27,12 @@ const events = require('events'); function listener() {} function listener2() {} +function listener3() { + return 0; +} +function listener4() { + return 1; +} { const ee = new events.EventEmitter(); @@ -101,3 +107,15 @@ function listener2() {} assert.strictEqual(wrappedListeners.length, 2); assert.strictEqual(wrappedListeners[1].listener, listener); } + +{ + const ee = new events.EventEmitter(); + ee.once('foo', listener3); + ee.on('foo', listener4); + const rawListeners = ee.rawListeners('foo'); + assert.strictEqual(rawListeners.length, 2); + assert.strictEqual(rawListeners[0](), 0); + const rawListener = ee.rawListeners('foo'); + assert.strictEqual(rawListener.length, 1); + assert.strictEqual(rawListener[0](), 1); +}