Browse Source

events: avoid emit() eager deopt

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: #10323 and this specific case might
become a more serious performance issue in upcoming V8 releases.

PR-URL: https://github.com/nodejs/node/pull/10568
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
v6
Victor Felder 8 years ago
committed by James M Snell
parent
commit
e52fee50a0
  1. 3
      lib/events.js

3
lib/events.js

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

Loading…
Cancel
Save