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 <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
  • Loading branch information
mscdex authored and jasnell committed Jun 7, 2017
1 parent 48cad9c commit a666238
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 a666238

Please sign in to comment.