Skip to content

Commit

Permalink
Merge pull request #12062 from emberjs/remove-next-super
Browse files Browse the repository at this point in the history
Remove this.__nextSuper
  • Loading branch information
rwjblue committed Aug 14, 2015
2 parents ec91278 + 5cecffa commit 6336d21
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 93 deletions.
58 changes: 4 additions & 54 deletions packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,6 @@ import { isStream } from 'ember-metal/streams/utils';
var REQUIRED;
var a_slice = [].slice;

function superFunction() {
var func = this.__nextSuper;
var ret;

if (func) {
var length = arguments.length;
this.__nextSuper = null;
if (length === 0) {
ret = func.call(this);
} else if (length === 1) {
ret = func.call(this, arguments[0]);
} else if (length === 2) {
ret = func.call(this, arguments[0], arguments[1]);
} else {
ret = func.apply(this, arguments);
}
this.__nextSuper = func;
return ret;
}
}

// ensure we prime superFunction to mitigate
// v8 bug potentially incorrectly deopts this function: https://code.google.com/p/v8/issues/detail?id=3709
var primer = {
__nextSuper(a, b, c, d) { }
};

superFunction.call(primer);
superFunction.call(primer, 1);
superFunction.call(primer, 1, 2);
superFunction.call(primer, 1, 2, 3);

function mixinsMeta(obj) {
return metaFor(obj, true).writableMixins();
}
Expand Down Expand Up @@ -154,10 +122,6 @@ function giveDescriptorSuper(meta, key, property, values, descs, base) {
return property;
}

var sourceAvailable = (function() {
return this;
}).toString().indexOf('return this;') > -1;

function giveMethodSuper(obj, key, method, values, descs) {
var superMethod;

Expand All @@ -176,21 +140,7 @@ function giveMethodSuper(obj, key, method, values, descs) {
return method;
}

var hasSuper;
if (sourceAvailable) {
hasSuper = method.__hasSuper;

if (hasSuper === undefined) {
hasSuper = method.toString().indexOf('_super') > -1;
method.__hasSuper = hasSuper;
}
}

if (sourceAvailable === false || hasSuper) {
return wrap(method, superMethod);
} else {
return method;
}
return wrap(method, superMethod);
}

function applyConcatenatedProperties(obj, key, value, values) {
Expand Down Expand Up @@ -235,7 +185,7 @@ function applyMergedProperties(obj, key, value, values) {
}

if (hasFunction) {
newBase._super = superFunction;
newBase._super = function () {};
}

return newBase;
Expand All @@ -246,7 +196,7 @@ function addNormalizedProperty(base, key, value, meta, descs, values, concats, m
if (value === REQUIRED && descs[key]) { return CONTINUE; }

// Wrap descriptor function to implement
// __nextSuper() if needed
// _super() if needed
if (value._getter) {
value = giveDescriptorSuper(meta, key, value, values, descs, base);
}
Expand Down Expand Up @@ -422,7 +372,7 @@ function applyMixin(obj, mixins, partial) {
var keys = [];
var key, value, desc;

obj._super = superFunction;
obj._super = function () {};

// Go through all mixins and hashes passed in, and:
//
Expand Down
74 changes: 37 additions & 37 deletions packages/ember-metal/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ export var GUID_DESC = {
value: null
};

var undefinedDescriptor = {
configurable: true,
writable: true,
enumerable: false,
value: undefined
};

var nullDescriptor = {
configurable: true,
writable: true,
Expand All @@ -142,12 +135,6 @@ export var GUID_KEY_PROPERTY = {
descriptor: nullDescriptor
};

export var NEXT_SUPER_PROPERTY = {
name: '__nextSuper',
descriptor: undefinedDescriptor
};


/**
Generates a new guid, optionally saving the guid to the object that you
pass in. You will rarely need to use this method. Instead you should
Expand Down Expand Up @@ -267,6 +254,9 @@ export function guidFor(obj) {
}


var sourceAvailable = (function() {
return this;
}).toString().indexOf('return this;') > -1;

/**
Wraps the passed function so that `this._super` will point to the superFunc
Expand All @@ -280,35 +270,45 @@ export function guidFor(obj) {
@param {Function} superFunc The super function.
@return {Function} wrapped function.
*/

export function wrap(func, superFunc) {
function superWrapper() {
var ret;
var sup = this && this.__nextSuper;
var length = arguments.length;

if (this) {
this.__nextSuper = superFunc;
export function wrap(func, _superFunc) {
var superFunc = _superFunc;
var hasSuper;
if (sourceAvailable) {
hasSuper = func.__hasSuper;

if (hasSuper === undefined) {
hasSuper = func.toString().indexOf('_super') > -1;
func.__hasSuper = hasSuper;
}

if (length === 0) {
ret = func.call(this);
} else if (length === 1) {
ret = func.call(this, arguments[0]);
} else if (length === 2) {
ret = func.call(this, arguments[0], arguments[1]);
} else {
var args = new Array(length);
for (var i = 0; i < length; i++) {
args[i] = arguments[i];
}
ret = apply(this, func, args);
if (!hasSuper) {
return func;
}
}

if (this) {
this.__nextSuper = sup;
}
if (superFunc.wrappedFunction === undefined) {
// terminate _super to prevent infinite recursion
superFunc = wrap(superFunc, function () {});
}

return _wrap(func, superFunc);
}

function _wrap(func, superFunc) {
function superWrapper() {
var 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: ret = func.apply(this, arguments); break;
}
this._super = orig;
return ret;
}

Expand Down
2 changes: 0 additions & 2 deletions packages/ember-runtime/lib/system/core_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import {
generateGuid,
GUID_KEY_PROPERTY,
NEXT_SUPER_PROPERTY,
makeArray
} from 'ember-metal/utils';
import { meta } from 'ember-metal/meta';
Expand Down Expand Up @@ -73,7 +72,6 @@ function makeCtor() {
}

this.__defineNonEnumerable(GUID_KEY_PROPERTY);
this.__defineNonEnumerable(NEXT_SUPER_PROPERTY);
var m = meta(this);
var proto = m.proto;
m.proto = this;
Expand Down

0 comments on commit 6336d21

Please sign in to comment.