diff --git a/events.js b/events.js index 094dd8c..e887e5e 100644 --- a/events.js +++ b/events.js @@ -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); } } diff --git a/tests/listeners.js b/tests/listeners.js index 365f8a0..1909d2d 100644 --- a/tests/listeners.js +++ b/tests/listeners.js @@ -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); @@ -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); +}