Skip to content

Commit a666238

Browse files
mscdexjasnell
authored andcommitted
events: fix potential permanent deopt
PR-URL: #13384 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 48cad9c commit a666238

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/events.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,25 @@ EventEmitter.prototype.prependListener =
306306
};
307307

308308
function onceWrapper() {
309-
this.target.removeListener(this.type, this.wrapFn);
310309
if (!this.fired) {
310+
this.target.removeListener(this.type, this.wrapFn);
311311
this.fired = true;
312-
this.listener.apply(this.target, arguments);
312+
switch (arguments.length) {
313+
case 0:
314+
return this.listener.call(this.target);
315+
case 1:
316+
return this.listener.call(this.target, arguments[0]);
317+
case 2:
318+
return this.listener.call(this.target, arguments[0], arguments[1]);
319+
case 3:
320+
return this.listener.call(this.target, arguments[0], arguments[1],
321+
arguments[2]);
322+
default:
323+
const args = new Array(arguments.length);
324+
for (var i = 0; i < args.length; ++i)
325+
args[i] = arguments[i];
326+
this.listener.apply(this.target, args);
327+
}
313328
}
314329
}
315330

0 commit comments

Comments
 (0)