index.js 996 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. var $WeakMap = typeof WeakMap === 'function' && WeakMap.prototype ? WeakMap : null;
  3. var $WeakSet = typeof WeakSet === 'function' && WeakSet.prototype ? WeakSet : null;
  4. var exported;
  5. if (!$WeakMap) {
  6. // eslint-disable-next-line no-unused-vars
  7. exported = function isWeakMap(x) {
  8. // `WeakMap` is not present in this environment.
  9. return false;
  10. };
  11. }
  12. var $mapHas = $WeakMap ? $WeakMap.prototype.has : null;
  13. var $setHas = $WeakSet ? $WeakSet.prototype.has : null;
  14. if (!exported && !$mapHas) {
  15. // eslint-disable-next-line no-unused-vars
  16. exported = function isWeakMap(x) {
  17. // `WeakMap` does not have a `has` method
  18. return false;
  19. };
  20. }
  21. module.exports = exported || function isWeakMap(x) {
  22. if (!x || typeof x !== 'object') {
  23. return false;
  24. }
  25. try {
  26. $mapHas.call(x, $mapHas);
  27. if ($setHas) {
  28. try {
  29. $setHas.call(x, $setHas);
  30. } catch (e) {
  31. return true;
  32. }
  33. }
  34. return x instanceof $WeakMap; // core-js workaround, pre-v3
  35. } catch (e) {}
  36. return false;
  37. };