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:
1.1 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var $WeakMap = typeof WeakMap === 'function' && WeakMap.prototype ? WeakMap : null;
|
---|
4 | var $WeakSet = typeof WeakSet === 'function' && WeakSet.prototype ? WeakSet : null;
|
---|
5 |
|
---|
6 | var exported;
|
---|
7 |
|
---|
8 | if (!$WeakMap) {
|
---|
9 | /** @type {import('.')} */
|
---|
10 | // eslint-disable-next-line no-unused-vars
|
---|
11 | exported = function isWeakMap(x) {
|
---|
12 | // `WeakMap` is not present in this environment.
|
---|
13 | return false;
|
---|
14 | };
|
---|
15 | }
|
---|
16 |
|
---|
17 | var $mapHas = $WeakMap ? $WeakMap.prototype.has : null;
|
---|
18 | var $setHas = $WeakSet ? $WeakSet.prototype.has : null;
|
---|
19 | if (!exported && !$mapHas) {
|
---|
20 | /** @type {import('.')} */
|
---|
21 | // eslint-disable-next-line no-unused-vars
|
---|
22 | exported = function isWeakMap(x) {
|
---|
23 | // `WeakMap` does not have a `has` method
|
---|
24 | return false;
|
---|
25 | };
|
---|
26 | }
|
---|
27 |
|
---|
28 | /** @type {import('.')} */
|
---|
29 | module.exports = exported || function isWeakMap(x) {
|
---|
30 | if (!x || typeof x !== 'object') {
|
---|
31 | return false;
|
---|
32 | }
|
---|
33 | try {
|
---|
34 | $mapHas.call(x, $mapHas);
|
---|
35 | if ($setHas) {
|
---|
36 | try {
|
---|
37 | $setHas.call(x, $setHas);
|
---|
38 | } catch (e) {
|
---|
39 | return true;
|
---|
40 | }
|
---|
41 | }
|
---|
42 | // @ts-expect-error TS can't figure out that $WeakMap is always truthy here
|
---|
43 | return x instanceof $WeakMap; // core-js workaround, pre-v3
|
---|
44 | } catch (e) {}
|
---|
45 | return false;
|
---|
46 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.