mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Remove defineProperty forks of baseSetData and getData.
This commit is contained in:
37
lodash.js
37
lodash.js
@@ -27,9 +27,6 @@
|
|||||||
var HOT_COUNT = 150,
|
var HOT_COUNT = 150,
|
||||||
HOT_SPAN = 16;
|
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 */
|
/** Used as the TypeError message for "Functions" methods */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
@@ -722,17 +719,6 @@
|
|||||||
return result;
|
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 */
|
/* Native method references for those with the same name as other `lodash` methods */
|
||||||
var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
|
var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
|
||||||
nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
|
nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
|
||||||
@@ -2226,19 +2212,10 @@
|
|||||||
* @param {*} data The metadata.
|
* @param {*} data The metadata.
|
||||||
* @returns {Function} Returns `func`.
|
* @returns {Function} Returns `func`.
|
||||||
*/
|
*/
|
||||||
function baseSetData(func, data) {
|
var baseSetData = !WeakMap ? identity : function(func, data) {
|
||||||
metaMap.set(func, data);
|
metaMap.set(func, data);
|
||||||
return func;
|
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
|
* The base implementation of `_.some` without support for callback shorthands
|
||||||
@@ -2831,15 +2808,9 @@
|
|||||||
* @param {Function} func The function to query.
|
* @param {Function} func The function to query.
|
||||||
* @returns {*} Returns the metadata for `func`.
|
* @returns {*} Returns the metadata for `func`.
|
||||||
*/
|
*/
|
||||||
function getData(func) {
|
var getData = !WeakMap ? noop : function(func) {
|
||||||
return metaMap.get(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
|
* Gets the appropriate "indexOf" function. If the `_.indexOf` method is
|
||||||
|
|||||||
@@ -275,7 +275,6 @@
|
|||||||
// store Lo-Dash to test for bad extensions/shims
|
// store Lo-Dash to test for bad extensions/shims
|
||||||
if (!ui.isModularize) {
|
if (!ui.isModularize) {
|
||||||
var lodashBizarro = window._;
|
var lodashBizarro = window._;
|
||||||
lodashBizarro.support.funcNames = !lodashBizarro.support.funcNames;
|
|
||||||
window._ = undefined;
|
window._ = undefined;
|
||||||
removeBizarroMethods();
|
removeBizarroMethods();
|
||||||
}
|
}
|
||||||
@@ -396,7 +395,6 @@
|
|||||||
addBizarroMethods();
|
addBizarroMethods();
|
||||||
require(getConfig(), ['lodash'], function(lodash) {
|
require(getConfig(), ['lodash'], function(lodash) {
|
||||||
lodashBizarro = (lodash['default'] || lodash).noConflict();
|
lodashBizarro = (lodash['default'] || lodash).noConflict();
|
||||||
lodashBizarro.support.funcNames = !lodashBizarro.support.funcNames;
|
|
||||||
delete requirejs.s.contexts._;
|
delete requirejs.s.contexts._;
|
||||||
|
|
||||||
removeBizarroMethods();
|
removeBizarroMethods();
|
||||||
|
|||||||
56
test/test.js
56
test/test.js
@@ -202,9 +202,6 @@
|
|||||||
(_.runInContext ? _.runInContext(root) : _)
|
(_.runInContext ? _.runInContext(root) : _)
|
||||||
));
|
));
|
||||||
|
|
||||||
/** Used as the property name for wrapper metadata */
|
|
||||||
var EXPANDO = '__lodash_' + _.VERSION.replace(/[-.]/g, '_') + '__';
|
|
||||||
|
|
||||||
/** Used to provide falsey values to methods */
|
/** Used to provide falsey values to methods */
|
||||||
var falsey = [, '', 0, false, NaN, null, undefined];
|
var falsey = [, '', 0, false, NaN, null, undefined];
|
||||||
|
|
||||||
@@ -471,7 +468,6 @@
|
|||||||
|
|
||||||
// load Lo-Dash and expose it to the bad extensions/shims
|
// load Lo-Dash and expose it to the bad extensions/shims
|
||||||
lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro['default'] || lodashBizarro;
|
lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro['default'] || lodashBizarro;
|
||||||
lodashBizarro.support.funcNames = !lodashBizarro.support.funcNames;
|
|
||||||
|
|
||||||
// restore native methods
|
// restore native methods
|
||||||
setProperty(Array, 'isArray', _isArray);
|
setProperty(Array, 'isArray', _isArray);
|
||||||
@@ -2229,46 +2225,36 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should only write metadata to named functions', 3, function() {
|
test('should work with bizarro `_.support.funcNames`', 6, function() {
|
||||||
function a() {};
|
function a() {}
|
||||||
|
|
||||||
var b = function() {};
|
var b = function() {};
|
||||||
function c() {};
|
|
||||||
|
|
||||||
var object = {};
|
function c() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
if (lodashBizarro && lodashBizarro.support.funcDecomp) {
|
var object = {},
|
||||||
lodashBizarro.callback(a, object);
|
supportBizarro = lodashBizarro.support,
|
||||||
ok(EXPANDO in a);
|
funcDecomp = supportBizarro.funcDecomp,
|
||||||
|
funcNames = supportBizarro.funcNames;
|
||||||
|
|
||||||
lodashBizarro.callback(b, object);
|
supportBizarro.funcNames = !supportBizarro.funcNames;
|
||||||
ok(!(EXPANDO in b));
|
supportBizarro.funcDecomp = true;
|
||||||
|
|
||||||
if (lodashBizarro.support.funcNames) {
|
_.each([a, b, c], function(fn) {
|
||||||
lodashBizarro.support.funcNames = false;
|
if (_.support.funcDecomp) {
|
||||||
lodashBizarro.callback(c, object);
|
var callback = lodashBizarro.callback(fn, object);
|
||||||
|
strictEqual(callback(), fn === c ? object : undefined);
|
||||||
ok(EXPANDO in c);
|
strictEqual(callback === fn, fn === a);
|
||||||
lodashBizarro.support.funcNames = true;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest();
|
skipTest(2);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
else {
|
|
||||||
skipTest(3);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should not write metadata when `_.support.funcDecomp` is `false`', 1, function() {
|
supportBizarro.funcDecomp = funcDecomp;
|
||||||
function a() {};
|
supportBizarro.funcNames = funcNames;
|
||||||
|
|
||||||
if (lodashBizarro) {
|
|
||||||
lodashBizarro.callback(a, {});
|
|
||||||
ok(!(EXPANDO in a));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should be aliased', 1, function() {
|
test('should be aliased', 1, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user