Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] Fix inlining of superWrapper. #13655

Merged
merged 1 commit into from
Jun 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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