events: fix potential permanent deopt

PR-URL: https://github.com/nodejs/node/pull/13384
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
Brian White 2017-06-02 02:09:19 -04:00
parent 8cc8358ef7
commit e374e44a8a
No known key found for this signature in database
GPG Key ID: 606D7358F94DA209

View File

@ -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);
}
}
}