Replace getTag implementation by the one from baseGetTag (remove workarounds) (#4115)

This commit is contained in:
Luiz Américo
2018-12-11 12:53:23 -03:00
committed by John-David Dalton
parent c77650a17b
commit aa1d7d870d
15 changed files with 32 additions and 83 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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))
}

View File

@@ -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]'
}

View File

@@ -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

View File

@@ -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) {

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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