From 8db488b943e4e979e9e7a57c99086a7648b57d23 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 22 Mar 2017 21:34:52 -0700 Subject: [PATCH] Remove `getRawTag` and `objectToString`. --- .internal/baseGetTag.js | 38 ++++++++++++++++++++----------- .internal/getRawTag.js | 45 ------------------------------------- .internal/objectToString.js | 19 ---------------- 3 files changed, 25 insertions(+), 77 deletions(-) delete mode 100644 .internal/getRawTag.js delete mode 100644 .internal/objectToString.js diff --git a/.internal/baseGetTag.js b/.internal/baseGetTag.js index 75c77f1e1..870c63f07 100644 --- a/.internal/baseGetTag.js +++ b/.internal/baseGetTag.js @@ -1,12 +1,7 @@ -import getRawTag from './getRawTag.js' -import objectToString from './objectToString.js' - -/** `Object#toString` result references. */ -const nullTag = '[object Null]' -const undefinedTag = '[object Undefined]' - -/** Built-in value references. */ -const symToStringTag = Symbol ? Symbol.toStringTag : undefined +const objectProto = Object.prototype +const hasOwnProperty = objectProto.hasOwnProperty +const toString = objectProto.toString +const symToStringTag = typeof Symbol != 'undefined' ? Symbol.toStringTag : undefined /** * The base implementation of `getTag` without fallbacks for buggy environments. @@ -17,11 +12,28 @@ const symToStringTag = Symbol ? Symbol.toStringTag : undefined */ function baseGetTag(value) { if (value == null) { - return value === undefined ? undefinedTag : nullTag + return value === undefined ? '[object Undefined]' : '[object Null]' } - return (symToStringTag && symToStringTag in Object(value)) - ? getRawTag(value) - : objectToString(value) + if (!(symToStringTag && symToStringTag in Object(value))) { + return toString.call(value) + } + const isOwn = hasOwnProperty.call(value, symToStringTag) + const tag = value[symToStringTag] + let unmasked = false + try { + value[symToStringTag] = undefined + unmasked = true + } catch (e) {} + + const result = toString.call(value) + if (unmasked) { + if (isOwn) { + value[symToStringTag] = tag + } else { + delete value[symToStringTag] + } + } + return result } export default baseGetTag diff --git a/.internal/getRawTag.js b/.internal/getRawTag.js deleted file mode 100644 index 0b8c7165e..000000000 --- a/.internal/getRawTag.js +++ /dev/null @@ -1,45 +0,0 @@ -/** Used for built-in method references. */ -const objectProto = Object.prototype - -/** Used to check objects for own properties. */ -const hasOwnProperty = objectProto.hasOwnProperty - -/** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ -const nativeObjectToString = objectProto.toString - -/** Built-in value references. */ -const symToStringTag = Symbol ? Symbol.toStringTag : undefined - -/** - * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the raw `toStringTag`. - */ -function getRawTag(value) { - const isOwn = hasOwnProperty.call(value, symToStringTag) - const tag = value[symToStringTag] - let unmasked = false - - try { - value[symToStringTag] = undefined - unmasked = true - } catch (e) {} - - const result = nativeObjectToString.call(value) - if (unmasked) { - if (isOwn) { - value[symToStringTag] = tag - } else { - delete value[symToStringTag] - } - } - return result -} - -export default getRawTag diff --git a/.internal/objectToString.js b/.internal/objectToString.js deleted file mode 100644 index c10d12d7a..000000000 --- a/.internal/objectToString.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ -const nativeObjectToString = Object.prototype.toString - -/** - * Converts `value` to a string using `Object.prototype.toString`. - * - * @private - * @param {*} value The value to convert. - * @returns {string} Returns the converted string. - */ -function objectToString(value) { - return nativeObjectToString.call(value) -} - -export default objectToString