Skip to content

Commit

Permalink
events: avoid emit() eager deopt
Browse files Browse the repository at this point in the history
This commit makes sure EventEmitter.emit() doesn't get deoptimized by
V8. The deopt happens when accessing out of bound indexes of the
`arguments` object.

This issue has been raised here: nodejs#10323 and this specific case might
become a more serious performance issue in upcoming V8 releases.
  • Loading branch information
vhf committed Jan 2, 2017
1 parent b465cd0 commit 91cf369
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ EventEmitter.prototype.emit = function emit(type) {

// If there is no 'error' event listener then throw.
if (doError) {
er = arguments[1];
if (arguments.length > 1)
er = arguments[1];
if (domain) {
if (!er)
er = new Error('Uncaught, unspecified "error" event');
Expand Down

0 comments on commit 91cf369

Please sign in to comment.