source: trip-planner-front/node_modules/object.assign/hasSymbols.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[6a3a178]1'use strict';
2
3var keys = require('object-keys');
4
5module.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 /*
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
24 var symVal = 42;
25 obj[sym] = symVal;
26 for (sym in obj) { return false; } // eslint-disable-line no-unreachable-loop
27 if (keys(obj).length !== 0) { return false; }
28 if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
29
30 if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
31
32 var syms = Object.getOwnPropertySymbols(obj);
33 if (syms.length !== 1 || syms[0] !== sym) { return false; }
34
35 if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
36
37 if (typeof Object.getOwnPropertyDescriptor === 'function') {
38 var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
39 if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
40 }
41
42 return true;
43};
Note: See TracBrowser for help on using the repository browser.