94bab4d9ebe399a91675e3e2dd7cb1c961a958430fcdb49580d9600b85f19e87ccf6a94f78ca7797fc6c7e95b6c7e69fa0750d3ab52f44a1213faf74831eb4 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import DataView from './_DataView.js';
  2. import Map from './_Map.js';
  3. import Promise from './_Promise.js';
  4. import Set from './_Set.js';
  5. import WeakMap from './_WeakMap.js';
  6. import baseGetTag from './_baseGetTag.js';
  7. import toSource from './_toSource.js';
  8. /** `Object#toString` result references. */
  9. var mapTag = '[object Map]',
  10. objectTag = '[object Object]',
  11. promiseTag = '[object Promise]',
  12. setTag = '[object Set]',
  13. weakMapTag = '[object WeakMap]';
  14. var dataViewTag = '[object DataView]';
  15. /** Used to detect maps, sets, and weakmaps. */
  16. var dataViewCtorString = toSource(DataView),
  17. mapCtorString = toSource(Map),
  18. promiseCtorString = toSource(Promise),
  19. setCtorString = toSource(Set),
  20. weakMapCtorString = toSource(WeakMap);
  21. /**
  22. * Gets the `toStringTag` of `value`.
  23. *
  24. * @private
  25. * @param {*} value The value to query.
  26. * @returns {string} Returns the `toStringTag`.
  27. */
  28. var getTag = baseGetTag;
  29. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  30. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  31. (Map && getTag(new Map) != mapTag) ||
  32. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  33. (Set && getTag(new Set) != setTag) ||
  34. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  35. getTag = function(value) {
  36. var result = baseGetTag(value),
  37. Ctor = result == objectTag ? value.constructor : undefined,
  38. ctorString = Ctor ? toSource(Ctor) : '';
  39. if (ctorString) {
  40. switch (ctorString) {
  41. case dataViewCtorString: return dataViewTag;
  42. case mapCtorString: return mapTag;
  43. case promiseCtorString: return promiseTag;
  44. case setCtorString: return setTag;
  45. case weakMapCtorString: return weakMapTag;
  46. }
  47. }
  48. return result;
  49. };
  50. }
  51. export default getTag;