From 0ae2291dd7dd95b0d44055336ec6911d12f756e6 Mon Sep 17 00:00:00 2001 From: Andrey Vasenin Date: Mon, 29 May 2017 19:37:47 +0200 Subject: [PATCH] Fix V8 warning 'Not Optimized: Bad value context for arguments value' --- src/observer.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/observer.js b/src/observer.js index b19d6ab..8be4761 100644 --- a/src/observer.js +++ b/src/observer.js @@ -70,14 +70,25 @@ Observer.prototype = { * [Subscription]{@link Subscription} object. * * @param {string} name - Event name. + * @param {...Object} args - Event arguments. * * @return {void} */ - fire: function (name) { - var col = this.handlers[name] || []; - var args = Array.prototype.slice.call(arguments); - args.shift(); - col.forEach(function (fn) { + fire: function () { + var name; + var fns; + var i; + var len = arguments.length; + // Copy arguments to solve 'Not optimized: Bad value context for arguments value' + // See https://github.com/GoogleChrome/devtools-docs/issues/53#issuecomment-51941358 + var args = new Array(len); + for (i = 0; i < len; i += 1) { + args[i] = arguments[i]; + } + name = args.shift(); + + fns = this.handlers[name] || []; + fns.forEach(function (fn) { try { fn.apply(null, args); } catch (e) {