diff --git a/lodash.js b/lodash.js index 2b3fd65f0..6dbb79143 100644 --- a/lodash.js +++ b/lodash.js @@ -27,9 +27,6 @@ var HOT_COUNT = 150, HOT_SPAN = 16; - /** Used as the property name for wrapper metadata */ - var EXPANDO = '__lodash_' + VERSION.replace(/[-.]/g, '_') + '__'; - /** Used as the TypeError message for "Functions" methods */ var FUNC_ERROR_TEXT = 'Expected a function'; @@ -722,17 +719,6 @@ return result; }()); - /** Used to set metadata on functions */ - var defineProperty = (function() { - // IE 8 only accepts DOM elements - try { - var o = {}, - func = isNative(func = Object.defineProperty) && func, - result = func(o, o, o) && func; - } catch(e) {} - return result; - }()); - /* Native method references for those with the same name as other `lodash` methods */ var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate, nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray, @@ -2226,19 +2212,10 @@ * @param {*} data The metadata. * @returns {Function} Returns `func`. */ - function baseSetData(func, data) { + var baseSetData = !WeakMap ? identity : function(func, data) { metaMap.set(func, data); return func; - } - // fallback for environments without `WeakMap` - if (!WeakMap) { - baseSetData = !defineProperty ? identity : function(func, value) { - descriptor.value = value; - defineProperty(func, EXPANDO, descriptor); - descriptor.value = null; - return func; - }; - } + }; /** * The base implementation of `_.some` without support for callback shorthands @@ -2831,15 +2808,9 @@ * @param {Function} func The function to query. * @returns {*} Returns the metadata for `func`. */ - function getData(func) { + var getData = !WeakMap ? noop : function(func) { return metaMap.get(func); - } - // fallback for environments without `WeakMap` - if (!WeakMap) { - getData = !defineProperty ? noop : function(func) { - return func[EXPANDO]; - }; - } + }; /** * Gets the appropriate "indexOf" function. If the `_.indexOf` method is diff --git a/test/index.html b/test/index.html index 5c5ca8893..74294700d 100644 --- a/test/index.html +++ b/test/index.html @@ -275,7 +275,6 @@ // store Lo-Dash to test for bad extensions/shims if (!ui.isModularize) { var lodashBizarro = window._; - lodashBizarro.support.funcNames = !lodashBizarro.support.funcNames; window._ = undefined; removeBizarroMethods(); } @@ -396,7 +395,6 @@ addBizarroMethods(); require(getConfig(), ['lodash'], function(lodash) { lodashBizarro = (lodash['default'] || lodash).noConflict(); - lodashBizarro.support.funcNames = !lodashBizarro.support.funcNames; delete requirejs.s.contexts._; removeBizarroMethods(); diff --git a/test/test.js b/test/test.js index deb5eadf6..a6fabed4e 100644 --- a/test/test.js +++ b/test/test.js @@ -202,9 +202,6 @@ (_.runInContext ? _.runInContext(root) : _) )); - /** Used as the property name for wrapper metadata */ - var EXPANDO = '__lodash_' + _.VERSION.replace(/[-.]/g, '_') + '__'; - /** Used to provide falsey values to methods */ var falsey = [, '', 0, false, NaN, null, undefined]; @@ -471,7 +468,6 @@ // load Lo-Dash and expose it to the bad extensions/shims lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro['default'] || lodashBizarro; - lodashBizarro.support.funcNames = !lodashBizarro.support.funcNames; // restore native methods setProperty(Array, 'isArray', _isArray); @@ -2229,46 +2225,36 @@ } }); - test('should only write metadata to named functions', 3, function() { - function a() {}; + test('should work with bizarro `_.support.funcNames`', 6, function() { + function a() {} + var b = function() {}; - function c() {}; - var object = {}; + function c() { + return this; + } - if (lodashBizarro && lodashBizarro.support.funcDecomp) { - lodashBizarro.callback(a, object); - ok(EXPANDO in a); + var object = {}, + supportBizarro = lodashBizarro.support, + funcDecomp = supportBizarro.funcDecomp, + funcNames = supportBizarro.funcNames; - lodashBizarro.callback(b, object); - ok(!(EXPANDO in b)); + supportBizarro.funcNames = !supportBizarro.funcNames; + supportBizarro.funcDecomp = true; - if (lodashBizarro.support.funcNames) { - lodashBizarro.support.funcNames = false; - lodashBizarro.callback(c, object); - - ok(EXPANDO in c); - lodashBizarro.support.funcNames = true; + _.each([a, b, c], function(fn) { + if (_.support.funcDecomp) { + var callback = lodashBizarro.callback(fn, object); + strictEqual(callback(), fn === c ? object : undefined); + strictEqual(callback === fn, fn === a); } else { - skipTest(); + skipTest(2); } - } - else { - skipTest(3); - } - }); + }); - test('should not write metadata when `_.support.funcDecomp` is `false`', 1, function() { - function a() {}; - - if (lodashBizarro) { - lodashBizarro.callback(a, {}); - ok(!(EXPANDO in a)); - } - else { - skipTest(); - } + supportBizarro.funcDecomp = funcDecomp; + supportBizarro.funcNames = funcNames; }); test('should be aliased', 1, function() {