main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
936 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 | var callBound = require('call-bind/callBound');
|
---|
5 |
|
---|
6 | var $WeakSet = GetIntrinsic('%WeakSet%', true);
|
---|
7 |
|
---|
8 | var $setHas = callBound('WeakSet.prototype.has', true);
|
---|
9 |
|
---|
10 | if ($setHas) {
|
---|
11 | var $mapHas = callBound('WeakMap.prototype.has', true);
|
---|
12 |
|
---|
13 | /** @type {import('.')} */
|
---|
14 | module.exports = function isWeakSet(x) {
|
---|
15 | if (!x || typeof x !== 'object') {
|
---|
16 | return false;
|
---|
17 | }
|
---|
18 | try {
|
---|
19 | $setHas(x, $setHas);
|
---|
20 | if ($mapHas) {
|
---|
21 | try {
|
---|
22 | $mapHas(x, $mapHas);
|
---|
23 | } catch (e) {
|
---|
24 | return true;
|
---|
25 | }
|
---|
26 | }
|
---|
27 | // @ts-expect-error TS can't figure out that $WeakSet is always truthy here
|
---|
28 | return x instanceof $WeakSet; // core-js workaround, pre-v3
|
---|
29 | } catch (e) {}
|
---|
30 | return false;
|
---|
31 | };
|
---|
32 | } else {
|
---|
33 | /** @type {import('.')} */
|
---|
34 | // eslint-disable-next-line no-unused-vars
|
---|
35 | module.exports = function isWeakSet(x) {
|
---|
36 | // `WeakSet` does not exist, or does not have a `has` method
|
---|
37 | return false;
|
---|
38 | };
|
---|
39 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.