-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymbols.js
More file actions
25 lines (20 loc) · 657 Bytes
/
symbols.js
File metadata and controls
25 lines (20 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { polyfillMethod } from './utils.js';
if ('Symbol' in globalThis) {
const known = new Set(
Reflect.ownKeys(Symbol)
.filter(item => typeof Symbol[item] === 'symbol')
.map(key => Symbol[key])
);
if (typeof Symbol.toStringTag === 'undefined') {
Symbol.toStringTag = Symbol('Symbol.toStringTag');
}
if (typeof Symbol.iterator === 'undefined') {
Symbol.iterator = Symbol('Symbol.iterator');
}
polyfillMethod(Symbol, 'isRegistered', function(symbol) {
return typeof symbol === 'symbol' && typeof Symbol.keyFor(symbol) === 'string';
});
polyfillMethod(Symbol, 'isWellKnown', function(symbol) {
return known.has(symbol);
});
}