From 3c0cee8463958c053b6e5c35987a79d16925cfb1 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Fri, 29 Oct 2021 13:03:49 +0700 Subject: [PATCH] change names of methods to *more probable* to- prefix schema https://github.com/tc39/proposal-change-array-by-copy/issues/10 --- packages/core-js-compat/src/data.mjs | 20 +++--- .../src/modules-by-versions.mjs | 16 ++--- ...t.js => esnext.typed-array.to-reversed.js} | 0 ...sed.js => esnext.typed-array.to-sorted.js} | 0 ...ed.js => esnext.typed-array.to-spliced.js} | 0 ...-spliced.js => esnext.typed-array.with.js} | 0 packages/core-js/features/array/index.js | 8 +-- .../core-js/features/array/to-reversed.js | 4 ++ packages/core-js/features/array/to-sorted.js | 5 ++ packages/core-js/features/array/to-spliced.js | 4 ++ .../core-js/features/array/virtual/index.js | 8 +-- .../features/array/virtual/to-reversed.js | 4 ++ .../virtual/{with-sorted.js => to-sorted.js} | 4 +- .../features/array/virtual/to-spliced.js | 4 ++ .../core-js/features/array/virtual/with-at.js | 4 -- .../features/array/virtual/with-reversed.js | 4 -- .../features/array/virtual/with-spliced.js | 4 -- .../core-js/features/array/virtual/with.js | 4 ++ packages/core-js/features/array/with-at.js | 4 -- .../core-js/features/array/with-reversed.js | 4 -- .../core-js/features/array/with-sorted.js | 5 -- .../core-js/features/array/with-spliced.js | 4 -- packages/core-js/features/array/with.js | 4 ++ .../{with-sorted.js => to-reversed.js} | 6 +- .../{with-spliced.js => to-sorted.js} | 6 +- .../{with-reversed.js => to-spliced.js} | 6 +- .../features/instance/{with-at.js => with.js} | 6 +- .../core-js/features/typed-array/index.js | 8 +-- .../core-js/features/typed-array/methods.js | 8 +-- .../features/typed-array/to-reversed.js | 1 + .../core-js/features/typed-array/to-sorted.js | 2 + .../features/typed-array/to-spliced.js | 1 + .../core-js/features/typed-array/with-at.js | 1 - .../features/typed-array/with-reversed.js | 1 - .../features/typed-array/with-sorted.js | 2 - .../features/typed-array/with-spliced.js | 1 - packages/core-js/features/typed-array/with.js | 1 + ...-with-reversed.js => array-to-reversed.js} | 4 +- ...ay-with-spliced.js => array-to-spliced.js} | 4 +- .../{array-with-at.js => array-with.js} | 4 +- ...with-at.js => esnext.array.to-reversed.js} | 12 ++-- ...th-sorted.js => esnext.array.to-sorted.js} | 8 +-- ...-spliced.js => esnext.array.to-spliced.js} | 12 ++-- .../modules/esnext.array.with-reversed.js | 18 ----- packages/core-js/modules/esnext.array.with.js | 15 ++++ ...t.js => esnext.typed-array.to-reversed.js} | 10 +-- ...ted.js => esnext.typed-array.to-sorted.js} | 6 +- ...ed.js => esnext.typed-array.to-spliced.js} | 10 +-- ...reversed.js => esnext.typed-array.with.js} | 12 ++-- .../core-js/proposals/change-array-by-copy.js | 16 ++--- tests/commonjs.mjs | 70 +++++++++---------- tests/compat/tests.js | 40 +++++------ ...eversed.js => esnext.array.to-reversed.js} | 18 ++--- ...th-sorted.js => esnext.array.to-sorted.js} | 44 ++++++------ tests/pure/esnext.array.to-spliced.js | 28 ++++++++ tests/pure/esnext.array.with-spliced.js | 28 -------- ....array.with-at.js => esnext.array.with.js} | 4 +- tests/tests/esnext.array.to-reversed.js | 62 ++++++++++++++++ ...th-sorted.js => esnext.array.to-sorted.js} | 54 +++++++------- tests/tests/esnext.array.to-spliced.js | 34 +++++++++ tests/tests/esnext.array.with-at.js | 35 ---------- tests/tests/esnext.array.with-reversed.js | 62 ---------------- tests/tests/esnext.array.with-spliced.js | 34 --------- tests/tests/esnext.array.with.js | 33 +++++++++ tests/tests/esnext.typed-array.to-reversed.js | 23 ++++++ ...ted.js => esnext.typed-array.to-sorted.js} | 36 +++++----- tests/tests/esnext.typed-array.to-spliced.js | 27 +++++++ tests/tests/esnext.typed-array.with-at.js | 28 -------- .../tests/esnext.typed-array.with-reversed.js | 23 ------ .../tests/esnext.typed-array.with-spliced.js | 27 ------- tests/tests/esnext.typed-array.with.js | 28 ++++++++ 71 files changed, 514 insertions(+), 519 deletions(-) rename packages/core-js-pure/override/modules/{esnext.typed-array.with-at.js => esnext.typed-array.to-reversed.js} (100%) rename packages/core-js-pure/override/modules/{esnext.typed-array.with-reversed.js => esnext.typed-array.to-sorted.js} (100%) rename packages/core-js-pure/override/modules/{esnext.typed-array.with-sorted.js => esnext.typed-array.to-spliced.js} (100%) rename packages/core-js-pure/override/modules/{esnext.typed-array.with-spliced.js => esnext.typed-array.with.js} (100%) create mode 100644 packages/core-js/features/array/to-reversed.js create mode 100644 packages/core-js/features/array/to-sorted.js create mode 100644 packages/core-js/features/array/to-spliced.js create mode 100644 packages/core-js/features/array/virtual/to-reversed.js rename packages/core-js/features/array/virtual/{with-sorted.js => to-sorted.js} (50%) create mode 100644 packages/core-js/features/array/virtual/to-spliced.js delete mode 100644 packages/core-js/features/array/virtual/with-at.js delete mode 100644 packages/core-js/features/array/virtual/with-reversed.js delete mode 100644 packages/core-js/features/array/virtual/with-spliced.js create mode 100644 packages/core-js/features/array/virtual/with.js delete mode 100644 packages/core-js/features/array/with-at.js delete mode 100644 packages/core-js/features/array/with-reversed.js delete mode 100644 packages/core-js/features/array/with-sorted.js delete mode 100644 packages/core-js/features/array/with-spliced.js create mode 100644 packages/core-js/features/array/with.js rename packages/core-js/features/instance/{with-sorted.js => to-reversed.js} (59%) rename packages/core-js/features/instance/{with-spliced.js => to-sorted.js} (59%) rename packages/core-js/features/instance/{with-reversed.js => to-spliced.js} (58%) rename packages/core-js/features/instance/{with-at.js => with.js} (61%) create mode 100644 packages/core-js/features/typed-array/to-reversed.js create mode 100644 packages/core-js/features/typed-array/to-sorted.js create mode 100644 packages/core-js/features/typed-array/to-spliced.js delete mode 100644 packages/core-js/features/typed-array/with-at.js delete mode 100644 packages/core-js/features/typed-array/with-reversed.js delete mode 100644 packages/core-js/features/typed-array/with-sorted.js delete mode 100644 packages/core-js/features/typed-array/with-spliced.js create mode 100644 packages/core-js/features/typed-array/with.js rename packages/core-js/internals/{array-with-reversed.js => array-to-reversed.js} (88%) rename packages/core-js/internals/{array-with-spliced.js => array-to-spliced.js} (96%) rename packages/core-js/internals/{array-with-at.js => array-with.js} (95%) rename packages/core-js/modules/{esnext.array.with-at.js => esnext.array.to-reversed.js} (59%) rename packages/core-js/modules/{esnext.array.with-sorted.js => esnext.array.to-sorted.js} (86%) rename packages/core-js/modules/{esnext.array.with-spliced.js => esnext.array.to-spliced.js} (61%) delete mode 100644 packages/core-js/modules/esnext.array.with-reversed.js create mode 100644 packages/core-js/modules/esnext.array.with.js rename packages/core-js/modules/{esnext.typed-array.with-at.js => esnext.typed-array.to-reversed.js} (56%) rename packages/core-js/modules/{esnext.typed-array.with-sorted.js => esnext.typed-array.to-sorted.js} (85%) rename packages/core-js/modules/{esnext.typed-array.with-spliced.js => esnext.typed-array.to-spliced.js} (58%) rename packages/core-js/modules/{esnext.typed-array.with-reversed.js => esnext.typed-array.with.js} (54%) rename tests/pure/{esnext.array.with-reversed.js => esnext.array.to-reversed.js} (52%) rename tests/pure/{esnext.array.with-sorted.js => esnext.array.to-sorted.js} (59%) create mode 100644 tests/pure/esnext.array.to-spliced.js delete mode 100644 tests/pure/esnext.array.with-spliced.js rename tests/pure/{esnext.array.with-at.js => esnext.array.with.js} (90%) create mode 100644 tests/tests/esnext.array.to-reversed.js rename tests/tests/{esnext.array.with-sorted.js => esnext.array.to-sorted.js} (54%) create mode 100644 tests/tests/esnext.array.to-spliced.js delete mode 100644 tests/tests/esnext.array.with-at.js delete mode 100644 tests/tests/esnext.array.with-reversed.js delete mode 100644 tests/tests/esnext.array.with-spliced.js create mode 100644 tests/tests/esnext.array.with.js create mode 100644 tests/tests/esnext.typed-array.to-reversed.js rename tests/tests/{esnext.typed-array.with-sorted.js => esnext.typed-array.to-sorted.js} (50%) create mode 100644 tests/tests/esnext.typed-array.to-spliced.js delete mode 100644 tests/tests/esnext.typed-array.with-at.js delete mode 100644 tests/tests/esnext.typed-array.with-reversed.js delete mode 100644 tests/tests/esnext.typed-array.with-spliced.js create mode 100644 tests/tests/esnext.typed-array.with.js diff --git a/packages/core-js-compat/src/data.mjs b/packages/core-js-compat/src/data.mjs index f3182d24713a..3c2ad8344bc4 100644 --- a/packages/core-js-compat/src/data.mjs +++ b/packages/core-js-compat/src/data.mjs @@ -1459,15 +1459,15 @@ export const data = { // TODO: Remove from `core-js@4` 'esnext.array.last-item': { }, - 'esnext.array.unique-by': { + 'esnext.array.to-reversed': { }, - 'esnext.array.with-at': { + 'esnext.array.to-sorted': { }, - 'esnext.array.with-reversed': { + 'esnext.array.to-spliced': { }, - 'esnext.array.with-sorted': { + 'esnext.array.unique-by': { }, - 'esnext.array.with-spliced': { + 'esnext.array.with': { }, 'esnext.async-iterator.constructor': { }, @@ -1737,15 +1737,15 @@ export const data = { }, 'esnext.typed-array.group-by': { }, - 'esnext.typed-array.unique-by': { + 'esnext.typed-array.to-reversed': { }, - 'esnext.typed-array.with-at': { + 'esnext.typed-array.to-sorted': { }, - 'esnext.typed-array.with-reversed': { + 'esnext.typed-array.to-spliced': { }, - 'esnext.typed-array.with-sorted': { + 'esnext.typed-array.unique-by': { }, - 'esnext.typed-array.with-spliced': { + 'esnext.typed-array.with': { }, 'esnext.weak-map.delete-all': { }, diff --git a/packages/core-js-compat/src/modules-by-versions.mjs b/packages/core-js-compat/src/modules-by-versions.mjs index c6fb7e1e900c..5c1305215b72 100644 --- a/packages/core-js-compat/src/modules-by-versions.mjs +++ b/packages/core-js-compat/src/modules-by-versions.mjs @@ -112,13 +112,13 @@ export default { 'esnext.typed-array.from-async', ], '3.20': [ - 'esnext.array.with-at', - 'esnext.array.with-reversed', - 'esnext.array.with-sorted', - 'esnext.array.with-spliced', - 'esnext.typed-array.with-at', - 'esnext.typed-array.with-reversed', - 'esnext.typed-array.with-sorted', - 'esnext.typed-array.with-spliced', + 'esnext.array.to-reversed', + 'esnext.array.to-sorted', + 'esnext.array.to-spliced', + 'esnext.array.with', + 'esnext.typed-array.to-reversed', + 'esnext.typed-array.to-sorted', + 'esnext.typed-array.to-spliced', + 'esnext.typed-array.with', ], }; diff --git a/packages/core-js-pure/override/modules/esnext.typed-array.with-at.js b/packages/core-js-pure/override/modules/esnext.typed-array.to-reversed.js similarity index 100% rename from packages/core-js-pure/override/modules/esnext.typed-array.with-at.js rename to packages/core-js-pure/override/modules/esnext.typed-array.to-reversed.js diff --git a/packages/core-js-pure/override/modules/esnext.typed-array.with-reversed.js b/packages/core-js-pure/override/modules/esnext.typed-array.to-sorted.js similarity index 100% rename from packages/core-js-pure/override/modules/esnext.typed-array.with-reversed.js rename to packages/core-js-pure/override/modules/esnext.typed-array.to-sorted.js diff --git a/packages/core-js-pure/override/modules/esnext.typed-array.with-sorted.js b/packages/core-js-pure/override/modules/esnext.typed-array.to-spliced.js similarity index 100% rename from packages/core-js-pure/override/modules/esnext.typed-array.with-sorted.js rename to packages/core-js-pure/override/modules/esnext.typed-array.to-spliced.js diff --git a/packages/core-js-pure/override/modules/esnext.typed-array.with-spliced.js b/packages/core-js-pure/override/modules/esnext.typed-array.with.js similarity index 100% rename from packages/core-js-pure/override/modules/esnext.typed-array.with-spliced.js rename to packages/core-js-pure/override/modules/esnext.typed-array.with.js diff --git a/packages/core-js/features/array/index.js b/packages/core-js/features/array/index.js index 706e8febaf31..2471feaaa960 100644 --- a/packages/core-js/features/array/index.js +++ b/packages/core-js/features/array/index.js @@ -13,10 +13,10 @@ require('../../modules/esnext.array.group-by'); require('../../modules/esnext.array.is-template-object'); require('../../modules/esnext.array.last-item'); require('../../modules/esnext.array.last-index'); +require('../../modules/esnext.array.to-reversed'); +require('../../modules/esnext.array.to-sorted'); +require('../../modules/esnext.array.to-spliced'); require('../../modules/esnext.array.unique-by'); -require('../../modules/esnext.array.with-at'); -require('../../modules/esnext.array.with-reversed'); -require('../../modules/esnext.array.with-sorted'); -require('../../modules/esnext.array.with-spliced'); +require('../../modules/esnext.array.with'); module.exports = parent; diff --git a/packages/core-js/features/array/to-reversed.js b/packages/core-js/features/array/to-reversed.js new file mode 100644 index 000000000000..f144b53a141e --- /dev/null +++ b/packages/core-js/features/array/to-reversed.js @@ -0,0 +1,4 @@ +require('../../modules/esnext.array.to-reversed'); +var entryUnbind = require('../../internals/entry-unbind'); + +module.exports = entryUnbind('Array', 'toReversed'); diff --git a/packages/core-js/features/array/to-sorted.js b/packages/core-js/features/array/to-sorted.js new file mode 100644 index 000000000000..42ac4ee45721 --- /dev/null +++ b/packages/core-js/features/array/to-sorted.js @@ -0,0 +1,5 @@ +require('../../modules/es.array.sort'); +require('../../modules/esnext.array.to-sorted'); +var entryUnbind = require('../../internals/entry-unbind'); + +module.exports = entryUnbind('Array', 'toSorted'); diff --git a/packages/core-js/features/array/to-spliced.js b/packages/core-js/features/array/to-spliced.js new file mode 100644 index 000000000000..9f03e3b06cb1 --- /dev/null +++ b/packages/core-js/features/array/to-spliced.js @@ -0,0 +1,4 @@ +require('../../modules/esnext.array.to-spliced'); +var entryUnbind = require('../../internals/entry-unbind'); + +module.exports = entryUnbind('Array', 'toSpliced'); diff --git a/packages/core-js/features/array/virtual/index.js b/packages/core-js/features/array/virtual/index.js index 93cd432b3dfc..619fda120223 100644 --- a/packages/core-js/features/array/virtual/index.js +++ b/packages/core-js/features/array/virtual/index.js @@ -8,10 +8,10 @@ require('../../../modules/esnext.array.filter-reject'); require('../../../modules/esnext.array.find-last'); require('../../../modules/esnext.array.find-last-index'); require('../../../modules/esnext.array.group-by'); +require('../../../modules/esnext.array.to-reversed'); +require('../../../modules/esnext.array.to-sorted'); +require('../../../modules/esnext.array.to-spliced'); require('../../../modules/esnext.array.unique-by'); -require('../../../modules/esnext.array.with-at'); -require('../../../modules/esnext.array.with-reversed'); -require('../../../modules/esnext.array.with-sorted'); -require('../../../modules/esnext.array.with-spliced'); +require('../../../modules/esnext.array.with'); module.exports = parent; diff --git a/packages/core-js/features/array/virtual/to-reversed.js b/packages/core-js/features/array/virtual/to-reversed.js new file mode 100644 index 000000000000..be5ac5d7d880 --- /dev/null +++ b/packages/core-js/features/array/virtual/to-reversed.js @@ -0,0 +1,4 @@ +require('../../../modules/esnext.array.to-reversed'); +var entryVirtual = require('../../../internals/entry-virtual'); + +module.exports = entryVirtual('Array').toReversed; diff --git a/packages/core-js/features/array/virtual/with-sorted.js b/packages/core-js/features/array/virtual/to-sorted.js similarity index 50% rename from packages/core-js/features/array/virtual/with-sorted.js rename to packages/core-js/features/array/virtual/to-sorted.js index c09716fd1712..3406f1919fbc 100644 --- a/packages/core-js/features/array/virtual/with-sorted.js +++ b/packages/core-js/features/array/virtual/to-sorted.js @@ -1,5 +1,5 @@ require('../../../modules/es.array.sort'); -require('../../../modules/esnext.array.with-sorted'); +require('../../../modules/esnext.array.to-sorted'); var entryVirtual = require('../../../internals/entry-virtual'); -module.exports = entryVirtual('Array').withSorted; +module.exports = entryVirtual('Array').toSorted; diff --git a/packages/core-js/features/array/virtual/to-spliced.js b/packages/core-js/features/array/virtual/to-spliced.js new file mode 100644 index 000000000000..863743314516 --- /dev/null +++ b/packages/core-js/features/array/virtual/to-spliced.js @@ -0,0 +1,4 @@ +require('../../../modules/esnext.array.to-spliced'); +var entryVirtual = require('../../../internals/entry-virtual'); + +module.exports = entryVirtual('Array').toSpliced; diff --git a/packages/core-js/features/array/virtual/with-at.js b/packages/core-js/features/array/virtual/with-at.js deleted file mode 100644 index 4be4fee0a617..000000000000 --- a/packages/core-js/features/array/virtual/with-at.js +++ /dev/null @@ -1,4 +0,0 @@ -require('../../../modules/esnext.array.with-at'); -var entryVirtual = require('../../../internals/entry-virtual'); - -module.exports = entryVirtual('Array').withAt; diff --git a/packages/core-js/features/array/virtual/with-reversed.js b/packages/core-js/features/array/virtual/with-reversed.js deleted file mode 100644 index edb9bfaeaeaa..000000000000 --- a/packages/core-js/features/array/virtual/with-reversed.js +++ /dev/null @@ -1,4 +0,0 @@ -require('../../../modules/esnext.array.with-reversed'); -var entryVirtual = require('../../../internals/entry-virtual'); - -module.exports = entryVirtual('Array').withReversed; diff --git a/packages/core-js/features/array/virtual/with-spliced.js b/packages/core-js/features/array/virtual/with-spliced.js deleted file mode 100644 index 596c957ca87f..000000000000 --- a/packages/core-js/features/array/virtual/with-spliced.js +++ /dev/null @@ -1,4 +0,0 @@ -require('../../../modules/esnext.array.with-spliced'); -var entryVirtual = require('../../../internals/entry-virtual'); - -module.exports = entryVirtual('Array').withSpliced; diff --git a/packages/core-js/features/array/virtual/with.js b/packages/core-js/features/array/virtual/with.js new file mode 100644 index 000000000000..6df870aeb2ff --- /dev/null +++ b/packages/core-js/features/array/virtual/with.js @@ -0,0 +1,4 @@ +require('../../../modules/esnext.array.with'); +var entryVirtual = require('../../../internals/entry-virtual'); + +module.exports = entryVirtual('Array')['with']; diff --git a/packages/core-js/features/array/with-at.js b/packages/core-js/features/array/with-at.js deleted file mode 100644 index 1b09246ded45..000000000000 --- a/packages/core-js/features/array/with-at.js +++ /dev/null @@ -1,4 +0,0 @@ -require('../../modules/esnext.array.with-at'); -var entryUnbind = require('../../internals/entry-unbind'); - -module.exports = entryUnbind('Array', 'withAt'); diff --git a/packages/core-js/features/array/with-reversed.js b/packages/core-js/features/array/with-reversed.js deleted file mode 100644 index 7b6b1eb12a49..000000000000 --- a/packages/core-js/features/array/with-reversed.js +++ /dev/null @@ -1,4 +0,0 @@ -require('../../modules/esnext.array.with-reversed'); -var entryUnbind = require('../../internals/entry-unbind'); - -module.exports = entryUnbind('Array', 'withReversed'); diff --git a/packages/core-js/features/array/with-sorted.js b/packages/core-js/features/array/with-sorted.js deleted file mode 100644 index 47fa1cc25d83..000000000000 --- a/packages/core-js/features/array/with-sorted.js +++ /dev/null @@ -1,5 +0,0 @@ -require('../../modules/es.array.sort'); -require('../../modules/esnext.array.with-sorted'); -var entryUnbind = require('../../internals/entry-unbind'); - -module.exports = entryUnbind('Array', 'withSorted'); diff --git a/packages/core-js/features/array/with-spliced.js b/packages/core-js/features/array/with-spliced.js deleted file mode 100644 index ef989c0ac0b4..000000000000 --- a/packages/core-js/features/array/with-spliced.js +++ /dev/null @@ -1,4 +0,0 @@ -require('../../modules/esnext.array.with-spliced'); -var entryUnbind = require('../../internals/entry-unbind'); - -module.exports = entryUnbind('Array', 'withSpliced'); diff --git a/packages/core-js/features/array/with.js b/packages/core-js/features/array/with.js new file mode 100644 index 000000000000..3591eaceeaf5 --- /dev/null +++ b/packages/core-js/features/array/with.js @@ -0,0 +1,4 @@ +require('../../modules/esnext.array.with'); +var entryUnbind = require('../../internals/entry-unbind'); + +module.exports = entryUnbind('Array', 'with'); diff --git a/packages/core-js/features/instance/with-sorted.js b/packages/core-js/features/instance/to-reversed.js similarity index 59% rename from packages/core-js/features/instance/with-sorted.js rename to packages/core-js/features/instance/to-reversed.js index 31537027ed88..5ef01827bea4 100644 --- a/packages/core-js/features/instance/with-sorted.js +++ b/packages/core-js/features/instance/to-reversed.js @@ -1,9 +1,9 @@ var isPrototypeOf = require('../../internals/object-is-prototype-of'); -var method = require('../array/virtual/with-sorted'); +var method = require('../array/virtual/to-reversed'); var ArrayPrototype = Array.prototype; module.exports = function (it) { - var own = it.withSorted; - return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.withSorted)) ? method : own; + var own = it.toReversed; + return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.toReversed)) ? method : own; }; diff --git a/packages/core-js/features/instance/with-spliced.js b/packages/core-js/features/instance/to-sorted.js similarity index 59% rename from packages/core-js/features/instance/with-spliced.js rename to packages/core-js/features/instance/to-sorted.js index a7bffa158c70..7110c9bc770c 100644 --- a/packages/core-js/features/instance/with-spliced.js +++ b/packages/core-js/features/instance/to-sorted.js @@ -1,9 +1,9 @@ var isPrototypeOf = require('../../internals/object-is-prototype-of'); -var method = require('../array/virtual/with-spliced'); +var method = require('../array/virtual/to-sorted'); var ArrayPrototype = Array.prototype; module.exports = function (it) { - var own = it.withSpliced; - return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.withSpliced)) ? method : own; + var own = it.toSorted; + return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.toSorted)) ? method : own; }; diff --git a/packages/core-js/features/instance/with-reversed.js b/packages/core-js/features/instance/to-spliced.js similarity index 58% rename from packages/core-js/features/instance/with-reversed.js rename to packages/core-js/features/instance/to-spliced.js index 9e105fa7c08c..b1044cbf0feb 100644 --- a/packages/core-js/features/instance/with-reversed.js +++ b/packages/core-js/features/instance/to-spliced.js @@ -1,9 +1,9 @@ var isPrototypeOf = require('../../internals/object-is-prototype-of'); -var method = require('../array/virtual/with-reversed'); +var method = require('../array/virtual/to-spliced'); var ArrayPrototype = Array.prototype; module.exports = function (it) { - var own = it.withReversed; - return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.withReversed)) ? method : own; + var own = it.toSpliced; + return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.toSpliced)) ? method : own; }; diff --git a/packages/core-js/features/instance/with-at.js b/packages/core-js/features/instance/with.js similarity index 61% rename from packages/core-js/features/instance/with-at.js rename to packages/core-js/features/instance/with.js index 15672610d0c3..d5e7c3b08178 100644 --- a/packages/core-js/features/instance/with-at.js +++ b/packages/core-js/features/instance/with.js @@ -1,9 +1,9 @@ var isPrototypeOf = require('../../internals/object-is-prototype-of'); -var method = require('../array/virtual/with-at'); +var method = require('../array/virtual/with'); var ArrayPrototype = Array.prototype; module.exports = function (it) { - var own = it.withAt; - return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.withAt)) ? method : own; + var own = it['with']; + return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype['with'])) ? method : own; }; diff --git a/packages/core-js/features/typed-array/index.js b/packages/core-js/features/typed-array/index.js index ab1238b80102..80760c62015e 100644 --- a/packages/core-js/features/typed-array/index.js +++ b/packages/core-js/features/typed-array/index.js @@ -10,10 +10,10 @@ require('../../modules/esnext.typed-array.filter-reject'); require('../../modules/esnext.typed-array.find-last'); require('../../modules/esnext.typed-array.find-last-index'); require('../../modules/esnext.typed-array.group-by'); +require('../../modules/esnext.typed-array.to-reversed'); +require('../../modules/esnext.typed-array.to-sorted'); +require('../../modules/esnext.typed-array.to-spliced'); require('../../modules/esnext.typed-array.unique-by'); -require('../../modules/esnext.typed-array.with-at'); -require('../../modules/esnext.typed-array.with-reversed'); -require('../../modules/esnext.typed-array.with-sorted'); -require('../../modules/esnext.typed-array.with-spliced'); +require('../../modules/esnext.typed-array.with'); module.exports = parent; diff --git a/packages/core-js/features/typed-array/methods.js b/packages/core-js/features/typed-array/methods.js index 1ce78f337c1d..3188b466926b 100644 --- a/packages/core-js/features/typed-array/methods.js +++ b/packages/core-js/features/typed-array/methods.js @@ -10,10 +10,10 @@ require('../../modules/esnext.typed-array.filter-reject'); require('../../modules/esnext.typed-array.find-last'); require('../../modules/esnext.typed-array.find-last-index'); require('../../modules/esnext.typed-array.group-by'); +require('../../modules/esnext.typed-array.to-reversed'); +require('../../modules/esnext.typed-array.to-sorted'); +require('../../modules/esnext.typed-array.to-spliced'); require('../../modules/esnext.typed-array.unique-by'); -require('../../modules/esnext.typed-array.with-at'); -require('../../modules/esnext.typed-array.with-reversed'); -require('../../modules/esnext.typed-array.with-sorted'); -require('../../modules/esnext.typed-array.with-spliced'); +require('../../modules/esnext.typed-array.with'); module.exports = parent; diff --git a/packages/core-js/features/typed-array/to-reversed.js b/packages/core-js/features/typed-array/to-reversed.js new file mode 100644 index 000000000000..28cbd6cbeb32 --- /dev/null +++ b/packages/core-js/features/typed-array/to-reversed.js @@ -0,0 +1 @@ +require('../../modules/esnext.typed-array.to-reversed'); diff --git a/packages/core-js/features/typed-array/to-sorted.js b/packages/core-js/features/typed-array/to-sorted.js new file mode 100644 index 000000000000..644f0fe564e6 --- /dev/null +++ b/packages/core-js/features/typed-array/to-sorted.js @@ -0,0 +1,2 @@ +require('../../modules/es.typed-array.sort'); +require('../../modules/esnext.typed-array.to-sorted'); diff --git a/packages/core-js/features/typed-array/to-spliced.js b/packages/core-js/features/typed-array/to-spliced.js new file mode 100644 index 000000000000..44ae5c2f6f32 --- /dev/null +++ b/packages/core-js/features/typed-array/to-spliced.js @@ -0,0 +1 @@ +require('../../modules/esnext.typed-array.to-spliced'); diff --git a/packages/core-js/features/typed-array/with-at.js b/packages/core-js/features/typed-array/with-at.js deleted file mode 100644 index 83dbc7198252..000000000000 --- a/packages/core-js/features/typed-array/with-at.js +++ /dev/null @@ -1 +0,0 @@ -require('../../modules/esnext.typed-array.with-at'); diff --git a/packages/core-js/features/typed-array/with-reversed.js b/packages/core-js/features/typed-array/with-reversed.js deleted file mode 100644 index 125399a6a8fb..000000000000 --- a/packages/core-js/features/typed-array/with-reversed.js +++ /dev/null @@ -1 +0,0 @@ -require('../../modules/esnext.typed-array.with-reversed'); diff --git a/packages/core-js/features/typed-array/with-sorted.js b/packages/core-js/features/typed-array/with-sorted.js deleted file mode 100644 index 0b420617d910..000000000000 --- a/packages/core-js/features/typed-array/with-sorted.js +++ /dev/null @@ -1,2 +0,0 @@ -require('../../modules/es.typed-array.sort'); -require('../../modules/esnext.typed-array.with-sorted'); diff --git a/packages/core-js/features/typed-array/with-spliced.js b/packages/core-js/features/typed-array/with-spliced.js deleted file mode 100644 index 9d324400bb36..000000000000 --- a/packages/core-js/features/typed-array/with-spliced.js +++ /dev/null @@ -1 +0,0 @@ -require('../../modules/esnext.typed-array.with-spliced'); diff --git a/packages/core-js/features/typed-array/with.js b/packages/core-js/features/typed-array/with.js new file mode 100644 index 000000000000..7908e59f7e47 --- /dev/null +++ b/packages/core-js/features/typed-array/with.js @@ -0,0 +1 @@ +require('../../modules/esnext.typed-array.with'); diff --git a/packages/core-js/internals/array-with-reversed.js b/packages/core-js/internals/array-to-reversed.js similarity index 88% rename from packages/core-js/internals/array-with-reversed.js rename to packages/core-js/internals/array-to-reversed.js index 0c3f13774a1d..6de7ff340024 100644 --- a/packages/core-js/internals/array-with-reversed.js +++ b/packages/core-js/internals/array-to-reversed.js @@ -1,7 +1,7 @@ var lengthOfArrayLike = require('../internals/length-of-array-like'); -// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.withReversed -// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.withReversed +// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toReversed +// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toReversed module.exports = function (O, C) { var len = lengthOfArrayLike(O); var A = new C(len); diff --git a/packages/core-js/internals/array-with-spliced.js b/packages/core-js/internals/array-to-spliced.js similarity index 96% rename from packages/core-js/internals/array-with-spliced.js rename to packages/core-js/internals/array-to-spliced.js index aeb51232a66a..5eec407af71e 100644 --- a/packages/core-js/internals/array-with-spliced.js +++ b/packages/core-js/internals/array-to-spliced.js @@ -5,8 +5,8 @@ var toIntegerOrInfinity = require('../internals/to-integer-or-infinity'); var max = Math.max; var min = Math.min; -// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.withSpliced -// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.withSpliced +// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSpliced +// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toSpliced module.exports = function (O, C, args) { var start = args[0]; var deleteCount = args[1]; diff --git a/packages/core-js/internals/array-with-at.js b/packages/core-js/internals/array-with.js similarity index 95% rename from packages/core-js/internals/array-with-at.js rename to packages/core-js/internals/array-with.js index f5088882acd6..c726632bde9b 100644 --- a/packages/core-js/internals/array-with-at.js +++ b/packages/core-js/internals/array-with.js @@ -5,8 +5,8 @@ var isIntegralNumber = require('../internals/is-integral-number'); var RangeError = global.RangeError; var ERROR_MESSAGE = 'Incorrect index'; -// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.withAt -// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.withAt +// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with +// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.with module.exports = function (O, C, index, value) { var len = lengthOfArrayLike(O); if (!isIntegralNumber(index) || index >= len) throw RangeError(ERROR_MESSAGE); diff --git a/packages/core-js/modules/esnext.array.with-at.js b/packages/core-js/modules/esnext.array.to-reversed.js similarity index 59% rename from packages/core-js/modules/esnext.array.with-at.js rename to packages/core-js/modules/esnext.array.to-reversed.js index 4056c02067d6..67e2d6244f64 100644 --- a/packages/core-js/modules/esnext.array.with-at.js +++ b/packages/core-js/modules/esnext.array.to-reversed.js @@ -1,18 +1,18 @@ 'use strict'; var $ = require('../internals/export'); var global = require('../internals/global'); -var arrayWithAt = require('../internals/array-with-at'); +var arrayToReversed = require('../internals/array-to-reversed'); var toIndexedObject = require('../internals/to-indexed-object'); var addToUnscopables = require('../internals/add-to-unscopables'); var Array = global.Array; -// `Array.prototype.withAt` method -// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.withAt +// `Array.prototype.toReversed` method +// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toReversed $({ target: 'Array', proto: true }, { - withAt: function withAt(index, value) { - return arrayWithAt(toIndexedObject(this), Array, index, value); + toReversed: function toReversed() { + return arrayToReversed(toIndexedObject(this), Array); } }); -addToUnscopables('withAt'); +addToUnscopables('toReversed'); diff --git a/packages/core-js/modules/esnext.array.with-sorted.js b/packages/core-js/modules/esnext.array.to-sorted.js similarity index 86% rename from packages/core-js/modules/esnext.array.with-sorted.js rename to packages/core-js/modules/esnext.array.to-sorted.js index 160eaec8e02e..212e93b03672 100644 --- a/packages/core-js/modules/esnext.array.with-sorted.js +++ b/packages/core-js/modules/esnext.array.to-sorted.js @@ -11,10 +11,10 @@ var addToUnscopables = require('../internals/add-to-unscopables'); var Array = global.Array; var sort = uncurryThis(getVirtual('Array').sort); -// `Array.prototype.withSorted` method -// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.withSorted +// `Array.prototype.toSorted` method +// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSorted $({ target: 'Array', proto: true }, { - withSorted: function withSorted(compareFn) { + toSorted: function toSorted(compareFn) { if (compareFn !== undefined) aCallable(compareFn); var O = toIndexedObject(this); var A = arrayFromConstructorAndList(Array, O); @@ -22,4 +22,4 @@ $({ target: 'Array', proto: true }, { } }); -addToUnscopables('withSorted'); +addToUnscopables('toSorted'); diff --git a/packages/core-js/modules/esnext.array.with-spliced.js b/packages/core-js/modules/esnext.array.to-spliced.js similarity index 61% rename from packages/core-js/modules/esnext.array.with-spliced.js rename to packages/core-js/modules/esnext.array.to-spliced.js index 7531f4dfe834..1b6ca49d4f43 100644 --- a/packages/core-js/modules/esnext.array.with-spliced.js +++ b/packages/core-js/modules/esnext.array.to-spliced.js @@ -3,18 +3,18 @@ var $ = require('../internals/export'); var global = require('../internals/global'); var toIndexedObject = require('../internals/to-indexed-object'); var arraySlice = require('../internals/array-slice'); -var arrayWithSpliced = require('../internals/array-with-spliced'); +var arrayToSpliced = require('../internals/array-to-spliced'); var addToUnscopables = require('../internals/add-to-unscopables'); var Array = global.Array; -// `Array.prototype.withSpliced` method -// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.withSpliced +// `Array.prototype.toSpliced` method +// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toSpliced $({ target: 'Array', proto: true }, { // eslint-disable-next-line no-unused-vars -- required for .length - withSpliced: function withSpliced(start, deleteCount /* , ...items */) { - return arrayWithSpliced(toIndexedObject(this), Array, arraySlice(arguments)); + toSpliced: function toSpliced(start, deleteCount /* , ...items */) { + return arrayToSpliced(toIndexedObject(this), Array, arraySlice(arguments)); } }); -addToUnscopables('withSpliced'); +addToUnscopables('toSpliced'); diff --git a/packages/core-js/modules/esnext.array.with-reversed.js b/packages/core-js/modules/esnext.array.with-reversed.js deleted file mode 100644 index 7482534305f6..000000000000 --- a/packages/core-js/modules/esnext.array.with-reversed.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; -var $ = require('../internals/export'); -var global = require('../internals/global'); -var arrayWithReversed = require('../internals/array-with-reversed'); -var toIndexedObject = require('../internals/to-indexed-object'); -var addToUnscopables = require('../internals/add-to-unscopables'); - -var Array = global.Array; - -// `Array.prototype.withReversed` method -// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.withReversed -$({ target: 'Array', proto: true }, { - withReversed: function withReversed() { - return arrayWithReversed(toIndexedObject(this), Array); - } -}); - -addToUnscopables('withReversed'); diff --git a/packages/core-js/modules/esnext.array.with.js b/packages/core-js/modules/esnext.array.with.js new file mode 100644 index 000000000000..c585d71f45cb --- /dev/null +++ b/packages/core-js/modules/esnext.array.with.js @@ -0,0 +1,15 @@ +'use strict'; +var $ = require('../internals/export'); +var global = require('../internals/global'); +var arrayWith = require('../internals/array-with'); +var toIndexedObject = require('../internals/to-indexed-object'); + +var Array = global.Array; + +// `Array.prototype.with` method +// https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with +$({ target: 'Array', proto: true }, { + 'with': function (index, value) { + return arrayWith(toIndexedObject(this), Array, index, value); + } +}); diff --git a/packages/core-js/modules/esnext.typed-array.with-at.js b/packages/core-js/modules/esnext.typed-array.to-reversed.js similarity index 56% rename from packages/core-js/modules/esnext.typed-array.with-at.js rename to packages/core-js/modules/esnext.typed-array.to-reversed.js index d52e5b192665..bdc9d4664756 100644 --- a/packages/core-js/modules/esnext.typed-array.with-at.js +++ b/packages/core-js/modules/esnext.typed-array.to-reversed.js @@ -1,13 +1,13 @@ 'use strict'; -var arrayWithAt = require('../internals/array-with-at'); +var arrayToReversed = require('../internals/array-to-reversed'); var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); var aTypedArray = ArrayBufferViewCore.aTypedArray; var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; var TYPED_ARRAY_CONSTRUCTOR = ArrayBufferViewCore.TYPED_ARRAY_CONSTRUCTOR; -// `%TypedArray%.prototype.withAt` method -// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.withAt -exportTypedArrayMethod('withAt', function withAt(index, value) { - return arrayWithAt(aTypedArray(this), this[TYPED_ARRAY_CONSTRUCTOR], index, value); +// `%TypedArray%.prototype.toReversed` method +// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toReversed +exportTypedArrayMethod('toReversed', function toReversed() { + return arrayToReversed(aTypedArray(this), this[TYPED_ARRAY_CONSTRUCTOR]); }); diff --git a/packages/core-js/modules/esnext.typed-array.with-sorted.js b/packages/core-js/modules/esnext.typed-array.to-sorted.js similarity index 85% rename from packages/core-js/modules/esnext.typed-array.with-sorted.js rename to packages/core-js/modules/esnext.typed-array.to-sorted.js index e50b4090b01e..d7dc40f4380e 100644 --- a/packages/core-js/modules/esnext.typed-array.with-sorted.js +++ b/packages/core-js/modules/esnext.typed-array.to-sorted.js @@ -9,9 +9,9 @@ var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; var TYPED_ARRAY_CONSTRUCTOR = ArrayBufferViewCore.TYPED_ARRAY_CONSTRUCTOR; var sort = uncurryThis(ArrayBufferViewCore.TypedArrayPrototype.sort); -// `%TypedArray%.prototype.withSorted` method -// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.withSorted -exportTypedArrayMethod('withSorted', function withSorted(compareFn) { +// `%TypedArray%.prototype.toSorted` method +// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toSorted +exportTypedArrayMethod('toSorted', function toSorted(compareFn) { if (compareFn !== undefined) aCallable(compareFn); var O = aTypedArray(this); var A = arrayFromConstructorAndList(O[TYPED_ARRAY_CONSTRUCTOR], O); diff --git a/packages/core-js/modules/esnext.typed-array.with-spliced.js b/packages/core-js/modules/esnext.typed-array.to-spliced.js similarity index 58% rename from packages/core-js/modules/esnext.typed-array.with-spliced.js rename to packages/core-js/modules/esnext.typed-array.to-spliced.js index 515626e0f1cd..bdbf3723adc2 100644 --- a/packages/core-js/modules/esnext.typed-array.with-spliced.js +++ b/packages/core-js/modules/esnext.typed-array.to-spliced.js @@ -1,15 +1,15 @@ 'use strict'; var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); var arraySlice = require('../internals/array-slice'); -var arrayWithSpliced = require('../internals/array-with-spliced'); +var arrayToSpliced = require('../internals/array-to-spliced'); var aTypedArray = ArrayBufferViewCore.aTypedArray; var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; var TYPED_ARRAY_CONSTRUCTOR = ArrayBufferViewCore.TYPED_ARRAY_CONSTRUCTOR; -// `%TypedArray%.prototype.withSpliced` method -// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.withSpliced +// `%TypedArray%.prototype.toSpliced` method +// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toSpliced // eslint-disable-next-line no-unused-vars -- required for .length -exportTypedArrayMethod('withSpliced', function withSpliced(start, deleteCount /* , ...items */) { - return arrayWithSpliced(aTypedArray(this), this[TYPED_ARRAY_CONSTRUCTOR], arraySlice(arguments)); +exportTypedArrayMethod('toSpliced', function toSpliced(start, deleteCount /* , ...items */) { + return arrayToSpliced(aTypedArray(this), this[TYPED_ARRAY_CONSTRUCTOR], arraySlice(arguments)); }); diff --git a/packages/core-js/modules/esnext.typed-array.with-reversed.js b/packages/core-js/modules/esnext.typed-array.with.js similarity index 54% rename from packages/core-js/modules/esnext.typed-array.with-reversed.js rename to packages/core-js/modules/esnext.typed-array.with.js index a4b3219146d9..5ef56b9ed882 100644 --- a/packages/core-js/modules/esnext.typed-array.with-reversed.js +++ b/packages/core-js/modules/esnext.typed-array.with.js @@ -1,13 +1,13 @@ 'use strict'; -var arrayWithReversed = require('../internals/array-with-reversed'); +var arrayWith = require('../internals/array-with'); var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); var aTypedArray = ArrayBufferViewCore.aTypedArray; var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; var TYPED_ARRAY_CONSTRUCTOR = ArrayBufferViewCore.TYPED_ARRAY_CONSTRUCTOR; -// `%TypedArray%.prototype.withReversed` method -// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.withReversed -exportTypedArrayMethod('withReversed', function withReversed() { - return arrayWithReversed(aTypedArray(this), this[TYPED_ARRAY_CONSTRUCTOR]); -}); +// `%TypedArray%.prototype.with` method +// https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.with +exportTypedArrayMethod('with', { 'with': function (index, value) { + return arrayWith(aTypedArray(this), this[TYPED_ARRAY_CONSTRUCTOR], index, value); +} }['with']); diff --git a/packages/core-js/proposals/change-array-by-copy.js b/packages/core-js/proposals/change-array-by-copy.js index d95d57391475..4a1121485a69 100644 --- a/packages/core-js/proposals/change-array-by-copy.js +++ b/packages/core-js/proposals/change-array-by-copy.js @@ -1,9 +1,9 @@ // https://github.com/tc39/proposal-change-array-by-copy -require('../modules/esnext.array.with-at'); -require('../modules/esnext.array.with-reversed'); -require('../modules/esnext.array.with-sorted'); -require('../modules/esnext.array.with-spliced'); -require('../modules/esnext.typed-array.with-at'); -require('../modules/esnext.typed-array.with-reversed'); -require('../modules/esnext.typed-array.with-sorted'); -require('../modules/esnext.typed-array.with-spliced'); +require('../modules/esnext.array.to-reversed'); +require('../modules/esnext.array.to-sorted'); +require('../modules/esnext.array.to-spliced'); +require('../modules/esnext.array.with'); +require('../modules/esnext.typed-array.to-reversed'); +require('../modules/esnext.typed-array.to-sorted'); +require('../modules/esnext.typed-array.to-spliced'); +require('../modules/esnext.typed-array.with'); diff --git a/tests/commonjs.mjs b/tests/commonjs.mjs index af0927793d8c..a58599498e61 100644 --- a/tests/commonjs.mjs +++ b/tests/commonjs.mjs @@ -571,20 +571,20 @@ for (PATH of ['core-js-pure', 'core-js']) { load(NS, 'array/last-item'); load(NS, 'array/last-index'); ok(typeof load(NS, 'array/unique-by') == 'function'); - ok(load(NS, 'array/with-at')([1, 2, 3], 1, 4)); - ok(load(NS, 'array/with-reversed')([1, 2, 3])[0] === 3); - ok(load(NS, 'array/with-sorted')([3, 2, 1])[0] === 1); - ok(load(NS, 'array/with-spliced')([3, 2, 1], 1, 1, 4, 5).length === 4); + ok(load(NS, 'array/with')([1, 2, 3], 1, 4)); + ok(load(NS, 'array/to-reversed')([1, 2, 3])[0] === 3); + ok(load(NS, 'array/to-sorted')([3, 2, 1])[0] === 1); + ok(load(NS, 'array/to-spliced')([3, 2, 1], 1, 1, 4, 5).length === 4); ok(typeof load(NS, 'array/virtual/filter-out') == 'function'); ok(typeof load(NS, 'array/virtual/filter-reject') == 'function'); ok(load(NS, 'array/virtual/find-last').call([1, 2, 3], it => it % 2) === 3); ok(load(NS, 'array/virtual/find-last-index').call([1, 2, 3], it => it % 2) === 2); ok(typeof load(NS, 'array/virtual/group-by') == 'function'); ok(typeof load(NS, 'array/virtual/unique-by') == 'function'); - ok(load(NS, 'array/virtual/with-at').call([1, 2, 3], 1, 4)); - ok(load(NS, 'array/virtual/with-reversed').call([1, 2, 3])[0] === 3); - ok(load(NS, 'array/virtual/with-sorted').call([3, 2, 1])[0] === 1); - ok(load(NS, 'array/virtual/with-spliced').call([3, 2, 1], 1, 1, 4, 5).length === 4); + ok(load(NS, 'array/virtual/with').call([1, 2, 3], 1, 4)); + ok(load(NS, 'array/virtual/to-reversed').call([1, 2, 3])[0] === 3); + ok(load(NS, 'array/virtual/to-sorted').call([3, 2, 1])[0] === 1); + ok(load(NS, 'array/virtual/to-spliced').call([3, 2, 1], 1, 1, 4, 5).length === 4); ok(typeof load(NS, 'async-iterator') == 'function'); ok(typeof load(NS, 'async-iterator/as-indexed-pairs') == 'function'); ok(typeof load(NS, 'async-iterator/drop') == 'function'); @@ -745,29 +745,29 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(typeof instanceUniqueBy([]) == 'function'); ok(instanceUniqueBy([]).call([1, 2, 3, 2, 1]).length === 3); - const instanceWithAt = load(NS, 'instance/with-at'); - ok(typeof instanceWithAt == 'function'); - ok(instanceWithAt({}) === undefined); - ok(typeof instanceWithAt([]) == 'function'); - ok(instanceWithAt([]).call([1, 2, 3], 1, 4)[1] === 4); - - const instanceWithReversed = load(NS, 'instance/with-reversed'); - ok(typeof instanceWithReversed == 'function'); - ok(instanceWithReversed({}) === undefined); - ok(typeof instanceWithReversed([]) == 'function'); - ok(instanceWithReversed([]).call([1, 2, 3])[0] === 3); - - const instanceWithSorted = load(NS, 'instance/with-sorted'); - ok(typeof instanceWithSorted == 'function'); - ok(instanceWithSorted({}) === undefined); - ok(typeof instanceWithSorted([]) == 'function'); - ok(instanceWithSorted([]).call([3, 2, 1])[0] === 1); - - const instanceWithSpliced = load(NS, 'instance/with-spliced'); - ok(typeof instanceWithSpliced == 'function'); - ok(instanceWithSpliced({}) === undefined); - ok(typeof instanceWithSpliced([]) == 'function'); - ok(instanceWithSpliced([]).call([3, 2, 1], 1, 1, 4, 5).length === 4); + const instanceWith = load(NS, 'instance/with'); + ok(typeof instanceWith == 'function'); + ok(instanceWith({}) === undefined); + ok(typeof instanceWith([]) == 'function'); + ok(instanceWith([]).call([1, 2, 3], 1, 4)[1] === 4); + + const instanceToReversed = load(NS, 'instance/to-reversed'); + ok(typeof instanceToReversed == 'function'); + ok(instanceToReversed({}) === undefined); + ok(typeof instanceToReversed([]) == 'function'); + ok(instanceToReversed([]).call([1, 2, 3])[0] === 3); + + const instanceToSorted = load(NS, 'instance/to-sorted'); + ok(typeof instanceToSorted == 'function'); + ok(instanceToSorted({}) === undefined); + ok(typeof instanceToSorted([]) == 'function'); + ok(instanceToSorted([]).call([3, 2, 1])[0] === 1); + + const instanceToSpliced = load(NS, 'instance/to-spliced'); + ok(typeof instanceToSpliced == 'function'); + ok(instanceToSpliced({}) === undefined); + ok(typeof instanceToSpliced([]) == 'function'); + ok(instanceToSpliced([]).call([3, 2, 1], 1, 1, 4, 5).length === 4); } load('proposals/accessible-object-hasownproperty'); @@ -894,10 +894,10 @@ for (const NS of ['es', 'stable', 'features']) { load(NS, 'typed-array/find-last-index'); load(NS, 'typed-array/group-by'); load(NS, 'typed-array/unique-by'); - load(NS, 'typed-array/with-at'); - load(NS, 'typed-array/with-reversed'); - load(NS, 'typed-array/with-sorted'); - load(NS, 'typed-array/with-spliced'); + load(NS, 'typed-array/with'); + load(NS, 'typed-array/to-reversed'); + load(NS, 'typed-array/to-sorted'); + load(NS, 'typed-array/to-spliced'); } load('modules/esnext.string.at-alternative'); diff --git a/tests/compat/tests.js b/tests/compat/tests.js index c3ecf31c0688..acef5e442564 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -1224,20 +1224,20 @@ GLOBAL.tests = { 'esnext.array.is-template-object': function () { return Array.isTemplateObject; }, - 'esnext.array.unique-by': function () { - return [].uniqueBy; + 'esnext.array.to-reversed': function () { + return [].toReversed; }, - 'esnext.array.with-at': function () { - return [].withAt; + 'esnext.array.to-sorted': function () { + return [].toSorted; }, - 'esnext.array.with-reversed': function () { - return [].withReversed; + 'esnext.array.to-spliced': function () { + return [].toSpliced; }, - 'esnext.array.with-sorted': function () { - return [].withSorted; + 'esnext.array.unique-by': function () { + return [].uniqueBy; }, - 'esnext.array.with-spliced': function () { - return [].withSpliced; + 'esnext.array.with': function () { + return []['with']; }, 'esnext.async-iterator.constructor': function () { return typeof AsyncIterator == 'function'; @@ -1511,20 +1511,20 @@ GLOBAL.tests = { 'esnext.typed-array.group-by': function () { return Int8Array.prototype.groupBy; }, - 'esnext.typed-array.unique-by': function () { - return Int8Array.prototype.uniqueBy; + 'esnext.typed-array.to-reversed': function () { + return Int8Array.prototype.toReversed; }, - 'esnext.typed-array.with-at': function () { - return Int8Array.prototype.withAt; + 'esnext.typed-array.to-sorted': function () { + return Int8Array.prototype.toSorted; }, - 'esnext.typed-array.with-reversed': function () { - return Int8Array.prototype.withReversed; + 'esnext.typed-array.to-spliced': function () { + return Int8Array.prototype.toSpliced; }, - 'esnext.typed-array.with-sorted': function () { - return Int8Array.prototype.withSorted; + 'esnext.typed-array.unique-by': function () { + return Int8Array.prototype.uniqueBy; }, - 'esnext.typed-array.with-spliced': function () { - return Int8Array.prototype.withSpliced; + 'esnext.typed-array.with': function () { + return Int8Array.prototype['with']; }, 'esnext.weak-map.delete-all': function () { return WeakMap.prototype.deleteAll; diff --git a/tests/pure/esnext.array.with-reversed.js b/tests/pure/esnext.array.to-reversed.js similarity index 52% rename from tests/pure/esnext.array.with-reversed.js rename to tests/pure/esnext.array.to-reversed.js index b8f2b36fb46b..8de40c13c38d 100644 --- a/tests/pure/esnext.array.with-reversed.js +++ b/tests/pure/esnext.array.to-reversed.js @@ -1,14 +1,14 @@ import { STRICT } from '../helpers/constants'; import Symbol from 'core-js-pure/es/symbol'; -import withReversed from 'core-js-pure/features/array/with-reversed'; +import toReversed from 'core-js-pure/features/array/to-reversed'; -QUnit.test('Array#withReversed', assert => { - assert.isFunction(withReversed); +QUnit.test('Array#toReversed', assert => { + assert.isFunction(toReversed); let array = [1, 2]; - assert.ok(withReversed(array) !== array, 'immutable'); - assert.deepEqual(withReversed([1, 2.2, 3.3]), [3.3, 2.2, 1], 'basic'); + assert.ok(toReversed(array) !== array, 'immutable'); + assert.deepEqual(toReversed([1, 2.2, 3.3]), [3.3, 2.2, 1], 'basic'); const object = {}; @@ -40,17 +40,17 @@ QUnit.test('Array#withReversed', assert => { undefined, ]; - assert.deepEqual(withReversed(array), expected, 'non-array target'); + assert.deepEqual(toReversed(array), expected, 'non-array target'); array = [1]; // eslint-disable-next-line object-shorthand -- constructor array.constructor = { [Symbol.species]: function () { return { foo: 1 }; } }; - assert.ok(withReversed(array) instanceof Array, 'non-generic'); + assert.ok(toReversed(array) instanceof Array, 'non-generic'); if (STRICT) { - assert.throws(() => withReversed(null, () => { /* empty */ }, 1), TypeError); - assert.throws(() => withReversed(undefined, () => { /* empty */ }, 1), TypeError); + assert.throws(() => toReversed(null, () => { /* empty */ }, 1), TypeError); + assert.throws(() => toReversed(undefined, () => { /* empty */ }, 1), TypeError); } }); diff --git a/tests/pure/esnext.array.with-sorted.js b/tests/pure/esnext.array.to-sorted.js similarity index 59% rename from tests/pure/esnext.array.with-sorted.js rename to tests/pure/esnext.array.to-sorted.js index 4d5c68080eb1..aefef87479dd 100644 --- a/tests/pure/esnext.array.with-sorted.js +++ b/tests/pure/esnext.array.to-sorted.js @@ -1,16 +1,16 @@ import { STRICT } from '../helpers/constants'; import Symbol from 'core-js-pure/es/symbol'; -import withSorted from 'core-js-pure/features/array/with-sorted'; +import toSorted from 'core-js-pure/features/array/to-sorted'; -QUnit.test('Array#withSorted', assert => { - assert.isFunction(withSorted); +QUnit.test('Array#toSorted', assert => { + assert.isFunction(toSorted); let array = [1]; - assert.ok(withSorted(array) !== array, 'immutable'); - assert.deepEqual(withSorted([1, 3, 2]), [1, 2, 3], '#1'); - assert.deepEqual(withSorted([1, 3, 2, 11]), [1, 11, 2, 3], '#2'); - assert.deepEqual(withSorted([1, -1, 3, NaN, 2, 0, 11, -0]), [-1, 0, -0, 1, 11, 2, 3, NaN], '#1'); + assert.ok(toSorted(array) !== array, 'immutable'); + assert.deepEqual(toSorted([1, 3, 2]), [1, 2, 3], '#1'); + assert.deepEqual(toSorted([1, 3, 2, 11]), [1, 11, 2, 3], '#2'); + assert.deepEqual(toSorted([1, -1, 3, NaN, 2, 0, 11, -0]), [-1, 0, -0, 1, 11, 2, 3, NaN], '#1'); array = Array(5); array[0] = 1; @@ -20,18 +20,18 @@ QUnit.test('Array#withSorted', assert => { expected[0] = 1; expected[1] = 2; expected[2] = 3; - assert.deepEqual(withSorted(array), expected, 'holes'); + assert.deepEqual(toSorted(array), expected, 'holes'); array = 'zyxwvutsrqponMLKJIHGFEDCBA'.split(''); expected = 'ABCDEFGHIJKLMnopqrstuvwxyz'.split(''); - assert.deepEqual(withSorted(array), expected, 'alpha #1'); + assert.deepEqual(toSorted(array), expected, 'alpha #1'); array = 'ёяюэьыъщшчцхфутсрПОНМЛКЙИЗЖЕДГВБА'.split(''); expected = 'АБВГДЕЖЗИЙКЛМНОПрстуфхцчшщъыьэюяё'.split(''); - assert.deepEqual(withSorted(array), expected, 'alpha #2'); + assert.deepEqual(toSorted(array), expected, 'alpha #2'); array = [undefined, 1]; - assert.notThrows(() => array = withSorted(array, () => { throw 1; }), 'undefined #1'); + assert.notThrows(() => array = toSorted(array, () => { throw 1; }), 'undefined #1'); assert.deepEqual(array, [1, undefined], 'undefined #2'); const object = { @@ -67,7 +67,7 @@ QUnit.test('Array#withSorted', assert => { undefined, ]; - assert.deepEqual(withSorted(array), expected, 'non-array target'); + assert.deepEqual(toSorted(array), expected, 'non-array target'); let index, mod, code, chr, value; expected = Array(516); @@ -79,9 +79,9 @@ QUnit.test('Array#withSorted', assert => { expected[index] = index - 2 * mod + 3; } - assert.same(String(withSorted(array, (a, b) => (a / 4 | 0) - (b / 4 | 0))), String(expected), 'stable #1'); + assert.same(String(toSorted(array, (a, b) => (a / 4 | 0) - (b / 4 | 0))), String(expected), 'stable #1'); - assert.ok(1 / withSorted([0, -0])[0] > 0, '-0'); + assert.ok(1 / toSorted([0, -0])[0] > 0, '-0'); let result = ''; array = []; @@ -101,7 +101,7 @@ QUnit.test('Array#withSorted', assert => { } } - array = withSorted(array, (a, b) => b.v - a.v); + array = toSorted(array, (a, b) => b.v - a.v); for (index = 0; index < array.length; index++) { chr = array[index].k.charAt(0); @@ -110,12 +110,12 @@ QUnit.test('Array#withSorted', assert => { assert.same(result, 'DGBEFHACIJK', 'stable #2'); - assert.notThrows(() => withSorted([1, 2, 3], undefined).length === 3, 'works with undefined'); - assert.throws(() => withSorted([1, 2, 3], null), 'throws on null'); - assert.throws(() => withSorted([1, 2, 3], {}), 'throws on {}'); + assert.notThrows(() => toSorted([1, 2, 3], undefined).length === 3, 'works with undefined'); + assert.throws(() => toSorted([1, 2, 3], null), 'throws on null'); + assert.throws(() => toSorted([1, 2, 3], {}), 'throws on {}'); if (typeof Symbol == 'function' && !Symbol.sham) { - assert.throws(() => withSorted([Symbol(1), Symbol(2)]), 'w/o cmp throws on symbols'); + assert.throws(() => toSorted([Symbol(1), Symbol(2)]), 'w/o cmp throws on symbols'); } array = [1]; @@ -123,10 +123,10 @@ QUnit.test('Array#withSorted', assert => { array.constructor = { [Symbol.species]: function () { return { foo: 1 }; } }; - assert.ok(withSorted(array) instanceof Array, 'non-generic'); + assert.ok(toSorted(array) instanceof Array, 'non-generic'); if (STRICT) { - assert.throws(() => withSorted(null), TypeError, 'ToObject(this)'); - assert.throws(() => withSorted(undefined), TypeError, 'ToObject(this)'); + assert.throws(() => toSorted(null), TypeError, 'ToObject(this)'); + assert.throws(() => toSorted(undefined), TypeError, 'ToObject(this)'); } }); diff --git a/tests/pure/esnext.array.to-spliced.js b/tests/pure/esnext.array.to-spliced.js new file mode 100644 index 000000000000..ca264436137d --- /dev/null +++ b/tests/pure/esnext.array.to-spliced.js @@ -0,0 +1,28 @@ +import { STRICT } from '../helpers/constants'; + +import Symbol from 'core-js-pure/es/symbol'; +import toSpliced from 'core-js-pure/features/array/to-spliced'; + +QUnit.test('Array#toSpliced', assert => { + assert.isFunction(toSpliced); + + let array = [1, 2, 3, 4, 5]; + assert.ok(toSpliced(array, 2) !== array); + assert.deepEqual(toSpliced([1, 2, 3, 4, 5], 2), [1, 2]); + assert.deepEqual(toSpliced([1, 2, 3, 4, 5], -2), [1, 2, 3]); + assert.deepEqual(toSpliced([1, 2, 3, 4, 5], 2, 2), [1, 2, 5]); + assert.deepEqual(toSpliced([1, 2, 3, 4, 5], 2, -2), [1, 2, 3, 4, 5]); + assert.deepEqual(toSpliced([1, 2, 3, 4, 5], 2, 2, 6, 7), [1, 2, 6, 7, 5]); + + if (STRICT) { + assert.throws(() => toSpliced(null), TypeError); + assert.throws(() => toSpliced(undefined), TypeError); + } + + array = []; + // eslint-disable-next-line object-shorthand -- constructor + array.constructor = { [Symbol.species]: function () { + return { foo: 1 }; + } }; + assert.ok(toSpliced(array) instanceof Array, 'non-generic'); +}); diff --git a/tests/pure/esnext.array.with-spliced.js b/tests/pure/esnext.array.with-spliced.js deleted file mode 100644 index 92025cc8f275..000000000000 --- a/tests/pure/esnext.array.with-spliced.js +++ /dev/null @@ -1,28 +0,0 @@ -import { STRICT } from '../helpers/constants'; - -import Symbol from 'core-js-pure/es/symbol'; -import withSpliced from 'core-js-pure/features/array/with-spliced'; - -QUnit.test('Array#withSpliced', assert => { - assert.isFunction(withSpliced); - - let array = [1, 2, 3, 4, 5]; - assert.ok(withSpliced(array, 2) !== array); - assert.deepEqual(withSpliced([1, 2, 3, 4, 5], 2), [1, 2]); - assert.deepEqual(withSpliced([1, 2, 3, 4, 5], -2), [1, 2, 3]); - assert.deepEqual(withSpliced([1, 2, 3, 4, 5], 2, 2), [1, 2, 5]); - assert.deepEqual(withSpliced([1, 2, 3, 4, 5], 2, -2), [1, 2, 3, 4, 5]); - assert.deepEqual(withSpliced([1, 2, 3, 4, 5], 2, 2, 6, 7), [1, 2, 6, 7, 5]); - - if (STRICT) { - assert.throws(() => withSpliced(null), TypeError); - assert.throws(() => withSpliced(undefined), TypeError); - } - - array = []; - // eslint-disable-next-line object-shorthand -- constructor - array.constructor = { [Symbol.species]: function () { - return { foo: 1 }; - } }; - assert.ok(withSpliced(array) instanceof Array, 'non-generic'); -}); diff --git a/tests/pure/esnext.array.with-at.js b/tests/pure/esnext.array.with.js similarity index 90% rename from tests/pure/esnext.array.with-at.js rename to tests/pure/esnext.array.with.js index f0b394f03889..81bd9a145888 100644 --- a/tests/pure/esnext.array.with-at.js +++ b/tests/pure/esnext.array.with.js @@ -1,9 +1,9 @@ import { STRICT } from '../helpers/constants'; import Symbol from 'core-js-pure/es/symbol'; -import withAt from 'core-js-pure/features/array/with-at'; +import withAt from 'core-js-pure/features/array/with'; -QUnit.test('Array#withAt', assert => { +QUnit.test('Array#with', assert => { assert.isFunction(withAt); let array = [1, 2, 3, 4, 5]; diff --git a/tests/tests/esnext.array.to-reversed.js b/tests/tests/esnext.array.to-reversed.js new file mode 100644 index 000000000000..ac993ecfd0c1 --- /dev/null +++ b/tests/tests/esnext.array.to-reversed.js @@ -0,0 +1,62 @@ +import { STRICT } from '../helpers/constants'; + +QUnit.test('Array#toReversed', assert => { + const { toReversed } = Array.prototype; + + assert.isFunction(toReversed); + assert.arity(toReversed, 0); + assert.name(toReversed, 'toReversed'); + assert.looksNative(toReversed); + assert.nonEnumerable(Array.prototype, 'toReversed'); + + let array = [1, 2]; + assert.ok(array.toReversed() !== array, 'immutable'); + + assert.deepEqual([1, 2.2, 3.3].toReversed(), [3.3, 2.2, 1], 'basic'); + + const object = {}; + + array = { + 0: undefined, + 1: 2, + 2: 1, + 3: 'X', + 4: -1, + 5: 'a', + 6: true, + 7: object, + 8: NaN, + 10: Infinity, + length: 11, + }; + + const expected = [ + Infinity, + undefined, + NaN, + object, + true, + 'a', + -1, + 'X', + 1, + 2, + undefined, + ]; + + assert.deepEqual(toReversed.call(array), expected, 'non-array target'); + + array = [1]; + // eslint-disable-next-line object-shorthand -- constructor + array.constructor = { [Symbol.species]: function () { + return { foo: 1 }; + } }; + assert.ok(array.toReversed() instanceof Array, 'non-generic'); + + if (STRICT) { + assert.throws(() => toReversed.call(null, () => { /* empty */ }, 1), TypeError); + assert.throws(() => toReversed.call(undefined, () => { /* empty */ }, 1), TypeError); + } + + assert.ok('toReversed' in Array.prototype[Symbol.unscopables], 'In Array#@@unscopables'); +}); diff --git a/tests/tests/esnext.array.with-sorted.js b/tests/tests/esnext.array.to-sorted.js similarity index 54% rename from tests/tests/esnext.array.with-sorted.js rename to tests/tests/esnext.array.to-sorted.js index 2ed9c23c3913..04318d142c88 100644 --- a/tests/tests/esnext.array.with-sorted.js +++ b/tests/tests/esnext.array.to-sorted.js @@ -1,20 +1,20 @@ import { STRICT } from '../helpers/constants'; -QUnit.test('Array#withSorted', assert => { - const { withSorted } = Array.prototype; +QUnit.test('Array#toSorted', assert => { + const { toSorted } = Array.prototype; - assert.isFunction(withSorted); - assert.arity(withSorted, 1); - assert.name(withSorted, 'withSorted'); - assert.looksNative(withSorted); - assert.nonEnumerable(Array.prototype, 'withSorted'); + assert.isFunction(toSorted); + assert.arity(toSorted, 1); + assert.name(toSorted, 'toSorted'); + assert.looksNative(toSorted); + assert.nonEnumerable(Array.prototype, 'toSorted'); let array = [1]; - assert.ok(array.withSorted() !== array, 'immutable'); + assert.ok(array.toSorted() !== array, 'immutable'); - assert.deepEqual([1, 3, 2].withSorted(), [1, 2, 3], '#1'); - assert.deepEqual([1, 3, 2, 11].withSorted(), [1, 11, 2, 3], '#2'); - assert.deepEqual([1, -1, 3, NaN, 2, 0, 11, -0].withSorted(), [-1, 0, -0, 1, 11, 2, 3, NaN], '#1'); + assert.deepEqual([1, 3, 2].toSorted(), [1, 2, 3], '#1'); + assert.deepEqual([1, 3, 2, 11].toSorted(), [1, 11, 2, 3], '#2'); + assert.deepEqual([1, -1, 3, NaN, 2, 0, 11, -0].toSorted(), [-1, 0, -0, 1, 11, 2, 3, NaN], '#1'); array = Array(5); array[0] = 1; @@ -24,18 +24,18 @@ QUnit.test('Array#withSorted', assert => { expected[0] = 1; expected[1] = 2; expected[2] = 3; - assert.deepEqual(array.withSorted(), expected, 'holes'); + assert.deepEqual(array.toSorted(), expected, 'holes'); array = 'zyxwvutsrqponMLKJIHGFEDCBA'.split(''); expected = 'ABCDEFGHIJKLMnopqrstuvwxyz'.split(''); - assert.deepEqual(array.withSorted(), expected, 'alpha #1'); + assert.deepEqual(array.toSorted(), expected, 'alpha #1'); array = 'ёяюэьыъщшчцхфутсрПОНМЛКЙИЗЖЕДГВБА'.split(''); expected = 'АБВГДЕЖЗИЙКЛМНОПрстуфхцчшщъыьэюяё'.split(''); - assert.deepEqual(array.withSorted(), expected, 'alpha #2'); + assert.deepEqual(array.toSorted(), expected, 'alpha #2'); array = [undefined, 1]; - assert.notThrows(() => array = array.withSorted(() => { throw 1; }), 'undefined #1'); + assert.notThrows(() => array = array.toSorted(() => { throw 1; }), 'undefined #1'); assert.deepEqual(array, [1, undefined], 'undefined #2'); const object = { @@ -71,7 +71,7 @@ QUnit.test('Array#withSorted', assert => { undefined, ]; - assert.deepEqual(withSorted.call(array), expected, 'non-array target'); + assert.deepEqual(toSorted.call(array), expected, 'non-array target'); let index, mod, code, chr, value; expected = Array(516); @@ -83,9 +83,9 @@ QUnit.test('Array#withSorted', assert => { expected[index] = index - 2 * mod + 3; } - assert.same(String(array.withSorted((a, b) => (a / 4 | 0) - (b / 4 | 0))), String(expected), 'stable #1'); + assert.same(String(array.toSorted((a, b) => (a / 4 | 0) - (b / 4 | 0))), String(expected), 'stable #1'); - assert.ok(1 / [0, -0].withSorted()[0] > 0, '-0'); + assert.ok(1 / [0, -0].toSorted()[0] > 0, '-0'); let result = ''; array = []; @@ -105,7 +105,7 @@ QUnit.test('Array#withSorted', assert => { } } - array = array.withSorted((a, b) => b.v - a.v); + array = array.toSorted((a, b) => b.v - a.v); for (index = 0; index < array.length; index++) { chr = array[index].k.charAt(0); @@ -114,12 +114,12 @@ QUnit.test('Array#withSorted', assert => { assert.same(result, 'DGBEFHACIJK', 'stable #2'); - assert.notThrows(() => [1, 2, 3].withSorted(undefined).length === 3, 'works with undefined'); - assert.throws(() => [1, 2, 3].withSorted(null), 'throws on null'); - assert.throws(() => [1, 2, 3].withSorted({}), 'throws on {}'); + assert.notThrows(() => [1, 2, 3].toSorted(undefined).length === 3, 'works with undefined'); + assert.throws(() => [1, 2, 3].toSorted(null), 'throws on null'); + assert.throws(() => [1, 2, 3].toSorted({}), 'throws on {}'); if (typeof Symbol == 'function' && !Symbol.sham) { - assert.throws(() => [Symbol(1), Symbol(2)].withSorted(), 'w/o cmp throws on symbols'); + assert.throws(() => [Symbol(1), Symbol(2)].toSorted(), 'w/o cmp throws on symbols'); } array = [1]; @@ -127,12 +127,12 @@ QUnit.test('Array#withSorted', assert => { array.constructor = { [Symbol.species]: function () { return { foo: 1 }; } }; - assert.ok(array.withSorted() instanceof Array, 'non-generic'); + assert.ok(array.toSorted() instanceof Array, 'non-generic'); if (STRICT) { - assert.throws(() => withSorted.call(null), TypeError, 'ToObject(this)'); - assert.throws(() => withSorted.call(undefined), TypeError, 'ToObject(this)'); + assert.throws(() => toSorted.call(null), TypeError, 'ToObject(this)'); + assert.throws(() => toSorted.call(undefined), TypeError, 'ToObject(this)'); } - assert.ok('withSorted' in Array.prototype[Symbol.unscopables], 'In Array#@@unscopables'); + assert.ok('toSorted' in Array.prototype[Symbol.unscopables], 'In Array#@@unscopables'); }); diff --git a/tests/tests/esnext.array.to-spliced.js b/tests/tests/esnext.array.to-spliced.js new file mode 100644 index 000000000000..733c1711b98b --- /dev/null +++ b/tests/tests/esnext.array.to-spliced.js @@ -0,0 +1,34 @@ +import { STRICT } from '../helpers/constants'; + +QUnit.test('Array#toSpliced', assert => { + const { toSpliced } = Array.prototype; + + assert.isFunction(toSpliced); + assert.arity(toSpliced, 2); + assert.name(toSpliced, 'toSpliced'); + assert.looksNative(toSpliced); + assert.nonEnumerable(Array.prototype, 'toSpliced'); + + let array = [1, 2, 3, 4, 5]; + assert.ok(array.toSpliced(2) !== array, 'immutable'); + + assert.deepEqual([1, 2, 3, 4, 5].toSpliced(2), [1, 2]); + assert.deepEqual([1, 2, 3, 4, 5].toSpliced(-2), [1, 2, 3]); + assert.deepEqual([1, 2, 3, 4, 5].toSpliced(2, 2), [1, 2, 5]); + assert.deepEqual([1, 2, 3, 4, 5].toSpliced(2, -2), [1, 2, 3, 4, 5]); + assert.deepEqual([1, 2, 3, 4, 5].toSpliced(2, 2, 6, 7), [1, 2, 6, 7, 5]); + + if (STRICT) { + assert.throws(() => toSpliced.call(null), TypeError); + assert.throws(() => toSpliced.call(undefined), TypeError); + } + array = []; + // eslint-disable-next-line object-shorthand -- constructor + array.constructor = { [Symbol.species]: function () { + return { foo: 1 }; + } }; + + assert.ok(array.toSpliced() instanceof Array, 'non-generic'); + + assert.ok('toSpliced' in Array.prototype[Symbol.unscopables], 'In Array#@@unscopables'); +}); diff --git a/tests/tests/esnext.array.with-at.js b/tests/tests/esnext.array.with-at.js deleted file mode 100644 index 16e286ae96c3..000000000000 --- a/tests/tests/esnext.array.with-at.js +++ /dev/null @@ -1,35 +0,0 @@ -import { STRICT } from '../helpers/constants'; - -QUnit.test('Array#withAt', assert => { - const { withAt } = Array.prototype; - - assert.isFunction(withAt); - assert.arity(withAt, 2); - assert.name(withAt, 'withAt'); - assert.looksNative(withAt); - assert.nonEnumerable(Array.prototype, 'withAt'); - - let array = [1, 2, 3, 4, 5]; - assert.ok(array.withAt(2, 1) !== array, 'immutable'); - - assert.deepEqual([1, 2, 3, 4, 5].withAt(2, 6), [1, 2, 6, 4, 5]); - assert.deepEqual([1, 2, 3, 4, 5].withAt(-2, 6), [1, 2, 3, 6, 5]); - - assert.throws(() => [1, 2, 3, 4, 5].withAt(5, 6), RangeError); - assert.throws(() => [1, 2, 3, 4, 5].withAt(-6, 6), RangeError); - assert.throws(() => [1, 2, 3, 4, 5].withAt('1', 6), RangeError); - - if (STRICT) { - assert.throws(() => withAt.call(null, 1, 2), TypeError); - assert.throws(() => withAt.call(undefined, 1, 2), TypeError); - } - - array = [1, 2]; - // eslint-disable-next-line object-shorthand -- constructor - array.constructor = { [Symbol.species]: function () { - return { foo: 1 }; - } }; - assert.ok(array.withAt(1, 2) instanceof Array, 'non-generic'); - - assert.ok('withAt' in Array.prototype[Symbol.unscopables], 'In Array#@@unscopables'); -}); diff --git a/tests/tests/esnext.array.with-reversed.js b/tests/tests/esnext.array.with-reversed.js deleted file mode 100644 index 118d3ad1743f..000000000000 --- a/tests/tests/esnext.array.with-reversed.js +++ /dev/null @@ -1,62 +0,0 @@ -import { STRICT } from '../helpers/constants'; - -QUnit.test('Array#withReversed', assert => { - const { withReversed } = Array.prototype; - - assert.isFunction(withReversed); - assert.arity(withReversed, 0); - assert.name(withReversed, 'withReversed'); - assert.looksNative(withReversed); - assert.nonEnumerable(Array.prototype, 'withReversed'); - - let array = [1, 2]; - assert.ok(array.withReversed() !== array, 'immutable'); - - assert.deepEqual([1, 2.2, 3.3].withReversed(), [3.3, 2.2, 1], 'basic'); - - const object = {}; - - array = { - 0: undefined, - 1: 2, - 2: 1, - 3: 'X', - 4: -1, - 5: 'a', - 6: true, - 7: object, - 8: NaN, - 10: Infinity, - length: 11, - }; - - const expected = [ - Infinity, - undefined, - NaN, - object, - true, - 'a', - -1, - 'X', - 1, - 2, - undefined, - ]; - - assert.deepEqual(withReversed.call(array), expected, 'non-array target'); - - array = [1]; - // eslint-disable-next-line object-shorthand -- constructor - array.constructor = { [Symbol.species]: function () { - return { foo: 1 }; - } }; - assert.ok(array.withReversed() instanceof Array, 'non-generic'); - - if (STRICT) { - assert.throws(() => withReversed.call(null, () => { /* empty */ }, 1), TypeError); - assert.throws(() => withReversed.call(undefined, () => { /* empty */ }, 1), TypeError); - } - - assert.ok('withReversed' in Array.prototype[Symbol.unscopables], 'In Array#@@unscopables'); -}); diff --git a/tests/tests/esnext.array.with-spliced.js b/tests/tests/esnext.array.with-spliced.js deleted file mode 100644 index 468af52640dd..000000000000 --- a/tests/tests/esnext.array.with-spliced.js +++ /dev/null @@ -1,34 +0,0 @@ -import { STRICT } from '../helpers/constants'; - -QUnit.test('Array#withSpliced', assert => { - const { withSpliced } = Array.prototype; - - assert.isFunction(withSpliced); - assert.arity(withSpliced, 2); - assert.name(withSpliced, 'withSpliced'); - assert.looksNative(withSpliced); - assert.nonEnumerable(Array.prototype, 'withSpliced'); - - let array = [1, 2, 3, 4, 5]; - assert.ok(array.withSpliced(2) !== array, 'immutable'); - - assert.deepEqual([1, 2, 3, 4, 5].withSpliced(2), [1, 2]); - assert.deepEqual([1, 2, 3, 4, 5].withSpliced(-2), [1, 2, 3]); - assert.deepEqual([1, 2, 3, 4, 5].withSpliced(2, 2), [1, 2, 5]); - assert.deepEqual([1, 2, 3, 4, 5].withSpliced(2, -2), [1, 2, 3, 4, 5]); - assert.deepEqual([1, 2, 3, 4, 5].withSpliced(2, 2, 6, 7), [1, 2, 6, 7, 5]); - - if (STRICT) { - assert.throws(() => withSpliced.call(null), TypeError); - assert.throws(() => withSpliced.call(undefined), TypeError); - } - array = []; - // eslint-disable-next-line object-shorthand -- constructor - array.constructor = { [Symbol.species]: function () { - return { foo: 1 }; - } }; - - assert.ok(array.withSpliced() instanceof Array, 'non-generic'); - - assert.ok('withSpliced' in Array.prototype[Symbol.unscopables], 'In Array#@@unscopables'); -}); diff --git a/tests/tests/esnext.array.with.js b/tests/tests/esnext.array.with.js new file mode 100644 index 000000000000..c1974d170ce2 --- /dev/null +++ b/tests/tests/esnext.array.with.js @@ -0,0 +1,33 @@ +import { STRICT } from '../helpers/constants'; + +QUnit.test('Array#with', assert => { + const { with: withAt } = Array.prototype; + + assert.isFunction(withAt); + assert.arity(withAt, 2); + // assert.name(withAt, 'with'); + assert.looksNative(withAt); + assert.nonEnumerable(Array.prototype, 'with'); + + let array = [1, 2, 3, 4, 5]; + assert.ok(array.with(2, 1) !== array, 'immutable'); + + assert.deepEqual([1, 2, 3, 4, 5].with(2, 6), [1, 2, 6, 4, 5]); + assert.deepEqual([1, 2, 3, 4, 5].with(-2, 6), [1, 2, 3, 6, 5]); + + assert.throws(() => [1, 2, 3, 4, 5].with(5, 6), RangeError); + assert.throws(() => [1, 2, 3, 4, 5].with(-6, 6), RangeError); + assert.throws(() => [1, 2, 3, 4, 5].with('1', 6), RangeError); + + if (STRICT) { + assert.throws(() => withAt.call(null, 1, 2), TypeError); + assert.throws(() => withAt.call(undefined, 1, 2), TypeError); + } + + array = [1, 2]; + // eslint-disable-next-line object-shorthand -- constructor + array.constructor = { [Symbol.species]: function () { + return { foo: 1 }; + } }; + assert.ok(array.with(1, 2) instanceof Array, 'non-generic'); +}); diff --git a/tests/tests/esnext.typed-array.to-reversed.js b/tests/tests/esnext.typed-array.to-reversed.js new file mode 100644 index 000000000000..2d9ae4792077 --- /dev/null +++ b/tests/tests/esnext.typed-array.to-reversed.js @@ -0,0 +1,23 @@ +import { DESCRIPTORS, GLOBAL, TYPED_ARRAYS } from '../helpers/constants'; + +if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.toReversed', assert => { + // we can't implement %TypedArrayPrototype% in all engines, so run all tests for each typed array constructor + for (const name in TYPED_ARRAYS) { + const TypedArray = GLOBAL[name]; + const { toReversed } = TypedArray.prototype; + + assert.isFunction(toReversed, `${ name }::toReversed is function`); + assert.arity(toReversed, 0, `${ name }::toReversed arity is 0`); + assert.name(toReversed, 'toReversed', `${ name }::toReversed name is 'toReversed'`); + assert.looksNative(toReversed, `${ name }::toReversed looks native`); + + const array = new TypedArray([1, 2]); + assert.ok(array.toReversed() !== array, 'immutable'); + assert.arrayEqual(new TypedArray([1, 2, 3, 4]).toReversed(), [4, 3, 2, 1], 'works #1'); + assert.arrayEqual(new TypedArray([1, 2, 3]).toReversed(), [3, 2, 1], 'works #2'); + + assert.throws(() => toReversed.call(null), TypeError, "isn't generic #1"); + assert.throws(() => toReversed.call(undefined), TypeError, "isn't generic #2"); + assert.throws(() => toReversed.call([1, 2]), TypeError, "isn't generic #3"); + } +}); diff --git a/tests/tests/esnext.typed-array.with-sorted.js b/tests/tests/esnext.typed-array.to-sorted.js similarity index 50% rename from tests/tests/esnext.typed-array.with-sorted.js rename to tests/tests/esnext.typed-array.to-sorted.js index fa4364cc8ace..14e4214d1e2e 100644 --- a/tests/tests/esnext.typed-array.with-sorted.js +++ b/tests/tests/esnext.typed-array.to-sorted.js @@ -1,23 +1,23 @@ import { DESCRIPTORS, GLOBAL, TYPED_ARRAYS } from '../helpers/constants'; -if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.withSorted', assert => { +if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.toSorted', assert => { // we can't implement %TypedArrayPrototype% in all engines, so run all tests for each typed array constructor for (const name in TYPED_ARRAYS) { const TypedArray = GLOBAL[name]; - const { withSorted } = TypedArray.prototype; + const { toSorted } = TypedArray.prototype; - assert.isFunction(withSorted, `${ name }::withSorted is function`); - assert.arity(withSorted, 1, `${ name }::withSorted arity is 1`); - assert.name(withSorted, 'withSorted', `${ name }::withSorted name is 'withSorted'`); - assert.looksNative(withSorted, `${ name }::withSorted looks native`); + assert.isFunction(toSorted, `${ name }::toSorted is function`); + assert.arity(toSorted, 1, `${ name }::toSorted arity is 1`); + assert.name(toSorted, 'toSorted', `${ name }::toSorted name is 'toSorted'`); + assert.looksNative(toSorted, `${ name }::toSorted looks native`); let array = new TypedArray([1]); - assert.ok(array.withSorted() !== array, 'immutable'); + assert.ok(array.toSorted() !== array, 'immutable'); if (name.indexOf('Float') === 0) { - assert.deepEqual(new TypedArray([1, -1, 3, NaN, 2, 0, 11, -0]).withSorted(), new TypedArray([-1, -0, 0, 1, 2, 3, 11, NaN]), '#1'); - assert.ok(1 / new TypedArray([0, -0]).withSorted()[0] < 0, '-0'); - assert.deepEqual(new TypedArray([NaN, 1, NaN]).withSorted(), new TypedArray([1, NaN, NaN]), 'NaN'); + assert.deepEqual(new TypedArray([1, -1, 3, NaN, 2, 0, 11, -0]).toSorted(), new TypedArray([-1, -0, 0, 1, 2, 3, 11, NaN]), '#1'); + assert.ok(1 / new TypedArray([0, -0]).toSorted()[0] < 0, '-0'); + assert.deepEqual(new TypedArray([NaN, 1, NaN]).toSorted(), new TypedArray([1, NaN, NaN]), 'NaN'); } if (name.indexOf('8') === -1) { @@ -31,7 +31,7 @@ if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.withSorted', assert => { expected[index] = index - 2 * mod + 3; } - array = array.withSorted((a, b) => (a / 4 | 0) - (b / 4 | 0)); + array = array.toSorted((a, b) => (a / 4 | 0) - (b / 4 | 0)); assert.same(String(array), String(expected), 'stable #1'); @@ -51,7 +51,7 @@ if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.withSorted', assert => { } } - array = array.withSorted((a, b) => b % 10 - a % 10); + array = array.toSorted((a, b) => b % 10 - a % 10); for (index = 0; index < array.length; index++) { j = String((array[index] / 520) | 0); @@ -61,12 +61,12 @@ if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.withSorted', assert => { assert.same(result, '3614570289', 'stable #2'); } - assert.notThrows(() => new TypedArray([1, 2, 3]).withSorted(undefined).length === 3, 'works with undefined'); - assert.throws(() => new TypedArray([1, 2, 3]).withSorted(null), 'throws on null'); - assert.throws(() => new TypedArray([1, 2, 3]).withSorted({}), 'throws on {}'); + assert.notThrows(() => new TypedArray([1, 2, 3]).toSorted(undefined).length === 3, 'works with undefined'); + assert.throws(() => new TypedArray([1, 2, 3]).toSorted(null), 'throws on null'); + assert.throws(() => new TypedArray([1, 2, 3]).toSorted({}), 'throws on {}'); - assert.throws(() => withSorted.call(null), TypeError, "isn't generic #1"); - assert.throws(() => withSorted.call(undefined), TypeError, "isn't generic #2"); - assert.throws(() => withSorted.call([1, 2]), TypeError, "isn't generic #3"); + assert.throws(() => toSorted.call(null), TypeError, "isn't generic #1"); + assert.throws(() => toSorted.call(undefined), TypeError, "isn't generic #2"); + assert.throws(() => toSorted.call([1, 2]), TypeError, "isn't generic #3"); } }); diff --git a/tests/tests/esnext.typed-array.to-spliced.js b/tests/tests/esnext.typed-array.to-spliced.js new file mode 100644 index 000000000000..b66d364a00a6 --- /dev/null +++ b/tests/tests/esnext.typed-array.to-spliced.js @@ -0,0 +1,27 @@ +import { DESCRIPTORS, GLOBAL, TYPED_ARRAYS } from '../helpers/constants'; + +if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.toSpliced', assert => { + // we can't implement %TypedArrayPrototype% in all engines, so run all tests for each typed array constructor + for (const name in TYPED_ARRAYS) { + const TypedArray = GLOBAL[name]; + const { toSpliced } = TypedArray.prototype; + + assert.isFunction(toSpliced, `${ name }::toSpliced is function`); + assert.arity(toSpliced, 2, `${ name }::toSpliced arity is 1`); + assert.name(toSpliced, 'toSpliced', `${ name }::toSpliced name is 'toSpliced'`); + assert.looksNative(toSpliced, `${ name }::toSpliced looks native`); + + const array = new TypedArray([1, 2, 3, 4, 5]); + assert.ok(array.toSpliced(2) !== array, 'immutable'); + + assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).toSpliced(2), new TypedArray([1, 2])); + assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).toSpliced(-2), new TypedArray([1, 2, 3])); + assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).toSpliced(2, 2), new TypedArray([1, 2, 5])); + assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).toSpliced(2, -2), new TypedArray([1, 2, 3, 4, 5])); + assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).toSpliced(2, 2, 6, 7), new TypedArray([1, 2, 6, 7, 5])); + + assert.throws(() => toSpliced.call(null), TypeError, "isn't generic #1"); + assert.throws(() => toSpliced.call(undefined), TypeError, "isn't generic #2"); + assert.throws(() => toSpliced.call([1, 2]), TypeError, "isn't generic #3"); + } +}); diff --git a/tests/tests/esnext.typed-array.with-at.js b/tests/tests/esnext.typed-array.with-at.js deleted file mode 100644 index c28749641592..000000000000 --- a/tests/tests/esnext.typed-array.with-at.js +++ /dev/null @@ -1,28 +0,0 @@ -import { DESCRIPTORS, GLOBAL, TYPED_ARRAYS } from '../helpers/constants'; - -if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.withAt', assert => { - // we can't implement %TypedArrayPrototype% in all engines, so run all tests for each typed array constructor - for (const name in TYPED_ARRAYS) { - const TypedArray = GLOBAL[name]; - const { withAt } = TypedArray.prototype; - - assert.isFunction(withAt, `${ name }::withAt is function`); - assert.arity(withAt, 2, `${ name }::withAt arity is 0`); - assert.name(withAt, 'withAt', `${ name }::withAt name is 'withAt'`); - assert.looksNative(withAt, `${ name }::withAt looks native`); - - const array = new TypedArray([1, 2, 3, 4, 5]); - assert.ok(array.withAt(2, 1) !== array, 'immutable'); - - assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).withAt(2, 6), new TypedArray([1, 2, 6, 4, 5])); - assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).withAt(-2, 6), new TypedArray([1, 2, 3, 6, 5])); - - assert.throws(() => new TypedArray([1, 2, 3, 4, 5]).withAt(5, 6), RangeError); - assert.throws(() => new TypedArray([1, 2, 3, 4, 5]).withAt(-6, 6), RangeError); - assert.throws(() => new TypedArray([1, 2, 3, 4, 5]).withAt('1', 6), RangeError); - - assert.throws(() => withAt.call(null, 1, 2), TypeError, "isn't generic #1"); - assert.throws(() => withAt.call(undefined, 1, 2), TypeError, "isn't generic #2"); - assert.throws(() => withAt.call([1, 2], 1, 3), TypeError, "isn't generic #3"); - } -}); diff --git a/tests/tests/esnext.typed-array.with-reversed.js b/tests/tests/esnext.typed-array.with-reversed.js deleted file mode 100644 index 9272ac4e4b07..000000000000 --- a/tests/tests/esnext.typed-array.with-reversed.js +++ /dev/null @@ -1,23 +0,0 @@ -import { DESCRIPTORS, GLOBAL, TYPED_ARRAYS } from '../helpers/constants'; - -if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.withReversed', assert => { - // we can't implement %TypedArrayPrototype% in all engines, so run all tests for each typed array constructor - for (const name in TYPED_ARRAYS) { - const TypedArray = GLOBAL[name]; - const { withReversed } = TypedArray.prototype; - - assert.isFunction(withReversed, `${ name }::withReversed is function`); - assert.arity(withReversed, 0, `${ name }::withReversed arity is 0`); - assert.name(withReversed, 'withReversed', `${ name }::withReversed name is 'withReversed'`); - assert.looksNative(withReversed, `${ name }::withReversed looks native`); - - const array = new TypedArray([1, 2]); - assert.ok(array.withReversed() !== array, 'immutable'); - assert.arrayEqual(new TypedArray([1, 2, 3, 4]).withReversed(), [4, 3, 2, 1], 'works #1'); - assert.arrayEqual(new TypedArray([1, 2, 3]).withReversed(), [3, 2, 1], 'works #2'); - - assert.throws(() => withReversed.call(null), TypeError, "isn't generic #1"); - assert.throws(() => withReversed.call(undefined), TypeError, "isn't generic #2"); - assert.throws(() => withReversed.call([1, 2]), TypeError, "isn't generic #3"); - } -}); diff --git a/tests/tests/esnext.typed-array.with-spliced.js b/tests/tests/esnext.typed-array.with-spliced.js deleted file mode 100644 index b1772c265699..000000000000 --- a/tests/tests/esnext.typed-array.with-spliced.js +++ /dev/null @@ -1,27 +0,0 @@ -import { DESCRIPTORS, GLOBAL, TYPED_ARRAYS } from '../helpers/constants'; - -if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.withSpliced', assert => { - // we can't implement %TypedArrayPrototype% in all engines, so run all tests for each typed array constructor - for (const name in TYPED_ARRAYS) { - const TypedArray = GLOBAL[name]; - const { withSpliced } = TypedArray.prototype; - - assert.isFunction(withSpliced, `${ name }::withSpliced is function`); - assert.arity(withSpliced, 2, `${ name }::withSpliced arity is 1`); - assert.name(withSpliced, 'withSpliced', `${ name }::withSpliced name is 'withSpliced'`); - assert.looksNative(withSpliced, `${ name }::withSpliced looks native`); - - const array = new TypedArray([1, 2, 3, 4, 5]); - assert.ok(array.withSpliced(2) !== array, 'immutable'); - - assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).withSpliced(2), new TypedArray([1, 2])); - assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).withSpliced(-2), new TypedArray([1, 2, 3])); - assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).withSpliced(2, 2), new TypedArray([1, 2, 5])); - assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).withSpliced(2, -2), new TypedArray([1, 2, 3, 4, 5])); - assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).withSpliced(2, 2, 6, 7), new TypedArray([1, 2, 6, 7, 5])); - - assert.throws(() => withSpliced.call(null), TypeError, "isn't generic #1"); - assert.throws(() => withSpliced.call(undefined), TypeError, "isn't generic #2"); - assert.throws(() => withSpliced.call([1, 2]), TypeError, "isn't generic #3"); - } -}); diff --git a/tests/tests/esnext.typed-array.with.js b/tests/tests/esnext.typed-array.with.js new file mode 100644 index 000000000000..b374f6dcf096 --- /dev/null +++ b/tests/tests/esnext.typed-array.with.js @@ -0,0 +1,28 @@ +import { DESCRIPTORS, GLOBAL, TYPED_ARRAYS } from '../helpers/constants'; + +if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.with', assert => { + // we can't implement %TypedArrayPrototype% in all engines, so run all tests for each typed array constructor + for (const name in TYPED_ARRAYS) { + const TypedArray = GLOBAL[name]; + const { with: withAt } = TypedArray.prototype; + + assert.isFunction(withAt, `${ name }::with is function`); + assert.arity(withAt, 2, `${ name }::with arity is 0`); + // assert.name(withAt, 'with', `${ name }::with name is 'with'`); + assert.looksNative(withAt, `${ name }::with looks native`); + + const array = new TypedArray([1, 2, 3, 4, 5]); + assert.ok(array.with(2, 1) !== array, 'immutable'); + + assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).with(2, 6), new TypedArray([1, 2, 6, 4, 5])); + assert.deepEqual(new TypedArray([1, 2, 3, 4, 5]).with(-2, 6), new TypedArray([1, 2, 3, 6, 5])); + + assert.throws(() => new TypedArray([1, 2, 3, 4, 5]).with(5, 6), RangeError); + assert.throws(() => new TypedArray([1, 2, 3, 4, 5]).with(-6, 6), RangeError); + assert.throws(() => new TypedArray([1, 2, 3, 4, 5]).with('1', 6), RangeError); + + assert.throws(() => withAt.call(null, 1, 2), TypeError, "isn't generic #1"); + assert.throws(() => withAt.call(undefined, 1, 2), TypeError, "isn't generic #2"); + assert.throws(() => withAt.call([1, 2], 1, 3), TypeError, "isn't generic #3"); + } +});