Skip to content

Commit

Permalink
events: onceWrapper returns target value
Browse files Browse the repository at this point in the history
PR-URL: #25818
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
himself65 authored and BridgeAR committed Mar 5, 2019
1 parent 905988a commit acc506c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,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);
}
}

Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-event-emitter-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

0 comments on commit acc506c

Please sign in to comment.