diff --git a/packages/ember-metal/lib/environment.js b/packages/ember-metal/lib/environment.js index d3e79c07de6..0bebf1db80a 100644 --- a/packages/ember-metal/lib/environment.js +++ b/packages/ember-metal/lib/environment.js @@ -26,6 +26,7 @@ if (hasDOM) { hasDOM: true, isChrome: !!window.chrome && !window.opera, isFirefox: typeof InstallTrigger !== 'undefined', + isPhantom: !!window.callPhantom, location: window.location, history: window.history, userAgent: window.navigator.userAgent, @@ -36,6 +37,7 @@ if (hasDOM) { hasDOM: false, isChrome: false, isFirefox: false, + isPhantom: false, location: null, history: null, userAgent: 'Lynx (textmode)', diff --git a/packages/ember-metal/lib/utils.js b/packages/ember-metal/lib/utils.js index 886115e0693..9a939f89a45 100644 --- a/packages/ember-metal/lib/utils.js +++ b/packages/ember-metal/lib/utils.js @@ -254,10 +254,10 @@ export function guidFor(obj) { const HAS_SUPER_PATTERN = /\.(_super|call\(this|apply\(this)/; -const checkHasSuper = (function () { +export const checkHasSuper = (function () { let sourceAvailable = (function() { return this; - }).toString().indexOf('return this;') > -1; + }).toString().indexOf('return this') > -1; if (sourceAvailable) { return function checkHasSuper(func) { diff --git a/packages/ember-metal/tests/utils_test.js b/packages/ember-metal/tests/utils_test.js index 444c9d092af..ca0d1624d23 100644 --- a/packages/ember-metal/tests/utils_test.js +++ b/packages/ember-metal/tests/utils_test.js @@ -1,4 +1,5 @@ -import { inspect } from 'ember-metal/utils'; +import { inspect, checkHasSuper } from 'ember-metal/utils'; +import environment from 'ember-metal/environment'; QUnit.module('Ember Metal Utils'); @@ -14,3 +15,12 @@ QUnit.test('inspect outputs the toString() representation of Symbols', function( expect(0); } }); + +// Only run this test on browsers that we are certain should have function +// source available. This allows the test suite to continue to pass on other +// platforms that correctly (for them) fall back to the "always wrap" code. +if (environment.isPhantom || environment.isChrome || environment.isFirefox) { + QUnit.test('does not super wrap needlessly [GH #12462]', function(assert) { + assert.notOk(checkHasSuper(function() {}), 'empty function does not have super'); + }); +}