Skip to content

Commit

Permalink
Merge pull request #13655 from emberjs/fix-super-inline
Browse files Browse the repository at this point in the history
[BUGFIX release] Fix inlining of superWrapper.
  • Loading branch information
rwjblue authored Jun 12, 2016
2 parents 66e9821 + a447c48 commit 6467153
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 48 deletions.
7 changes: 2 additions & 5 deletions packages/ember-metal/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
@submodule ember-metal
*/
import { assert } from 'ember-metal/debug';
import {
apply,
applyStr
} from 'ember-metal/utils';
import { applyStr } from 'ember-metal/utils';
import { meta as metaFor, peekMeta } from 'ember-metal/meta';
import { deprecate } from 'ember-metal/debug';

Expand Down Expand Up @@ -237,7 +234,7 @@ export function sendEvent(obj, eventName, params, actions) {
}
} else {
if (params) {
apply(target, method, params);
method.apply(target, params);
} else {
method.call(target);
}
Expand Down
49 changes: 6 additions & 43 deletions packages/ember-metal/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,16 @@ export function guidFor(obj) {
}

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

export const checkHasSuper = (function () {
let sourceAvailable = (function() {
let sourceAvailable = fnToString.call(function() {
return this;
}).toString().indexOf('return this') > -1;
}).indexOf('return this') > -1;

if (sourceAvailable) {
return function checkHasSuper(func) {
return HAS_SUPER_PATTERN.test(func.toString());
return HAS_SUPER_PATTERN.test(fnToString.call(func));
};
}

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

function _wrap(func, superFunc) {
function superWrapper() {
let orig = this._super;
let ret;
var orig = this._super;
this._super = superFunc;
switch (arguments.length) {
case 0: ret = func.call(this); break;
case 1: ret = func.call(this, arguments[0]); break;
case 2: ret = func.call(this, arguments[0], arguments[1]); break;
case 3: ret = func.call(this, arguments[0], arguments[1], arguments[2]); break;
case 4: ret = func.call(this, arguments[0], arguments[1], arguments[2], arguments[3]); break;
case 5: ret = func.call(this, arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]); break;
default:
// v8 bug potentially incorrectly deopts this function: https://code.google.com/p/v8/issues/detail?id=3709
// we may want to keep this around till this ages out on mobile
let args = new Array(arguments.length);
for (var x = 0; x < arguments.length; x++) {
args[x] = arguments[x];
}
ret = func.apply(this, args);
break;
}
var ret = func.apply(this, arguments);
this._super = orig;
return ret;
}
Expand Down Expand Up @@ -464,27 +448,6 @@ export function inspect(obj) {
return '{' + ret.join(', ') + '}';
}

// The following functions are intentionally minified to keep the functions
// below Chrome's function body size inlining limit of 600 chars.
/**
@param {Object} t target
@param {Function} m method
@param {Array} a args
@private
*/
export function apply(t, m, a) {
var l = a && a.length;
if (!a || !l) { return m.call(t); }
switch (l) {
case 1: return m.call(t, a[0]);
case 2: return m.call(t, a[0], a[1]);
case 3: return m.call(t, a[0], a[1], a[2]);
case 4: return m.call(t, a[0], a[1], a[2], a[3]);
case 5: return m.call(t, a[0], a[1], a[2], a[3], a[4]);
default: return m.apply(t, a);
}
}

/**
@param {Object} t target
@param {String} m method
Expand Down

0 comments on commit 6467153

Please sign in to comment.