main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
---|
[79a0317] | 4 | var callBound = require('call-bound');
|
---|
[d565449] | 5 |
|
---|
| 6 | var $WeakSet = GetIntrinsic('%WeakSet%', true);
|
---|
| 7 |
|
---|
[79a0317] | 8 | /** @type {undefined | (<V>(thisArg: Set<V>, value: V) => boolean)} */
|
---|
[d565449] | 9 | var $setHas = callBound('WeakSet.prototype.has', true);
|
---|
| 10 |
|
---|
| 11 | if ($setHas) {
|
---|
[79a0317] | 12 | /** @type {undefined | (<K extends object, V>(thisArg: WeakMap<K, V>, key: K) => boolean)} */
|
---|
[d565449] | 13 | var $mapHas = callBound('WeakMap.prototype.has', true);
|
---|
| 14 |
|
---|
| 15 | /** @type {import('.')} */
|
---|
| 16 | module.exports = function isWeakSet(x) {
|
---|
| 17 | if (!x || typeof x !== 'object') {
|
---|
| 18 | return false;
|
---|
| 19 | }
|
---|
| 20 | try {
|
---|
[79a0317] | 21 | // @ts-expect-error TS can't figure out that $setHas is always truthy here
|
---|
[d565449] | 22 | $setHas(x, $setHas);
|
---|
| 23 | if ($mapHas) {
|
---|
| 24 | try {
|
---|
[79a0317] | 25 | // @ts-expect-error this indeed might not be a weak collection
|
---|
[d565449] | 26 | $mapHas(x, $mapHas);
|
---|
| 27 | } catch (e) {
|
---|
| 28 | return true;
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 | // @ts-expect-error TS can't figure out that $WeakSet is always truthy here
|
---|
| 32 | return x instanceof $WeakSet; // core-js workaround, pre-v3
|
---|
| 33 | } catch (e) {}
|
---|
| 34 | return false;
|
---|
| 35 | };
|
---|
| 36 | } else {
|
---|
| 37 | /** @type {import('.')} */
|
---|
[79a0317] | 38 | // @ts-expect-error
|
---|
| 39 | module.exports = function isWeakSet(x) { // eslint-disable-line no-unused-vars
|
---|
[d565449] | 40 | // `WeakSet` does not exist, or does not have a `has` method
|
---|
| 41 | return false;
|
---|
| 42 | };
|
---|
| 43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.