Skip to content

Commit a447c48

Browse files
committed
[BUGFIX release] Fix inlining of superWrapper.
This fixes the inlining of superWrapper. The bug that copying the arguments was addressing has been fixed for long enough that more users are affected by fix than the fix benefits. This also fixes a deopt in the megamorphic load of toString, since we store metadata on functions we have many shapes of functions.
1 parent 66e9821 commit a447c48

File tree

2 files changed

+8
-48
lines changed

2 files changed

+8
-48
lines changed

packages/ember-metal/lib/events.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
@submodule ember-metal
88
*/
99
import { assert } from 'ember-metal/debug';
10-
import {
11-
apply,
12-
applyStr
13-
} from 'ember-metal/utils';
10+
import { applyStr } from 'ember-metal/utils';
1411
import { meta as metaFor, peekMeta } from 'ember-metal/meta';
1512
import { deprecate } from 'ember-metal/debug';
1613

@@ -237,7 +234,7 @@ export function sendEvent(obj, eventName, params, actions) {
237234
}
238235
} else {
239236
if (params) {
240-
apply(target, method, params);
237+
method.apply(target, params);
241238
} else {
242239
method.call(target);
243240
}

packages/ember-metal/lib/utils.js

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,16 @@ export function guidFor(obj) {
245245
}
246246

247247
const HAS_SUPER_PATTERN = /\.(_super|call\(this|apply\(this)/;
248+
const fnToString = Function.prototype.toString;
248249

249250
export const checkHasSuper = (function () {
250-
let sourceAvailable = (function() {
251+
let sourceAvailable = fnToString.call(function() {
251252
return this;
252-
}).toString().indexOf('return this') > -1;
253+
}).indexOf('return this') > -1;
253254

254255
if (sourceAvailable) {
255256
return function checkHasSuper(func) {
256-
return HAS_SUPER_PATTERN.test(func.toString());
257+
return HAS_SUPER_PATTERN.test(fnToString.call(func));
257258
};
258259
}
259260

@@ -297,26 +298,9 @@ export function wrap(func, superFunc) {
297298

298299
function _wrap(func, superFunc) {
299300
function superWrapper() {
300-
let orig = this._super;
301-
let ret;
301+
var orig = this._super;
302302
this._super = superFunc;
303-
switch (arguments.length) {
304-
case 0: ret = func.call(this); break;
305-
case 1: ret = func.call(this, arguments[0]); break;
306-
case 2: ret = func.call(this, arguments[0], arguments[1]); break;
307-
case 3: ret = func.call(this, arguments[0], arguments[1], arguments[2]); break;
308-
case 4: ret = func.call(this, arguments[0], arguments[1], arguments[2], arguments[3]); break;
309-
case 5: ret = func.call(this, arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]); break;
310-
default:
311-
// v8 bug potentially incorrectly deopts this function: https://code.google.com/p/v8/issues/detail?id=3709
312-
// we may want to keep this around till this ages out on mobile
313-
let args = new Array(arguments.length);
314-
for (var x = 0; x < arguments.length; x++) {
315-
args[x] = arguments[x];
316-
}
317-
ret = func.apply(this, args);
318-
break;
319-
}
303+
var ret = func.apply(this, arguments);
320304
this._super = orig;
321305
return ret;
322306
}
@@ -464,27 +448,6 @@ export function inspect(obj) {
464448
return '{' + ret.join(', ') + '}';
465449
}
466450

467-
// The following functions are intentionally minified to keep the functions
468-
// below Chrome's function body size inlining limit of 600 chars.
469-
/**
470-
@param {Object} t target
471-
@param {Function} m method
472-
@param {Array} a args
473-
@private
474-
*/
475-
export function apply(t, m, a) {
476-
var l = a && a.length;
477-
if (!a || !l) { return m.call(t); }
478-
switch (l) {
479-
case 1: return m.call(t, a[0]);
480-
case 2: return m.call(t, a[0], a[1]);
481-
case 3: return m.call(t, a[0], a[1], a[2]);
482-
case 4: return m.call(t, a[0], a[1], a[2], a[3]);
483-
case 5: return m.call(t, a[0], a[1], a[2], a[3], a[4]);
484-
default: return m.apply(t, a);
485-
}
486-
}
487-
488451
/**
489452
@param {Object} t target
490453
@param {String} m method

0 commit comments

Comments
 (0)