From aa1d7d870d9cf84842ee23ff485fd24abf0ed3d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Am=C3=A9rico?= Date: Tue, 11 Dec 2018 12:53:23 -0300 Subject: [PATCH] Replace getTag implementation by the one from baseGetTag (remove workarounds) (#4115) --- .internal/baseGetTag.js | 17 -------------- .internal/baseIsEqualDeep.js | 6 ++--- .internal/getTag.js | 44 ++++-------------------------------- isArguments.js | 4 ++-- isArrayBuffer.js | 4 ++-- isBoolean.js | 4 ++-- isDate.js | 4 ++-- isError.js | 4 ++-- isFunction.js | 4 ++-- isNumber.js | 4 ++-- isPlainObject.js | 4 ++-- isRegExp.js | 4 ++-- isString.js | 4 ++-- isSymbol.js | 4 ++-- isTypedArray.js | 4 ++-- 15 files changed, 32 insertions(+), 83 deletions(-) delete mode 100644 .internal/baseGetTag.js diff --git a/.internal/baseGetTag.js b/.internal/baseGetTag.js deleted file mode 100644 index aed858735..000000000 --- a/.internal/baseGetTag.js +++ /dev/null @@ -1,17 +0,0 @@ -const toString = Object.prototype.toString - -/** - * The base implementation of `getTag` without fallbacks for buggy environments. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the `toStringTag`. - */ -function baseGetTag(value) { - if (value == null) { - return value === undefined ? '[object Undefined]' : '[object Null]' - } - return toString.call(value) -} - -export default baseGetTag diff --git a/.internal/baseIsEqualDeep.js b/.internal/baseIsEqualDeep.js index cb9337bdd..27749cd01 100644 --- a/.internal/baseIsEqualDeep.js +++ b/.internal/baseIsEqualDeep.js @@ -2,7 +2,7 @@ import Stack from './Stack.js' import equalArrays from './equalArrays.js' import equalByTag from './equalByTag.js' import equalObjects from './equalObjects.js' -import baseGetTag from './baseGetTag.js' +import getTag from './getTag.js' import isBuffer from '../isBuffer.js' import isTypedArray from '../isTypedArray.js' @@ -34,8 +34,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { let objIsArr = Array.isArray(object) const othIsArr = Array.isArray(other) - let objTag = objIsArr ? arrayTag : baseGetTag(object) - let othTag = othIsArr ? arrayTag : baseGetTag(other) + let objTag = objIsArr ? arrayTag : getTag(object) + let othTag = othIsArr ? arrayTag : getTag(other) objTag = objTag == argsTag ? objectTag : objTag othTag = othTag == argsTag ? objectTag : othTag diff --git a/.internal/getTag.js b/.internal/getTag.js index d43709d49..04085cb4b 100644 --- a/.internal/getTag.js +++ b/.internal/getTag.js @@ -1,19 +1,4 @@ -import baseGetTag from './baseGetTag.js' - -/** `Object#toString` result references. */ -const dataViewTag = '[object DataView]' -const mapTag = '[object Map]' -const objectTag = '[object Object]' -const promiseTag = '[object Promise]' -const setTag = '[object Set]' -const weakMapTag = '[object WeakMap]' - -/** Used to detect maps, sets, and weakmaps. */ -const dataViewCtorString = `${DataView}` -const mapCtorString = `${Map}` -const promiseCtorString = `${Promise}` -const setCtorString = `${Set}` -const weakMapCtorString = `${WeakMap}` +const toString = Object.prototype.toString /** * Gets the `toStringTag` of `value`. @@ -22,30 +7,11 @@ const weakMapCtorString = `${WeakMap}` * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ -let getTag = baseGetTag - -// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6. -if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || - (getTag(new Map) != mapTag) || - (getTag(Promise.resolve()) != promiseTag) || - (getTag(new Set) != setTag) || - (getTag(new WeakMap) != weakMapTag)) { - getTag = (value) => { - const result = baseGetTag(value) - const Ctor = result == objectTag ? value.constructor : undefined - const ctorString = Ctor ? `${Ctor}` : '' - - if (ctorString) { - switch (ctorString) { - case dataViewCtorString: return dataViewTag - case mapCtorString: return mapTag - case promiseCtorString: return promiseTag - case setCtorString: return setTag - case weakMapCtorString: return weakMapTag - } - } - return result +function getTag(value) { + if (value == null) { + return value === undefined ? '[object Undefined]' : '[object Null]' } + return toString.call(value) } export default getTag diff --git a/isArguments.js b/isArguments.js index 3051a50b9..0bfdbe12c 100644 --- a/isArguments.js +++ b/isArguments.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' import isObjectLike from './isObjectLike' /** @@ -17,7 +17,7 @@ import isObjectLike from './isObjectLike' * // => false */ function isArguments(value) { - return isObjectLike(value) && baseGetTag(value) == '[object Arguments]' + return isObjectLike(value) && getTag(value) == '[object Arguments]' } export default isArguments diff --git a/isArrayBuffer.js b/isArrayBuffer.js index 77603b765..add5067c7 100644 --- a/isArrayBuffer.js +++ b/isArrayBuffer.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' import isObjectLike from './isObjectLike.js' import nodeTypes from './.internal/nodeTypes.js' @@ -22,6 +22,6 @@ const nodeIsArrayBuffer = nodeTypes && nodeTypes.isArrayBuffer */ const isArrayBuffer = nodeIsArrayBuffer ? (value) => nodeIsArrayBuffer(value) - : (value) => isObjectLike(value) && baseGetTag(value) == '[object ArrayBuffer]' + : (value) => isObjectLike(value) && getTag(value) == '[object ArrayBuffer]' export default isArrayBuffer diff --git a/isBoolean.js b/isBoolean.js index 0ac7edef0..04a5c530b 100644 --- a/isBoolean.js +++ b/isBoolean.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' import isObjectLike from './isObjectLike.js' /** @@ -18,7 +18,7 @@ import isObjectLike from './isObjectLike.js' */ function isBoolean(value) { return value === true || value === false || - (isObjectLike(value) && baseGetTag(value) == '[object Boolean]') + (isObjectLike(value) && getTag(value) == '[object Boolean]') } export default isBoolean diff --git a/isDate.js b/isDate.js index ad8e41731..1486be633 100644 --- a/isDate.js +++ b/isDate.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' import isObjectLike from './isObjectLike.js' import nodeTypes from './.internal/nodeTypes.js' @@ -22,6 +22,6 @@ const nodeIsDate = nodeTypes && nodeTypes.isDate */ const isDate = nodeIsDate ? (value) => nodeIsDate(value) - : (value) => isObjectLike(value) && baseGetTag(value) == '[object Date]' + : (value) => isObjectLike(value) && getTag(value) == '[object Date]' export default isDate diff --git a/isError.js b/isError.js index 6ac9bb4ef..a0c65d3e4 100644 --- a/isError.js +++ b/isError.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' import isObjectLike from './isObjectLike.js' import isPlainObject from './isPlainObject.js' @@ -22,7 +22,7 @@ function isError(value) { if (!isObjectLike(value)) { return false } - const tag = baseGetTag(value) + const tag = getTag(value) return tag == '[object Error]' || tag == '[object DOMException]' || (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)) } diff --git a/isFunction.js b/isFunction.js index 7f593cbcf..4c96c365a 100644 --- a/isFunction.js +++ b/isFunction.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' import isObject from './isObject.js' /** @@ -22,7 +22,7 @@ function isFunction(value) { } // The use of `Object#toString` avoids issues with the `typeof` operator // in Safari 9 which returns 'object' for typed arrays and other constructors. - const tag = baseGetTag(value) + const tag = getTag(value) return tag == '[object Function]' || tag == '[object AsyncFunction]' || tag == '[object GeneratorFunction]' || tag == '[object Proxy]' } diff --git a/isNumber.js b/isNumber.js index d70572b95..db9e5efb1 100644 --- a/isNumber.js +++ b/isNumber.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' import isObjectLike from './isObjectLike.js' /** @@ -28,7 +28,7 @@ import isObjectLike from './isObjectLike.js' */ function isNumber(value) { return typeof value == 'number' || - (isObjectLike(value) && baseGetTag(value) == '[object Number]') + (isObjectLike(value) && getTag(value) == '[object Number]') } export default isNumber diff --git a/isPlainObject.js b/isPlainObject.js index 34dcf9af8..896d4576f 100644 --- a/isPlainObject.js +++ b/isPlainObject.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' import isObjectLike from './isObjectLike.js' /** @@ -28,7 +28,7 @@ import isObjectLike from './isObjectLike.js' * // => true */ function isPlainObject(value) { - if (!isObjectLike(value) || baseGetTag(value) != '[object Object]') { + if (!isObjectLike(value) || getTag(value) != '[object Object]') { return false } if (Object.getPrototypeOf(value) === null) { diff --git a/isRegExp.js b/isRegExp.js index 7566ac963..42d567d68 100644 --- a/isRegExp.js +++ b/isRegExp.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' import isObjectLike from './isObjectLike.js' import nodeTypes from './.internal/nodeTypes.js' @@ -22,6 +22,6 @@ const nodeIsRegExp = nodeTypes && nodeTypes.isRegExp */ const isRegExp = nodeIsRegExp ? (value) => nodeIsRegExp(value) - : (value) => isObjectLike(value) && baseGetTag(value) == '[object RegExp]' + : (value) => isObjectLike(value) && getTag(value) == '[object RegExp]' export default isRegExp diff --git a/isString.js b/isString.js index 37aaa9066..b9ec3ae59 100644 --- a/isString.js +++ b/isString.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' /** * Checks if `value` is classified as a `String` primitive or object. @@ -17,7 +17,7 @@ import baseGetTag from './.internal/baseGetTag.js' */ function isString(value) { const type = typeof value - return type == 'string' || (type == 'object' && value != null && !Array.isArray(value) && baseGetTag(value) == '[object String]') + return type == 'string' || (type == 'object' && value != null && !Array.isArray(value) && getTag(value) == '[object String]') } export default isString diff --git a/isSymbol.js b/isSymbol.js index 570981bf2..8ea537f4e 100644 --- a/isSymbol.js +++ b/isSymbol.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' /** * Checks if `value` is classified as a `Symbol` primitive or object. @@ -17,7 +17,7 @@ import baseGetTag from './.internal/baseGetTag.js' */ function isSymbol(value) { const type = typeof value - return type == 'symbol' || (type == 'object' && value != null && baseGetTag(value) == '[object Symbol]') + return type == 'symbol' || (type == 'object' && value != null && getTag(value) == '[object Symbol]') } export default isSymbol diff --git a/isTypedArray.js b/isTypedArray.js index c41e9f854..564ec0107 100644 --- a/isTypedArray.js +++ b/isTypedArray.js @@ -1,4 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' +import getTag from './.internal/getTag.js' import nodeTypes from './.internal/nodeTypes.js' import isObjectLike from './isObjectLike' @@ -25,6 +25,6 @@ const nodeIsTypedArray = nodeTypes && nodeTypes.isTypedArray */ const isTypedArray = nodeIsTypedArray ? (value) => nodeIsTypedArray(value) - : (value) => isObjectLike(value) && reTypedTag.test(baseGetTag(value)) + : (value) => isObjectLike(value) && reTypedTag.test(getTag(value)) export default isTypedArray