Skip to content

Commit

Permalink
pass through return value in onceWrapper()-ed functions
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Jan 8, 2020
1 parent ade7481 commit 7ad7ba6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion events.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function onceWrapper() {
if (!this.fired) {
this.target.removeListener(this.type, this.wrapFn);
this.fired = true;
ReflectApply(this.listener, this.target, args);
return ReflectApply(this.listener, this.target, args);
}
}

Expand Down
23 changes: 21 additions & 2 deletions tests/listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ var assert = require('assert');
var events = require('../');
var util = require('util');

var listener = function listener() {};
var listener2 = function listener2() {};
function listener() {}
function listener2() {}
function listener3() {
return 0;
}
function listener4() {
return 1;
}

function TestStream() {}
util.inherits(TestStream, events.EventEmitter);

Expand Down Expand Up @@ -147,3 +154,15 @@ util.inherits(TestStream, events.EventEmitter);
assert.strictEqual(wrappedListeners.length, 2);
assert.strictEqual(wrappedListeners[1].listener, listener);
}

{
var ee = new events.EventEmitter();
ee.once('foo', listener3);
ee.on('foo', listener4);
var rawListeners = ee.rawListeners('foo');
assert.strictEqual(rawListeners.length, 2);
assert.strictEqual(rawListeners[0](), 0);
var rawListener = ee.rawListeners('foo');
assert.strictEqual(rawListener.length, 1);
assert.strictEqual(rawListener[0](), 1);
}

0 comments on commit 7ad7ba6

Please sign in to comment.