From 36f0ad2def251eef1190ba1fd52ca2ad0b5f0e97 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Mon, 22 May 2023 08:48:52 +0700 Subject: [PATCH] rename `Symbol` predicates https://github.com/babel/proposals/issues/88#issuecomment-1548219580 --- CHANGELOG.md | 4 +++ README.md | 22 ++++++------ packages/core-js-compat/src/data.mjs | 7 ++++ .../src/modules-by-versions.mjs | 4 +++ packages/core-js/full/symbol/index.js | 10 +++--- .../full/symbol/is-registered-symbol.js | 5 +++ .../full/symbol/is-well-known-symbol.js | 5 +++ .../core-js/internals/symbol-is-registered.js | 16 +++++++++ .../core-js/internals/symbol-is-well-known.js | 33 +++++++++++++++++ .../esnext.symbol.is-registered-symbol.js | 8 +++++ .../modules/esnext.symbol.is-registered.js | 19 +++------- .../esnext.symbol.is-well-known-symbol.js | 9 +++++ .../modules/esnext.symbol.is-well-known.js | 35 +++---------------- .../core-js/proposals/symbol-predicates-v2.js | 3 ++ packages/core-js/stage/2.js | 3 +- tests/compat-data/tests-coverage.mjs | 2 ++ tests/compat/tests.js | 8 ++--- tests/entries/unit.mjs | 2 ++ .../esnext.symbol.is-registered-symbol.js | 20 +++++++++++ .../esnext.symbol.is-registered.js | 2 +- .../esnext.symbol.is-well-known-symbol.js | 22 ++++++++++++ .../esnext.symbol.is-well-known.js | 2 +- .../esnext.symbol.is-registered-symbol.js | 20 +++++++++++ .../unit-pure/esnext.symbol.is-registered.js | 2 +- .../esnext.symbol.is-well-known-symbol.js | 22 ++++++++++++ .../unit-pure/esnext.symbol.is-well-known.js | 2 +- 26 files changed, 217 insertions(+), 70 deletions(-) create mode 100644 packages/core-js/full/symbol/is-registered-symbol.js create mode 100644 packages/core-js/full/symbol/is-well-known-symbol.js create mode 100644 packages/core-js/internals/symbol-is-registered.js create mode 100644 packages/core-js/internals/symbol-is-well-known.js create mode 100644 packages/core-js/modules/esnext.symbol.is-registered-symbol.js create mode 100644 packages/core-js/modules/esnext.symbol.is-well-known-symbol.js create mode 100644 packages/core-js/proposals/symbol-predicates-v2.js create mode 100644 tests/unit-global/esnext.symbol.is-registered-symbol.js create mode 100644 tests/unit-global/esnext.symbol.is-well-known-symbol.js create mode 100644 tests/unit-pure/esnext.symbol.is-registered-symbol.js create mode 100644 tests/unit-pure/esnext.symbol.is-well-known-symbol.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 37ce7834bdb8..50c0764e69f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog ##### Unreleased +- [`Symbol` predicates stage 2 proposal](https://github.com/tc39/proposal-symbol-predicates): + - The methods renamed to end with `Symbol`, [May 2023 TC39 meeting](https://github.com/babel/proposals/issues/88#issuecomment-1548219580): + - `Symbol.isRegistered` -> `Symbol.isRegisteredSymbol` + - `Symbol.isWellKnown` -> `Symbol.isWellKnownSymbol` - Fixed some cases of increasing buffer size in `ArrayBuffer.prototype.{ transfer, transferToFixedLength }` polyfills - Compat data improvements: - `Set.prototype.difference` that was missed in Bun because of [a bug](https://github.com/oven-sh/bun/issues/2309) added in 0.6.0 diff --git a/README.md b/README.md index e441b21211c6..e620d7bde905 100644 --- a/README.md +++ b/README.md @@ -2594,27 +2594,27 @@ core-js(-pure)/full/async-disposable-stack core-js(-pure)/full/async-iterator/async-dispose ``` ##### [`Symbol` predicates](https://github.com/tc39/proposal-symbol-predicates)[⬆](#index) -Modules [`esnext.symbol.is-registered`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.is-registered.js), [`esnext.symbol.is-well-known`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.is-well-known.js). +Modules [`esnext.symbol.is-registered-symbol`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.is-registered-symbol.js), [`esnext.symbol.is-well-known-symbol`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.is-well-known-symbol.js). ```js class Symbol { - static isRegistered(value: any): boolean; - static isWellKnown(value: any): boolean; + static isRegisteredSymbol(value: any): boolean; + static isWellKnownSymbol(value: any): boolean; } ``` ``` [*CommonJS entry points:*](#commonjs-api) ```js -core-js/proposals/symbol-predicates -core-js(-pure)/full/symbol/is-registered -core-js(-pure)/full/symbol/is-well-known +core-js/proposals/symbol-predicates-v2 +core-js(-pure)/full/symbol/is-registered-symbol +core-js(-pure)/full/symbol/is-well-known-symbol ``` -[*Example*](https://tinyurl.com/2cuwpu8d): +[*Example*](https://tinyurl.com/2oqoaq7t): ```js -Symbol.isRegistered(Symbol.for('key')); // => true -Symbol.isRegistered(Symbol('key')); // => false +Symbol.isRegisteredSymbol(Symbol.for('key')); // => true +Symbol.isRegisteredSymbol(Symbol('key')); // => false -Symbol.isWellKnown(Symbol.iterator); // => true -Symbol.isWellKnown(Symbol('key')); // => false +Symbol.isWellKnownSymbol(Symbol.iterator); // => true +Symbol.isWellKnownSymbol(Symbol('key')); // => false ``` ##### [`Symbol.metadata` for decorators metadata proposal](https://github.com/tc39/proposal-decorator-metadata)[⬆](#index) Module [`esnext.symbol.metadata`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.metadata.js). diff --git a/packages/core-js-compat/src/data.mjs b/packages/core-js-compat/src/data.mjs index 0009f32b953b..18469c02fd53 100644 --- a/packages/core-js-compat/src/data.mjs +++ b/packages/core-js-compat/src/data.mjs @@ -2234,8 +2234,15 @@ export const data = { }, 'esnext.symbol.dispose': { }, + 'esnext.symbol.is-registered-symbol': { + }, + // TODO: Remove from `core-js@4` 'esnext.symbol.is-registered': { }, + // We should patch it for newly added well-known symbols. If it's not required, this module just will not be injected + 'esnext.symbol.is-well-known-symbol': { + }, + // TODO: Remove from `core-js@4` 'esnext.symbol.is-well-known': { }, 'esnext.symbol.matcher': { diff --git a/packages/core-js-compat/src/modules-by-versions.mjs b/packages/core-js-compat/src/modules-by-versions.mjs index 1672e28c9382..b35a5d8a217b 100644 --- a/packages/core-js-compat/src/modules-by-versions.mjs +++ b/packages/core-js-compat/src/modules-by-versions.mjs @@ -202,4 +202,8 @@ export default { '3.30': [ 'web.url.can-parse', ], + 3.31: [ + 'esnext.symbol.is-registered-symbol', + 'esnext.symbol.is-well-known-symbol', + ], }; diff --git a/packages/core-js/full/symbol/index.js b/packages/core-js/full/symbol/index.js index e0e0e1231d8e..973a30f4db12 100644 --- a/packages/core-js/full/symbol/index.js +++ b/packages/core-js/full/symbol/index.js @@ -1,12 +1,14 @@ var parent = require('../../actual/symbol'); require('../../modules/esnext.symbol.async-dispose'); -require('../../modules/esnext.symbol.is-registered'); -require('../../modules/esnext.symbol.is-well-known'); +require('../../modules/esnext.symbol.is-registered-symbol'); +require('../../modules/esnext.symbol.is-well-known-symbol'); require('../../modules/esnext.symbol.matcher'); -require('../../modules/esnext.symbol.metadata-key'); +require('../../modules/esnext.symbol.metadata'); require('../../modules/esnext.symbol.observable'); // TODO: Remove from `core-js@4` -require('../../modules/esnext.symbol.metadata'); +require('../../modules/esnext.symbol.is-registered'); +require('../../modules/esnext.symbol.is-well-known'); +require('../../modules/esnext.symbol.metadata-key'); require('../../modules/esnext.symbol.pattern-match'); require('../../modules/esnext.symbol.replace-all'); diff --git a/packages/core-js/full/symbol/is-registered-symbol.js b/packages/core-js/full/symbol/is-registered-symbol.js new file mode 100644 index 000000000000..abd9f7b3f0a5 --- /dev/null +++ b/packages/core-js/full/symbol/is-registered-symbol.js @@ -0,0 +1,5 @@ +require('../../modules/es.symbol'); +require('../../modules/esnext.symbol.is-registered-symbol'); +var path = require('../../internals/path'); + +module.exports = path.Symbol.isRegisteredSymbol; diff --git a/packages/core-js/full/symbol/is-well-known-symbol.js b/packages/core-js/full/symbol/is-well-known-symbol.js new file mode 100644 index 000000000000..79941964efbc --- /dev/null +++ b/packages/core-js/full/symbol/is-well-known-symbol.js @@ -0,0 +1,5 @@ +require('../../modules/es.symbol'); +require('../../modules/esnext.symbol.is-well-known-symbol'); +var path = require('../../internals/path'); + +module.exports = path.Symbol.isWellKnownSymbol; diff --git a/packages/core-js/internals/symbol-is-registered.js b/packages/core-js/internals/symbol-is-registered.js new file mode 100644 index 000000000000..583991ccf96b --- /dev/null +++ b/packages/core-js/internals/symbol-is-registered.js @@ -0,0 +1,16 @@ +var getBuiltIn = require('../internals/get-built-in'); +var uncurryThis = require('../internals/function-uncurry-this'); + +var Symbol = getBuiltIn('Symbol'); +var keyFor = Symbol.keyFor; +var thisSymbolValue = uncurryThis(Symbol.prototype.valueOf); + +// `Symbol.isRegisteredSymbol` method +// https://tc39.es/proposal-symbol-predicates/#sec-symbol-isregisteredsymbol +module.exports = Symbol.isRegisteredSymbol || function isRegisteredSymbol(value) { + try { + return keyFor(thisSymbolValue(value)) !== undefined; + } catch (error) { + return false; + } +}; diff --git a/packages/core-js/internals/symbol-is-well-known.js b/packages/core-js/internals/symbol-is-well-known.js new file mode 100644 index 000000000000..9da5673b72ec --- /dev/null +++ b/packages/core-js/internals/symbol-is-well-known.js @@ -0,0 +1,33 @@ +var shared = require('../internals/shared'); +var getBuiltIn = require('../internals/get-built-in'); +var uncurryThis = require('../internals/function-uncurry-this'); +var isSymbol = require('../internals/is-symbol'); +var wellKnownSymbol = require('../internals/well-known-symbol'); + +var Symbol = getBuiltIn('Symbol'); +var $isWellKnownSymbol = Symbol.isWellKnownSymbol; +var getOwnPropertyNames = getBuiltIn('Object', 'getOwnPropertyNames'); +var thisSymbolValue = uncurryThis(Symbol.prototype.valueOf); +var WellKnownSymbolsStore = shared('wks'); + +for (var i = 0, symbolKeys = getOwnPropertyNames(Symbol), symbolKeysLength = symbolKeys.length; i < symbolKeysLength; i++) { + // some old engines throws on access to some keys like `arguments` or `caller` + try { + var symbolKey = symbolKeys[i]; + if (isSymbol(Symbol[symbolKey])) wellKnownSymbol(symbolKey); + } catch (error) { /* empty */ } +} + +// `Symbol.isWellKnownSymbol` method +// https://tc39.es/proposal-symbol-predicates/#sec-symbol-iswellknownsymbol +// We should patch it for newly added well-known symbols. If it's not required, this module just will not be injected +module.exports = function isWellKnownSymbol(value) { + if ($isWellKnownSymbol && $isWellKnownSymbol(value)) return true; + try { + var symbol = thisSymbolValue(value); + for (var j = 0, keys = getOwnPropertyNames(WellKnownSymbolsStore), keysLength = keys.length; j < keysLength; j++) { + if (WellKnownSymbolsStore[keys[j]] == symbol) return true; + } + } catch (error) { /* empty */ } + return false; +}; diff --git a/packages/core-js/modules/esnext.symbol.is-registered-symbol.js b/packages/core-js/modules/esnext.symbol.is-registered-symbol.js new file mode 100644 index 000000000000..b8cae6b8fac5 --- /dev/null +++ b/packages/core-js/modules/esnext.symbol.is-registered-symbol.js @@ -0,0 +1,8 @@ +var $ = require('../internals/export'); +var isRegisteredSymbol = require('../internals/symbol-is-registered'); + +// `Symbol.isRegisteredSymbol` method +// https://tc39.es/proposal-symbol-predicates/#sec-symbol-isregisteredsymbol +$({ target: 'Symbol', stat: true }, { + isRegisteredSymbol: isRegisteredSymbol +}); diff --git a/packages/core-js/modules/esnext.symbol.is-registered.js b/packages/core-js/modules/esnext.symbol.is-registered.js index 0ec2afb33c85..8c28f22a174a 100644 --- a/packages/core-js/modules/esnext.symbol.is-registered.js +++ b/packages/core-js/modules/esnext.symbol.is-registered.js @@ -1,19 +1,8 @@ var $ = require('../internals/export'); -var getBuiltIn = require('../internals/get-built-in'); -var uncurryThis = require('../internals/function-uncurry-this'); - -var Symbol = getBuiltIn('Symbol'); -var keyFor = Symbol.keyFor; -var thisSymbolValue = uncurryThis(Symbol.prototype.valueOf); +var isRegisteredSymbol = require('../internals/symbol-is-registered'); // `Symbol.isRegistered` method -// https://tc39.es/proposal-symbol-predicates/#sec-symbol-isregistered -$({ target: 'Symbol', stat: true }, { - isRegistered: function isRegistered(value) { - try { - return keyFor(thisSymbolValue(value)) !== undefined; - } catch (error) { - return false; - } - } +// obsolete version of https://tc39.es/proposal-symbol-predicates/#sec-symbol-isregisteredsymbol +$({ target: 'Symbol', stat: true, name: 'isRegisteredSymbol' }, { + isRegistered: isRegisteredSymbol }); diff --git a/packages/core-js/modules/esnext.symbol.is-well-known-symbol.js b/packages/core-js/modules/esnext.symbol.is-well-known-symbol.js new file mode 100644 index 000000000000..e31393ff1cb7 --- /dev/null +++ b/packages/core-js/modules/esnext.symbol.is-well-known-symbol.js @@ -0,0 +1,9 @@ +var $ = require('../internals/export'); +var isWellKnownSymbol = require('../internals/symbol-is-well-known'); + +// `Symbol.isWellKnownSymbol` method +// https://tc39.es/proposal-symbol-predicates/#sec-symbol-iswellknownsymbol +// We should patch it for newly added well-known symbols. If it's not required, this module just will not be injected +$({ target: 'Symbol', stat: true, forced: true }, { + isWellKnownSymbol: isWellKnownSymbol +}); diff --git a/packages/core-js/modules/esnext.symbol.is-well-known.js b/packages/core-js/modules/esnext.symbol.is-well-known.js index 929caec0005c..8cfb7f25ae35 100644 --- a/packages/core-js/modules/esnext.symbol.is-well-known.js +++ b/packages/core-js/modules/esnext.symbol.is-well-known.js @@ -1,36 +1,9 @@ var $ = require('../internals/export'); -var shared = require('../internals/shared'); -var getBuiltIn = require('../internals/get-built-in'); -var uncurryThis = require('../internals/function-uncurry-this'); -var isSymbol = require('../internals/is-symbol'); -var wellKnownSymbol = require('../internals/well-known-symbol'); - -var Symbol = getBuiltIn('Symbol'); -var $isWellKnown = Symbol.isWellKnown; -var getOwnPropertyNames = getBuiltIn('Object', 'getOwnPropertyNames'); -var thisSymbolValue = uncurryThis(Symbol.prototype.valueOf); -var WellKnownSymbolsStore = shared('wks'); - -for (var i = 0, symbolKeys = getOwnPropertyNames(Symbol), symbolKeysLength = symbolKeys.length; i < symbolKeysLength; i++) { - // some old engines throws on access to some keys like `arguments` or `caller` - try { - var symbolKey = symbolKeys[i]; - if (isSymbol(Symbol[symbolKey])) wellKnownSymbol(symbolKey); - } catch (error) { /* empty */ } -} +var isWellKnownSymbol = require('../internals/symbol-is-well-known'); // `Symbol.isWellKnown` method -// https://tc39.es/proposal-symbol-predicates/#sec-symbol-iswellknown +// obsolete version of https://tc39.es/proposal-symbol-predicates/#sec-symbol-iswellknownsymbol // We should patch it for newly added well-known symbols. If it's not required, this module just will not be injected -$({ target: 'Symbol', stat: true, forced: true }, { - isWellKnown: function isWellKnown(value) { - if ($isWellKnown && $isWellKnown(value)) return true; - try { - var symbol = thisSymbolValue(value); - for (var j = 0, keys = getOwnPropertyNames(WellKnownSymbolsStore), keysLength = keys.length; j < keysLength; j++) { - if (WellKnownSymbolsStore[keys[j]] == symbol) return true; - } - } catch (error) { /* empty */ } - return false; - } +$({ target: 'Symbol', stat: true, name: 'isWellKnownSymbol', forced: true }, { + isWellKnown: isWellKnownSymbol }); diff --git a/packages/core-js/proposals/symbol-predicates-v2.js b/packages/core-js/proposals/symbol-predicates-v2.js new file mode 100644 index 000000000000..6b9a9961148d --- /dev/null +++ b/packages/core-js/proposals/symbol-predicates-v2.js @@ -0,0 +1,3 @@ +// https://github.com/tc39/proposal-symbol-predicates +require('../modules/esnext.symbol.is-registered-symbol'); +require('../modules/esnext.symbol.is-well-known-symbol'); diff --git a/packages/core-js/stage/2.js b/packages/core-js/stage/2.js index 91a24b5f0d56..1ec6e66a8785 100644 --- a/packages/core-js/stage/2.js +++ b/packages/core-js/stage/2.js @@ -7,13 +7,14 @@ require('../proposals/decorator-metadata-v2'); require('../proposals/iterator-range'); require('../proposals/map-upsert-stage-2'); require('../proposals/string-dedent'); -require('../proposals/symbol-predicates'); +require('../proposals/symbol-predicates-v2'); // TODO: Obsolete versions, remove from `core-js@4` require('../proposals/array-grouping'); require('../proposals/decorators'); require('../proposals/decorator-metadata'); require('../proposals/iterator-helpers'); require('../proposals/set-methods'); +require('../proposals/symbol-predicates'); require('../proposals/using-statement'); module.exports = parent; diff --git a/tests/compat-data/tests-coverage.mjs b/tests/compat-data/tests-coverage.mjs index 272410fb8778..be68873e8953 100644 --- a/tests/compat-data/tests-coverage.mjs +++ b/tests/compat-data/tests-coverage.mjs @@ -56,6 +56,8 @@ const ignore = new Set([ 'esnext.set.symmetric-difference', 'esnext.set.union', 'esnext.string.at', + 'esnext.symbol.is-registered', + 'esnext.symbol.is-well-known', 'esnext.symbol.metadata', 'esnext.symbol.pattern-match', 'esnext.symbol.replace-all', diff --git a/tests/compat/tests.js b/tests/compat/tests.js index c224c6827f0f..8e3ef28638f7 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -1769,11 +1769,11 @@ GLOBAL.tests = { 'esnext.symbol.dispose': function () { return Symbol.dispose; }, - 'esnext.symbol.is-registered': function () { - return Symbol.isRegistered; + 'esnext.symbol.is-registered-symbol': function () { + return Symbol.isRegisteredSymbol; }, - 'esnext.symbol.is-well-known': function () { - return Symbol.isWellKnown; + 'esnext.symbol.is-well-known-symbol': function () { + return Symbol.isWellKnownSymbol; }, 'esnext.symbol.matcher': function () { return Symbol.matcher; diff --git a/tests/entries/unit.mjs b/tests/entries/unit.mjs index b11826d9fecf..74e2d51f7e2b 100644 --- a/tests/entries/unit.mjs +++ b/tests/entries/unit.mjs @@ -823,6 +823,8 @@ for (PATH of ['core-js-pure', 'core-js']) { ` === 'a1b'); ok('next' in load(NS, 'string/code-points')('a')); ok('next' in load(NS, 'string/virtual/code-points').call('a')); + ok(load(NS, 'symbol/is-registered-symbol')(1) === false); + ok(load(NS, 'symbol/is-well-known-symbol')(1) === false); ok(load(NS, 'symbol/is-registered')(1) === false); ok(load(NS, 'symbol/is-well-known')(1) === false); ok(load(NS, 'symbol/matcher')); diff --git a/tests/unit-global/esnext.symbol.is-registered-symbol.js b/tests/unit-global/esnext.symbol.is-registered-symbol.js new file mode 100644 index 000000000000..787e656d7db2 --- /dev/null +++ b/tests/unit-global/esnext.symbol.is-registered-symbol.js @@ -0,0 +1,20 @@ +QUnit.test('Symbol.isRegisteredSymbol', assert => { + const { isRegisteredSymbol } = Symbol; + assert.isFunction(isRegisteredSymbol, 'Symbol.isRegisteredSymbol is function'); + assert.nonEnumerable(Symbol, 'isRegisteredSymbol'); + assert.arity(isRegisteredSymbol, 1, 'Symbol.isRegisteredSymbol arity is 1'); + assert.name(isRegisteredSymbol, 'isRegisteredSymbol', 'Symbol.isRegisteredSymbol.name is "isRegisteredSymbol"'); + assert.looksNative(isRegisteredSymbol, 'isRegisteredSymbol looks like native'); + + assert.true(isRegisteredSymbol(Symbol.for('foo')), 'registered-1'); + assert.true(isRegisteredSymbol(Object(Symbol.for('foo'))), 'registered-2'); + assert.false(isRegisteredSymbol(Symbol()), 'non-registered'); + assert.false(isRegisteredSymbol(Object(Symbol())), 'non-registered'); + assert.false(isRegisteredSymbol(1), '1'); + assert.false(isRegisteredSymbol(true), 'true'); + assert.false(isRegisteredSymbol('1'), 'string'); + assert.false(isRegisteredSymbol(null), 'null'); + assert.false(isRegisteredSymbol(), 'undefined'); + assert.false(isRegisteredSymbol({}), 'object'); + assert.false(isRegisteredSymbol([]), 'array'); +}); diff --git a/tests/unit-global/esnext.symbol.is-registered.js b/tests/unit-global/esnext.symbol.is-registered.js index 08edd3211966..6e3395011669 100644 --- a/tests/unit-global/esnext.symbol.is-registered.js +++ b/tests/unit-global/esnext.symbol.is-registered.js @@ -3,7 +3,7 @@ QUnit.test('Symbol.isRegistered', assert => { assert.isFunction(isRegistered, 'Symbol.isRegistered is function'); assert.nonEnumerable(Symbol, 'isRegistered'); assert.arity(isRegistered, 1, 'Symbol.isRegistered arity is 1'); - assert.name(isRegistered, 'isRegistered', 'Symbol.isRegistered.name is "isRegistered"'); + assert.name(isRegistered, 'isRegisteredSymbol', 'Symbol.isRegistered.name is "isRegisteredSymbol"'); assert.looksNative(isRegistered, 'isRegistered looks like native'); assert.true(isRegistered(Symbol.for('foo')), 'registered-1'); diff --git a/tests/unit-global/esnext.symbol.is-well-known-symbol.js b/tests/unit-global/esnext.symbol.is-well-known-symbol.js new file mode 100644 index 000000000000..41f8e4910db4 --- /dev/null +++ b/tests/unit-global/esnext.symbol.is-well-known-symbol.js @@ -0,0 +1,22 @@ +QUnit.test('Symbol.isWellKnownSymbol', assert => { + const { isWellKnownSymbol } = Symbol; + assert.isFunction(isWellKnownSymbol, 'Symbol.isWellKnownSymbol is function'); + assert.nonEnumerable(Symbol, 'isWellKnownSymbol'); + assert.arity(isWellKnownSymbol, 1, 'Symbol.isWellKnownSymbol arity is 1'); + assert.name(isWellKnownSymbol, 'isWellKnownSymbol', 'Symbol.isWellKnownSymbol.name is "isWellKnownSymbol"'); + assert.looksNative(isWellKnownSymbol, 'isWellKnownSymbol looks like native'); + + assert.true(isWellKnownSymbol(Symbol.iterator), 'registered-1'); + assert.true(isWellKnownSymbol(Object(Symbol.iterator)), 'registered-2'); + assert.true(isWellKnownSymbol(Symbol.patternMatch), 'registered-3'); + assert.true(isWellKnownSymbol(Object(Symbol.patternMatch)), 'registered-4'); + assert.false(isWellKnownSymbol(Symbol()), 'non-registered'); + assert.false(isWellKnownSymbol(Object(Symbol())), 'non-registered'); + assert.false(isWellKnownSymbol(1), '1'); + assert.false(isWellKnownSymbol(true), 'true'); + assert.false(isWellKnownSymbol('1'), 'string'); + assert.false(isWellKnownSymbol(null), 'null'); + assert.false(isWellKnownSymbol(), 'undefined'); + assert.false(isWellKnownSymbol({}), 'object'); + assert.false(isWellKnownSymbol([]), 'array'); +}); diff --git a/tests/unit-global/esnext.symbol.is-well-known.js b/tests/unit-global/esnext.symbol.is-well-known.js index b84a341e3bfa..5c3224fcff7e 100644 --- a/tests/unit-global/esnext.symbol.is-well-known.js +++ b/tests/unit-global/esnext.symbol.is-well-known.js @@ -3,7 +3,7 @@ QUnit.test('Symbol.isWellKnown', assert => { assert.isFunction(isWellKnown, 'Symbol.isWellKnown is function'); assert.nonEnumerable(Symbol, 'isWellKnown'); assert.arity(isWellKnown, 1, 'Symbol.isWellKnown arity is 1'); - assert.name(isWellKnown, 'isWellKnown', 'Symbol.isWellKnown.name is "isWellKnown"'); + assert.name(isWellKnown, 'isWellKnownSymbol', 'Symbol.isWellKnown.name is "isWellKnownSymbol"'); assert.looksNative(isWellKnown, 'isWellKnown looks like native'); assert.true(isWellKnown(Symbol.iterator), 'registered-1'); diff --git a/tests/unit-pure/esnext.symbol.is-registered-symbol.js b/tests/unit-pure/esnext.symbol.is-registered-symbol.js new file mode 100644 index 000000000000..e650564ed960 --- /dev/null +++ b/tests/unit-pure/esnext.symbol.is-registered-symbol.js @@ -0,0 +1,20 @@ +import Symbol from 'core-js-pure/full/symbol'; + +QUnit.test('Symbol.isRegisteredSymbol', assert => { + const { isRegisteredSymbol } = Symbol; + assert.isFunction(isRegisteredSymbol, 'Symbol.isRegisteredSymbol is function'); + assert.arity(isRegisteredSymbol, 1, 'Symbol.isRegisteredSymbol arity is 1'); + assert.name(isRegisteredSymbol, 'isRegisteredSymbol', 'Symbol.isRegisteredSymbol.name is "isRegisteredSymbol"'); + + assert.true(isRegisteredSymbol(Symbol.for('foo')), 'registered-1'); + assert.true(isRegisteredSymbol(Object(Symbol.for('foo'))), 'registered-2'); + assert.false(isRegisteredSymbol(Symbol()), 'non-registered'); + assert.false(isRegisteredSymbol(Object(Symbol())), 'non-registered'); + assert.false(isRegisteredSymbol(1), '1'); + assert.false(isRegisteredSymbol(true), 'true'); + assert.false(isRegisteredSymbol('1'), 'string'); + assert.false(isRegisteredSymbol(null), 'null'); + assert.false(isRegisteredSymbol(), 'undefined'); + assert.false(isRegisteredSymbol({}), 'object'); + assert.false(isRegisteredSymbol([]), 'array'); +}); diff --git a/tests/unit-pure/esnext.symbol.is-registered.js b/tests/unit-pure/esnext.symbol.is-registered.js index 01402b4e267a..5467773f629e 100644 --- a/tests/unit-pure/esnext.symbol.is-registered.js +++ b/tests/unit-pure/esnext.symbol.is-registered.js @@ -4,7 +4,7 @@ QUnit.test('Symbol.isRegistered', assert => { const { isRegistered } = Symbol; assert.isFunction(isRegistered, 'Symbol.isRegistered is function'); assert.arity(isRegistered, 1, 'Symbol.isRegistered arity is 1'); - assert.name(isRegistered, 'isRegistered', 'Symbol.isRegistered.name is "isRegistered"'); + assert.name(isRegistered, 'isRegisteredSymbol', 'Symbol.isRegistered.name is "isRegisteredSymbol"'); assert.true(isRegistered(Symbol.for('foo')), 'registered-1'); assert.true(isRegistered(Object(Symbol.for('foo'))), 'registered-2'); diff --git a/tests/unit-pure/esnext.symbol.is-well-known-symbol.js b/tests/unit-pure/esnext.symbol.is-well-known-symbol.js new file mode 100644 index 000000000000..7c9cb1beef3c --- /dev/null +++ b/tests/unit-pure/esnext.symbol.is-well-known-symbol.js @@ -0,0 +1,22 @@ +import Symbol from 'core-js-pure/full/symbol'; + +QUnit.test('Symbol.isWellKnownSymbol', assert => { + const { isWellKnownSymbol } = Symbol; + assert.isFunction(isWellKnownSymbol, 'Symbol.isWellKnownSymbol is function'); + assert.arity(isWellKnownSymbol, 1, 'Symbol.isWellKnownSymbol arity is 1'); + assert.name(isWellKnownSymbol, 'isWellKnownSymbol', 'Symbol.isWellKnownSymbol.name is "isWellKnownSymbol"'); + + assert.true(isWellKnownSymbol(Symbol.iterator), 'registered-1'); + assert.true(isWellKnownSymbol(Object(Symbol.iterator)), 'registered-2'); + assert.true(isWellKnownSymbol(Symbol.patternMatch), 'registered-3'); + assert.true(isWellKnownSymbol(Object(Symbol.patternMatch)), 'registered-4'); + assert.false(isWellKnownSymbol(Symbol()), 'non-registered'); + assert.false(isWellKnownSymbol(Object(Symbol())), 'non-registered'); + assert.false(isWellKnownSymbol(1), '1'); + assert.false(isWellKnownSymbol(true), 'true'); + assert.false(isWellKnownSymbol('1'), 'string'); + assert.false(isWellKnownSymbol(null), 'null'); + assert.false(isWellKnownSymbol(), 'undefined'); + assert.false(isWellKnownSymbol({}), 'object'); + assert.false(isWellKnownSymbol([]), 'array'); +}); diff --git a/tests/unit-pure/esnext.symbol.is-well-known.js b/tests/unit-pure/esnext.symbol.is-well-known.js index e04519e8610c..4d255885017f 100644 --- a/tests/unit-pure/esnext.symbol.is-well-known.js +++ b/tests/unit-pure/esnext.symbol.is-well-known.js @@ -4,7 +4,7 @@ QUnit.test('Symbol.isWellKnown', assert => { const { isWellKnown } = Symbol; assert.isFunction(isWellKnown, 'Symbol.isWellKnown is function'); assert.arity(isWellKnown, 1, 'Symbol.isWellKnown arity is 1'); - assert.name(isWellKnown, 'isWellKnown', 'Symbol.isWellKnown.name is "isWellKnown"'); + assert.name(isWellKnown, 'isWellKnownSymbol', 'Symbol.isWellKnown.name is "isWellKnownSymbol"'); assert.true(isWellKnown(Symbol.iterator), 'registered-1'); assert.true(isWellKnown(Object(Symbol.iterator)), 'registered-2');