1
|
'use strict';
|
2
|
|
3
|
var keys = require('object-keys');
|
4
|
|
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
|
|
9
|
var obj = {};
|
10
|
var sym = Symbol('test');
|
11
|
var symObj = Object(sym);
|
12
|
if (typeof sym === 'string') { return false; }
|
13
|
|
14
|
if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }
|
15
|
if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }
|
16
|
|
17
|
// temp disabled per https://github.com/ljharb/object.assign/issues/17
|
18
|
// if (sym instanceof Symbol) { return false; }
|
19
|
// temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
|
20
|
// if (!(symObj instanceof Symbol)) { return false; }
|
21
|
|
22
|
var symVal = 42;
|
23
|
obj[sym] = symVal;
|
24
|
for (sym in obj) { return false; }
|
25
|
if (keys(obj).length !== 0) { return false; }
|
26
|
if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
|
27
|
|
28
|
if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
|
29
|
|
30
|
var syms = Object.getOwnPropertySymbols(obj);
|
31
|
if (syms.length !== 1 || syms[0] !== sym) { return false; }
|
32
|
|
33
|
if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
|
34
|
|
35
|
if (typeof Object.getOwnPropertyDescriptor === 'function') {
|
36
|
var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
|
37
|
if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
|
38
|
}
|
39
|
|
40
|
return true;
|
41
|
};
|