From 91e96ab0796e18a05f0a00b6f1ebd348be46cad8 Mon Sep 17 00:00:00 2001 From: Victor Felder Date: Mon, 2 Jan 2017 22:28:04 +0100 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Evan Lucas Reviewed-By: Jeremiah Senkpiel Reviewed-By: James M Snell Reviewed-By: Michael Dawson --- lib/events.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/events.js b/lib/events.js index 209700e65ad596..000fa98d5a88c5 100644 --- a/lib/events.js +++ b/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');