_getRawTag.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var Symbol = require('./_Symbol');
  2. /** Used for built-in method references. */
  3. var objectProto = Object.prototype;
  4. /** Used to check objects for own properties. */
  5. var hasOwnProperty = objectProto.hasOwnProperty;
  6. /**
  7. * Used to resolve the
  8. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  9. * of values.
  10. */
  11. var nativeObjectToString = objectProto.toString;
  12. /** Built-in value references. */
  13. var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  14. /**
  15. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  16. *
  17. * @private
  18. * @param {*} value The value to query.
  19. * @returns {string} Returns the raw `toStringTag`.
  20. */
  21. function getRawTag(value) {
  22. var isOwn = hasOwnProperty.call(value, symToStringTag),
  23. tag = value[symToStringTag];
  24. try {
  25. value[symToStringTag] = undefined;
  26. var unmasked = true;
  27. } catch (e) {}
  28. var result = nativeObjectToString.call(value);
  29. if (unmasked) {
  30. if (isOwn) {
  31. value[symToStringTag] = tag;
  32. } else {
  33. delete value[symToStringTag];
  34. }
  35. }
  36. return result;
  37. }
  38. module.exports = getRawTag;