polyfills.Symbol.meta.json Maven / Gradle / Ivy
The newest version!
{"aliases":["es6"],"browsers":{"ie":"< 13","ie_mob":"*","safari":"<9","chrome":"< 50","firefox":"< 40","ios_saf":"<9","opera":"< 37","samsung_mob":"<5","android":"<5.1","bb":"10 - *"},"dependencies":["Array.prototype.forEach","Array.prototype.filter","Array.prototype.map","Object.create","Object.defineProperty","Object.getOwnPropertyNames","Object.getOwnPropertyDescriptor","Object.keys"],"license":"MIT","spec":"http://www.ecma-international.org/ecma-262/6.0/index.html#sec-symbol-objects","docs":"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol","detectSource":"'Symbol' in this","testSource":"","baseDir":"Symbol","hasTests":true,"testsSource":"/* eslint-env mocha, browser*/\n/* global proclaim, it */\n\nvar arePropertyDescriptorsSupported = function () {\n\tvar obj = {};\n\ttry {\n\t\tObject.defineProperty(obj, 'x', { enumerable: false, value: obj });\n /* eslint-disable no-unused-vars, no-restricted-syntax */\n for (var _ in obj) { return false; }\n /* eslint-enable no-unused-vars, no-restricted-syntax */\n\t\treturn obj.x === obj;\n\t} catch (e) { // this is IE 8.\n\t\treturn false;\n\t}\n};\nvar supportsDescriptors = Object.defineProperty && arePropertyDescriptorsSupported();\n\n// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-symbol-constructor\nit('should throw if being used via `new`', function() {\n\tvar test = function () {\n\t\treturn new Symbol();\n\t};\n\tproclaim.throws(test);\n});\n\nit('should have Symbol as the constructor property', function() {\n\tproclaim.equal(Symbol().constructor, Symbol);\n});\n\nxit('should silently fail when assigning new properties', function (){\n\tvar a = Symbol(\"1\");\n\ta.b = '1';\n\tproclaim.equal(a.b, undefined);\n});\n\n// A tough one right now\nxit('should have Symbol.prototype as the prototype of an instance', function() {\n\tproclaim.equal(Object.getPrototypeOf(Symbol()), Symbol.prototype);\n});\n\nit('should return \"[object Symbol]\" when called with Object.prototype.toString()', function() {\n\tproclaim.equal(Object.prototype.toString.call(Symbol()), '[object Symbol]');\n});\n\nif (supportsDescriptors) {\n\tit('should silently fail when overwriting properties', function() {\n\t\tvar sym = Symbol(\"2\");\n\t\tsym.toString = 0;\n\t\tproclaim.isInstanceOf(sym.toString, Function);\n\t\tsym.valueOf = 0;\n\t\tproclaim.isInstanceOf(sym.valueOf, Function);\n\t});\n}\n\nit('should create unique symbols', function() {\n\tproclaim.notEqual(Symbol(\"3\"), Symbol(\"3\"));\n});\n\nit('has for, and keyFor static methods', function() {\n\tproclaim.isInstanceOf(Symbol[\"for\"], Function);\n\tproclaim.isInstanceOf(Symbol.keyFor, Function);\n});\n\nit('Symbol.keyFor should throw if not given a symbol', function() {\n\tvar stringKeyFor = function() {\n\t\treturn Symbol.keyFor('a');\n\t};\n\tvar numberKeyFor = function() {\n\t\treturn Symbol.keyFor(1);\n\t};\n\tvar arrayKeyFor = function() {\n\t\treturn Symbol.keyFor([]);\n\t};\n\tvar objectKeyFor = function() {\n\t\treturn Symbol.keyFor({});\n\t};\n\tvar boolKeyFor = function() {\n\t\treturn Symbol.keyFor(true);\n\t};\n\tvar undefinedKeyFor = function() {\n\t\treturn Symbol.keyFor(undefined);\n\t};\n\tvar symbolKeyFor = function() {\n\t\treturn Symbol.keyFor(Symbol(\"4\"));\n\t};\n\n\tproclaim.throws(stringKeyFor);\n\tproclaim.throws(numberKeyFor);\n\tproclaim.throws(arrayKeyFor);\n\tproclaim.throws(objectKeyFor);\n\tproclaim.throws(boolKeyFor);\n\tproclaim.throws(undefinedKeyFor);\n\tproclaim.doesNotThrow(symbolKeyFor);\n});\n\nxit('Symbol.keyFor should return undefined if can not find symbol in global registry', function() {\n\tproclaim.equal(Symbol.keyFor(Symbol(\"5\")), undefined);\n});\n\nxit('Symbol() should not add the symbol to the global registry', function() {\n\tvar sym = Symbol(\"6\");\n\tproclaim.equal(Symbol.keyFor(sym), undefined);\n});\n\nit('Symbol[\"for\"] should create new symbol if can not find symbol in global registry', function() {\n\tvar sym1 = Symbol(\"7\");\n\tvar sym2 = Symbol[\"for\"](\"7\");\n\tproclaim.notEqual(sym1, sym2);\n});\n\nit('Symbol[\"for\"] should return symbol if can find symbol in global registry', function() {\n\tvar sym = Symbol[\"for\"](\"8\");\n\tproclaim.equal(sym, Symbol[\"for\"](\"8\"));\n});\n\nit('Symbol.keyFor should return key of symbol if can find symbol in global registry', function() {\n\tvar key = \"9\";\n\tvar sym = Symbol[\"for\"](key);\n\tproclaim.equal(Symbol.keyFor(sym), key);\n});\n\nit('has toString and valueOf instance methods', function() {\n\tproclaim.isInstanceOf(Symbol.prototype['toString'], Function);\n\tproclaim.isInstanceOf(Symbol.prototype['valueOf'], Function);\n});\n\nif (supportsDescriptors) {\n\t// https://kangax.github.io/compat-table/es6/#Symbol_symbol_keys_are_hidden_to_pre-ES6_code\n\tit('should make symbols non-enumerable', function() {\n\t\tvar object = {};\n\t\tvar symbol = Symbol();\n\t\tobject[symbol] = 1;\n\n\t\tfor (var x in object){}\n\t\tvar passed = !x;\n\n\t\tproclaim.equal(passed, true);\n\t\tproclaim.equal(Object.keys(object).length, 0);\n\t\tproclaim.equal(Object.getOwnPropertyNames(object).length, 0);\n\t});\n}\n\n// Not really possible on a polyfill\nxit('should perform correctly with toString operations', function() {\n\tproclaim.equal(String(Symbol('10')), 'Symbol(10)');\n\tproclaim.equal(Symbol('10').toString(), 'Symbol(10)');\n\tproclaim.equal(Object(Symbol('10')).toString(), 'Symbol(10)');\n\tproclaim.equal(Symbol.prototype.toString.call(Symbol('10')), 'Symbol(10)');\n});\n\n// Not really possible on a polyfill\nxit('should not allow implicit string coercion', function() {\n\tvar implicitStringCoercion = function() {\n\t\treturn Symbol('10') + '';\n\t};\n\tproclaim.throws(implicitStringCoercion);\n});\n\nit('should create Object without symbols', function () {\n\tvar Obj = function () {};\n\tvar obj = Object.create(Obj.prototype);\n\tproclaim.equal(obj instanceof Obj, true);\n});\n\nit('should create Object without symbols, second argument undefined', function () {\n\tvar Obj = function () {};\n\tvar obj = Object.create(Obj.prototype, undefined);\n\tproclaim.equal(obj instanceof Obj, true);\n});\n\nit('does not break when an iframe is added', function () {\n\tvar div = document.createElement('div');\n\tdiv.innerHTML = '';\n\tdocument.body.appendChild(div);\n\tsetTimeout(function () {\n\t\tdocument.body.removeChild(div);\n\t}, 0);\n\tproclaim.equal(Object.prototype.toString.call(Object.getOwnPropertyNames(window)) === '[object Array]', true);\n});"}