diff --git a/lib/events.js b/lib/events.js index 1609d66192e333..c49df9fab84f46 100644 --- a/lib/events.js +++ b/lib/events.js @@ -306,10 +306,25 @@ EventEmitter.prototype.prependListener = }; function onceWrapper() { - this.target.removeListener(this.type, this.wrapFn); if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); this.fired = true; - this.listener.apply(this.target, arguments); + switch (arguments.length) { + case 0: + return this.listener.call(this.target); + case 1: + return this.listener.call(this.target, arguments[0]); + case 2: + return this.listener.call(this.target, arguments[0], arguments[1]); + case 3: + return this.listener.call(this.target, arguments[0], arguments[1], + arguments[2]); + default: + const args = new Array(arguments.length); + for (var i = 0; i < args.length; ++i) + args[i] = arguments[i]; + this.listener.apply(this.target, args); + } } }