mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Remove nativeAssign and getOwnPropertySymbols use.
This commit is contained in:
@@ -781,7 +781,6 @@
|
||||
ceil = Math.ceil,
|
||||
clearTimeout = context.clearTimeout,
|
||||
floor = Math.floor,
|
||||
getOwnPropertySymbols = isNative(getOwnPropertySymbols = Object.getOwnPropertySymbols) && getOwnPropertySymbols,
|
||||
getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
|
||||
push = arrayProto.push,
|
||||
preventExtensions = isNative(preventExtensions = Object.preventExtensions) && preventExtensions,
|
||||
@@ -804,29 +803,6 @@
|
||||
return result;
|
||||
}());
|
||||
|
||||
/** Used as `baseAssign`. */
|
||||
var nativeAssign = (function() {
|
||||
// Avoid `Object.assign` in Firefox 34-37 which have an early implementation
|
||||
// with a now defunct try/catch behavior. See https://bugzilla.mozilla.org/show_bug.cgi?id=1103344
|
||||
// for more details.
|
||||
//
|
||||
// Use `Object.preventExtensions` on a plain object instead of simply using
|
||||
// `Object('x')` because Chrome and IE fail to throw an error when attempting
|
||||
// to assign values to readonly indexes of strings.
|
||||
var func = preventExtensions && isNative(func = Object.assign) && func;
|
||||
try {
|
||||
if (func) {
|
||||
var object = preventExtensions({ '1': 0 });
|
||||
object[0] = 1;
|
||||
}
|
||||
} catch(e) {
|
||||
// Only attempt in strict mode.
|
||||
try { func(object, 'xo'); } catch(e) {}
|
||||
return !object[1] && func;
|
||||
}
|
||||
return false;
|
||||
}());
|
||||
|
||||
/* 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,
|
||||
@@ -1781,10 +1757,8 @@
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
function assignWith(object, source, customizer) {
|
||||
var props = keys(source);
|
||||
push.apply(props, getSymbols(source));
|
||||
|
||||
var index = -1,
|
||||
props = keys(source),
|
||||
length = props.length;
|
||||
|
||||
while (++index < length) {
|
||||
@@ -1809,11 +1783,11 @@
|
||||
* @param {Object} source The source object.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
var baseAssign = nativeAssign || function(object, source) {
|
||||
function baseAssign(object, source) {
|
||||
return source == null
|
||||
? object
|
||||
: baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object));
|
||||
};
|
||||
: baseCopy(source, keys(source), object);
|
||||
}
|
||||
|
||||
/**
|
||||
* The base implementation of `_.at` without support for string collections
|
||||
@@ -2603,11 +2577,9 @@
|
||||
if (!isObject(object)) {
|
||||
return object;
|
||||
}
|
||||
var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source));
|
||||
if (!isSrcArr) {
|
||||
var props = keys(source);
|
||||
push.apply(props, getSymbols(source));
|
||||
}
|
||||
var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
|
||||
props = !isSrcArr && keys(source);
|
||||
|
||||
arrayEach(props || source, function(srcValue, key) {
|
||||
if (props) {
|
||||
key = srcValue;
|
||||
@@ -4162,17 +4134,6 @@
|
||||
*/
|
||||
var getLength = baseProperty('length');
|
||||
|
||||
/**
|
||||
* Creates an array of the own symbols of `object`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to query.
|
||||
* @returns {Array} Returns the array of symbols.
|
||||
*/
|
||||
var getSymbols = !getOwnPropertySymbols ? constant([]) : function(object) {
|
||||
return getOwnPropertySymbols(toObject(object));
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the view, applying any `transforms` to the `start` and `end` positions.
|
||||
*
|
||||
|
||||
@@ -90,15 +90,6 @@
|
||||
setProperty(Date, '_now', Date.now);
|
||||
setProperty(Date, 'now', noop);
|
||||
|
||||
setProperty(Object, '_getOwnPropertySymbols', Object.getOwnPropertySymbols);
|
||||
setProperty(Object, 'getOwnPropertySymbols', (function() {
|
||||
function getOwnPropertySymbols() {
|
||||
return [];
|
||||
}
|
||||
setProperty(getOwnPropertySymbols, 'toString', createToString('getOwnPropertySymbols'));
|
||||
return getOwnPropertySymbols;
|
||||
}()));
|
||||
|
||||
setProperty(Object, '_getPrototypeOf', Object.getPrototypeOf);
|
||||
setProperty(Object, 'getPrototypeOf', noop);
|
||||
|
||||
@@ -204,11 +195,6 @@
|
||||
} else {
|
||||
delete Date.now;
|
||||
}
|
||||
if (Object._getOwnPropertySymbols) {
|
||||
setProperty(Object, 'getOwnPropertySymbols', Object._getOwnPropertySymbols);
|
||||
} else {
|
||||
delete Object.getOwnPropertySymbols;
|
||||
}
|
||||
if (Object._getPrototypeOf) {
|
||||
setProperty(Object, 'getPrototypeOf', Object._getPrototypeOf);
|
||||
} else {
|
||||
@@ -255,7 +241,6 @@
|
||||
|
||||
delete Array._isArray;
|
||||
delete Date._now;
|
||||
delete Object._getOwnPropertySymbols;
|
||||
delete Object._getPrototypeOf;
|
||||
delete Object._keys;
|
||||
delete funcProto._method;
|
||||
|
||||
42
test/test.js
42
test/test.js
@@ -460,15 +460,6 @@
|
||||
var _now = Date.now;
|
||||
setProperty(Date, 'now', _.noop);
|
||||
|
||||
var _getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
||||
setProperty(Object, 'getOwnPropertySymbols', (function() {
|
||||
function getOwnPropertySymbols() {
|
||||
return [];
|
||||
}
|
||||
setProperty(getOwnPropertySymbols, 'toString', createToString('getOwnPropertySymbols'));
|
||||
return getOwnPropertySymbols;
|
||||
}()));
|
||||
|
||||
var _getPrototypeOf = Object.getPrototypeOf;
|
||||
setProperty(Object, 'getPrototypeOf', _.noop);
|
||||
|
||||
@@ -561,7 +552,6 @@
|
||||
// Restore built-in methods.
|
||||
setProperty(Array, 'isArray', _isArray);
|
||||
setProperty(Date, 'now', _now);
|
||||
setProperty(Object, 'getOwnPropertySymbols', _getOwnPropertySymbols);
|
||||
setProperty(Object, 'getPrototypeOf', _getPrototypeOf);
|
||||
setProperty(Object, 'keys', _keys);
|
||||
|
||||
@@ -708,7 +698,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
test('should avoid overwritten native methods', 13, function() {
|
||||
test('should avoid overwritten native methods', 12, function() {
|
||||
function Foo() {}
|
||||
|
||||
function message(lodashMethod, nativeMethod) {
|
||||
@@ -734,13 +724,6 @@
|
||||
}
|
||||
ok(typeof actual == 'number', message('_.now', 'Date.now'));
|
||||
|
||||
try {
|
||||
actual = lodashBizarro.merge({}, object);
|
||||
} catch(e) {
|
||||
actual = null;
|
||||
}
|
||||
deepEqual(actual, object, message('_.merge', 'Object.getOwnPropertySymbols'));
|
||||
|
||||
try {
|
||||
actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])];
|
||||
} catch(e) {
|
||||
@@ -809,7 +792,7 @@
|
||||
}
|
||||
}
|
||||
else {
|
||||
skipTest(13);
|
||||
skipTest(12);
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -5862,25 +5845,6 @@
|
||||
deepEqual(func({}, new Foo), { 'a': 1 });
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should assign own symbols', 2, function() {
|
||||
if (Symbol) {
|
||||
var symbol1 = Symbol('a'),
|
||||
symbol2 = Symbol('b');
|
||||
|
||||
var Foo = function() {
|
||||
this[symbol1] = 1;
|
||||
};
|
||||
Foo.prototype[symbol2] = 2;
|
||||
|
||||
var actual = func({}, new Foo);
|
||||
strictEqual(actual[symbol1], 1);
|
||||
strictEqual(actual[symbol2], undefined);
|
||||
}
|
||||
else {
|
||||
skipTest(2);
|
||||
}
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should assign problem JScript properties (test in IE < 9)', 1, function() {
|
||||
var object = {
|
||||
'constructor': '0',
|
||||
@@ -16486,8 +16450,8 @@
|
||||
});
|
||||
|
||||
test('should work with large arrays of well-known symbols', 1, function() {
|
||||
// See https://people.mozilla.org/~jorendorff/es6-draft.html#sec-well-known-symbols.
|
||||
if (Symbol) {
|
||||
// See https://people.mozilla.org/~jorendorff/es6-draft.html#sec-well-known-symbols.
|
||||
var expected = [
|
||||
Symbol.hasInstance, Symbol.isConcatSpreadable, Symbol.iterator,
|
||||
Symbol.match, Symbol.replace, Symbol.search, Symbol.species,
|
||||
|
||||
Reference in New Issue
Block a user