mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Detect maps and sets in IE11.
This commit is contained in:
68
lodash.js
68
lodash.js
@@ -1285,6 +1285,10 @@
|
|||||||
// See https://es5.github.io/#x11.1.5 for more details.
|
// See https://es5.github.io/#x11.1.5 for more details.
|
||||||
context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
|
context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root;
|
||||||
|
|
||||||
|
/** Used as references for `-Infinity` and `Infinity`. */
|
||||||
|
var NEGATIVE_INFINITY = context.Number.NEGATIVE_INFINITY,
|
||||||
|
POSITIVE_INFINITY = context.Number.POSITIVE_INFINITY;
|
||||||
|
|
||||||
/** Native constructor references. */
|
/** Native constructor references. */
|
||||||
var Date = context.Date,
|
var Date = context.Date,
|
||||||
Error = context.Error,
|
Error = context.Error,
|
||||||
@@ -1320,7 +1324,7 @@
|
|||||||
|
|
||||||
/** Used to detect if a method is native. */
|
/** Used to detect if a method is native. */
|
||||||
var reIsNative = RegExp('^' +
|
var reIsNative = RegExp('^' +
|
||||||
fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
|
fnToString.call(hasOwnProperty).replace(reRegExpChars, '\\$&')
|
||||||
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1346,19 +1350,24 @@
|
|||||||
nativeFloor = Math.floor,
|
nativeFloor = Math.floor,
|
||||||
nativeIsFinite = context.isFinite,
|
nativeIsFinite = context.isFinite,
|
||||||
nativeKeys = Object.keys,
|
nativeKeys = Object.keys,
|
||||||
|
nativeMap = getNative(context, 'Map'),
|
||||||
nativeMax = Math.max,
|
nativeMax = Math.max,
|
||||||
nativeMin = Math.min,
|
nativeMin = Math.min,
|
||||||
nativeParseInt = context.parseInt,
|
nativeParseInt = context.parseInt,
|
||||||
nativeRandom = Math.random,
|
nativeRandom = Math.random,
|
||||||
nativeSet = getNative(context, 'Set');
|
nativeSet = getNative(context, 'Set');
|
||||||
|
|
||||||
/** Used as references for `-Infinity` and `Infinity`. */
|
|
||||||
var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
|
|
||||||
POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
|
||||||
|
|
||||||
/** Used to store function metadata. */
|
/** Used to store function metadata. */
|
||||||
var metaMap = WeakMap && new WeakMap;
|
var metaMap = WeakMap && new WeakMap;
|
||||||
|
|
||||||
|
/** Used to detect maps and sets. */
|
||||||
|
var mapCtorString = nativeMap ? fnToString.call(nativeMap) : '',
|
||||||
|
setCtorString = nativeSet ? fnToString.call(nativeSet) : '';
|
||||||
|
|
||||||
|
/** Detect support for map and set `toStringTag` values. */
|
||||||
|
var noMapSetTag = nativeMap && nativeSet &&
|
||||||
|
!(objToString.call(new Map) == mapTag && objToString.call(new Set) == setTag);
|
||||||
|
|
||||||
/** Used to lookup unminified function names. */
|
/** Used to lookup unminified function names. */
|
||||||
var realNames = {};
|
var realNames = {};
|
||||||
|
|
||||||
@@ -1865,6 +1874,9 @@
|
|||||||
var tag = objToString.call(value),
|
var tag = objToString.call(value),
|
||||||
isFunc = tag == funcTag;
|
isFunc = tag == funcTag;
|
||||||
|
|
||||||
|
if (tag == objectTag && noMapSetTag) {
|
||||||
|
tag = isMap(value) ? mapTag : (isSet(value) ? setTag : tag);
|
||||||
|
}
|
||||||
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
||||||
if (isHostObject(value)) {
|
if (isHostObject(value)) {
|
||||||
return object ? value : {};
|
return object ? value : {};
|
||||||
@@ -2272,17 +2284,21 @@
|
|||||||
|
|
||||||
if (!objIsArr) {
|
if (!objIsArr) {
|
||||||
objTag = objToString.call(object);
|
objTag = objToString.call(object);
|
||||||
if (objTag == argsTag) {
|
if (othTag == objectTag && noMapSetTag) {
|
||||||
|
objTag = isMap(object) ? mapTag : (isSet(object) ? setTag : objTag);
|
||||||
|
} else if (objTag == argsTag) {
|
||||||
objTag = objectTag;
|
objTag = objectTag;
|
||||||
} else if (objTag != objectTag) {
|
} else {
|
||||||
objIsArr = isTypedArray(object);
|
objIsArr = isTypedArray(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!othIsArr) {
|
if (!othIsArr) {
|
||||||
othTag = objToString.call(other);
|
othTag = objToString.call(other);
|
||||||
if (othTag == argsTag) {
|
if (othTag == objectTag && noMapSetTag) {
|
||||||
|
othTag = isMap(other) ? mapTag : (isSet(other) ? setTag : othTag);
|
||||||
|
} else if (othTag == argsTag) {
|
||||||
othTag = objectTag;
|
othTag = objectTag;
|
||||||
} else if (othTag != objectTag) {
|
} else {
|
||||||
othIsArr = isTypedArray(other);
|
othIsArr = isTypedArray(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4132,6 +4148,18 @@
|
|||||||
return !!data && func === data[0];
|
return !!data && func === data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if `value` is classified as a `Map` object.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {*} value The value to check.
|
||||||
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
||||||
|
*/
|
||||||
|
function isMap(value) {
|
||||||
|
var Ctor = value && value.constructor;
|
||||||
|
return typeof Ctor == 'function' && fnToString.call(Ctor) == mapCtorString;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is a prototype.
|
* Checks if `value` is a prototype.
|
||||||
*
|
*
|
||||||
@@ -4140,12 +4168,24 @@
|
|||||||
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
||||||
*/
|
*/
|
||||||
function isPrototype(value) {
|
function isPrototype(value) {
|
||||||
var Ctor = !!value && value.constructor,
|
var Ctor = value && value.constructor,
|
||||||
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
||||||
|
|
||||||
return value === proto;
|
return value === proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if `value` is classified as a `Set` object.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {*} value The value to check.
|
||||||
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
||||||
|
*/
|
||||||
|
function isSet(value) {
|
||||||
|
var Ctor = value && value.constructor;
|
||||||
|
return typeof Ctor == 'function' && fnToString.call(Ctor) == setCtorString;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
|
* Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
|
||||||
*
|
*
|
||||||
@@ -8754,9 +8794,11 @@
|
|||||||
if (iteratorSymbol && value[iteratorSymbol]) {
|
if (iteratorSymbol && value[iteratorSymbol]) {
|
||||||
return iteratorToArray(value[iteratorSymbol]());
|
return iteratorToArray(value[iteratorSymbol]());
|
||||||
}
|
}
|
||||||
var tag = objToString.call(value),
|
var tag = objToString.call(value);
|
||||||
func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
|
if (tag == objectTag && noMapSetTag) {
|
||||||
|
tag = isMap(value) ? mapTag : (isSet(value) ? setTag : tag);
|
||||||
|
}
|
||||||
|
var func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
|
||||||
return func(value);
|
return func(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user