Skip to content

Commit

Permalink
Merge pull request sindresorhus#73 from STRML/noDeopt
Browse files Browse the repository at this point in the history
Prevent v8 deopt when using [].slice.call(arguments)
  • Loading branch information
vendethiel authored Apr 9, 2019
2 parents 092199b + d29511f commit 6ef9d2c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,14 @@ Emitter.prototype.removeEventListener = function(event, fn){

Emitter.prototype.emit = function(event){
this._callbacks = this._callbacks || {};
var args = [].slice.call(arguments, 1)

var args = new Array(arguments.length - 1)
, callbacks = this._callbacks['$' + event];

for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}

if (callbacks) {
callbacks = callbacks.slice(0);
for (var i = 0, len = callbacks.length; i < len; ++i) {
Expand Down

0 comments on commit 6ef9d2c

Please sign in to comment.