index.js 801 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var callBound = require('call-bind/callBound');
  4. var $WeakSet = GetIntrinsic('%WeakSet%', true);
  5. var $setHas = callBound('WeakSet.prototype.has', true);
  6. if ($setHas) {
  7. var $mapHas = callBound('WeakMap.prototype.has', true);
  8. module.exports = function isWeakSet(x) {
  9. if (!x || typeof x !== 'object') {
  10. return false;
  11. }
  12. try {
  13. $setHas(x, $setHas);
  14. if ($mapHas) {
  15. try {
  16. $mapHas(x, $mapHas);
  17. } catch (e) {
  18. return true;
  19. }
  20. }
  21. return x instanceof $WeakSet; // core-js workaround, pre-v3
  22. } catch (e) {}
  23. return false;
  24. };
  25. } else {
  26. // eslint-disable-next-line no-unused-vars
  27. module.exports = function isWeakSet(x) {
  28. // `WeakSet` does not exist, or does not have a `has` method
  29. return false;
  30. };
  31. }