Skip to content

Commit

Permalink
events: fix potential permanent deopt
Browse files Browse the repository at this point in the history
PR-URL: #13384
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
mscdex committed Jun 5, 2017
1 parent 8cc8358 commit e374e44
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit e374e44

Please sign in to comment.