Sha256: a717ad59c4c930631c0dc207bea045ebd4f4902a19c46f228547ef619ee56177

Contents?: true

Size: 1.58 KB

Versions: 60

Compression:

Stored size: 1.58 KB

Contents

'use strict';

var keys = require('object-keys');

module.exports = function hasSymbols() {
	if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
	if (typeof Symbol.iterator === 'symbol') { return true; }

	var obj = {};
	var sym = Symbol('test');
	var symObj = Object(sym);
	if (typeof sym === 'string') { return false; }

	if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }
	if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }

	/*
	 * temp disabled per https://github.com/ljharb/object.assign/issues/17
	 * if (sym instanceof Symbol) { return false; }
	 * temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
	 * if (!(symObj instanceof Symbol)) { return false; }
	 */

	var symVal = 42;
	obj[sym] = symVal;
	for (sym in obj) { return false; } // eslint-disable-line no-unreachable-loop
	if (keys(obj).length !== 0) { return false; }
	if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }

	if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }

	var syms = Object.getOwnPropertySymbols(obj);
	if (syms.length !== 1 || syms[0] !== sym) { return false; }

	if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }

	if (typeof Object.getOwnPropertyDescriptor === 'function') {
		var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
		if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
	}

	return true;
};

Version data entries

60 entries across 59 versions & 5 rubygems

Version Path
immosquare-cleaner-0.1.17 node_modules/object.assign/hasSymbols.js
immosquare-cleaner-0.1.16 node_modules/object.assign/hasSymbols.js
immosquare-cleaner-0.1.14 node_modules/object.assign/hasSymbols.js
immosquare-cleaner-0.1.13 node_modules/object.assign/hasSymbols.js
immosquare-cleaner-0.1.12 node_modules/object.assign/hasSymbols.js
immosquare-cleaner-0.1.11 node_modules/object.assign/hasSymbols.js
immosquare-cleaner-0.1.10 node_modules/object.assign/hasSymbols.js
immosquare-cleaner-0.1.9 node_modules/object.assign/hasSymbols.js
immosquare-cleaner-0.1.8 node_modules/object.assign/hasSymbols.js
immosquare-cleaner-0.1.7 node_modules/object.assign/hasSymbols.js
immosquare-cleaner-0.1.6 node_modules/object.assign/hasSymbols.js
decidim-0.26.8 packages/eslint-config/node_modules/object.assign/hasSymbols.js
tang-0.2.1 spec/tang_app/node_modules/object.assign/hasSymbols.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/object.assign/hasSymbols.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/object.assign/hasSymbols.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/object.assign/hasSymbols.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/object.assign/hasSymbols.js
tang-0.2.0 spec/tang_app/node_modules/object.assign/hasSymbols.js
tang-0.1.0 spec/tang_app/node_modules/object.assign/hasSymbols.js
tang-0.0.9 spec/tang_app/node_modules/object.assign/hasSymbols.js