[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
[79a0317] | 3 | /** @type {import('./shams')} */
|
---|
[d565449] | 4 | /* eslint complexity: [2, 18], max-statements: [2, 33] */
|
---|
| 5 | module.exports = function hasSymbols() {
|
---|
| 6 | if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
|
---|
| 7 | if (typeof Symbol.iterator === 'symbol') { return true; }
|
---|
| 8 |
|
---|
[79a0317] | 9 | /** @type {{ [k in symbol]?: unknown }} */
|
---|
[d565449] | 10 | var obj = {};
|
---|
| 11 | var sym = Symbol('test');
|
---|
| 12 | var symObj = Object(sym);
|
---|
| 13 | if (typeof sym === 'string') { return false; }
|
---|
| 14 |
|
---|
| 15 | if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }
|
---|
| 16 | if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }
|
---|
| 17 |
|
---|
| 18 | // temp disabled per https://github.com/ljharb/object.assign/issues/17
|
---|
| 19 | // if (sym instanceof Symbol) { return false; }
|
---|
| 20 | // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
|
---|
| 21 | // if (!(symObj instanceof Symbol)) { return false; }
|
---|
| 22 |
|
---|
| 23 | // if (typeof Symbol.prototype.toString !== 'function') { return false; }
|
---|
| 24 | // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }
|
---|
| 25 |
|
---|
| 26 | var symVal = 42;
|
---|
| 27 | obj[sym] = symVal;
|
---|
[79a0317] | 28 | for (var _ in obj) { return false; } // eslint-disable-line no-restricted-syntax, no-unreachable-loop
|
---|
[d565449] | 29 | if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
|
---|
| 30 |
|
---|
| 31 | if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
|
---|
| 32 |
|
---|
| 33 | var syms = Object.getOwnPropertySymbols(obj);
|
---|
| 34 | if (syms.length !== 1 || syms[0] !== sym) { return false; }
|
---|
| 35 |
|
---|
| 36 | if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
|
---|
| 37 |
|
---|
| 38 | if (typeof Object.getOwnPropertyDescriptor === 'function') {
|
---|
[79a0317] | 39 | // eslint-disable-next-line no-extra-parens
|
---|
| 40 | var descriptor = /** @type {PropertyDescriptor} */ (Object.getOwnPropertyDescriptor(obj, sym));
|
---|
[d565449] | 41 | if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | return true;
|
---|
| 45 | };
|
---|