diff --git a/packages/core-js/internals/collection-of.js b/packages/core-js/internals/collection-of.js index b4b10541ba25..b23f18b16887 100644 --- a/packages/core-js/internals/collection-of.js +++ b/packages/core-js/internals/collection-of.js @@ -1,7 +1,15 @@ 'use strict'; -var arraySlice = require('../internals/array-slice'); +var anObject = require('../internals/an-object'); // https://tc39.github.io/proposal-setmap-offrom/ -module.exports = function of() { - return new this(arraySlice(arguments)); +module.exports = function (C, adder, ENTRY) { + return function of() { + var result = new C(); + var length = arguments.length; + for (var index = 0; index < length; index++) { + var entry = arguments[index]; + if (ENTRY) adder(result, anObject(entry)[0], entry[1]); + else adder(result, entry); + } return result; + }; }; diff --git a/packages/core-js/modules/esnext.map.of.js b/packages/core-js/modules/esnext.map.of.js index 6062ac0e8834..5fc111ede369 100644 --- a/packages/core-js/modules/esnext.map.of.js +++ b/packages/core-js/modules/esnext.map.of.js @@ -1,9 +1,10 @@ 'use strict'; var $ = require('../internals/export'); -var of = require('../internals/collection-of'); +var MapHelpers = require('../internals/map-helpers'); +var createCollectionOf = require('../internals/collection-of'); // `Map.of` method // https://tc39.github.io/proposal-setmap-offrom/#sec-map.of $({ target: 'Map', stat: true, forced: true }, { - of: of + of: createCollectionOf(MapHelpers.Map, MapHelpers.set, true) }); diff --git a/packages/core-js/modules/esnext.set.of.js b/packages/core-js/modules/esnext.set.of.js index 3aa973156184..a1a5424067c9 100644 --- a/packages/core-js/modules/esnext.set.of.js +++ b/packages/core-js/modules/esnext.set.of.js @@ -1,9 +1,10 @@ 'use strict'; var $ = require('../internals/export'); -var of = require('../internals/collection-of'); +var SetHelpers = require('../internals/set-helpers'); +var createCollectionOf = require('../internals/collection-of'); // `Set.of` method // https://tc39.github.io/proposal-setmap-offrom/#sec-set.of $({ target: 'Set', stat: true, forced: true }, { - of: of + of: createCollectionOf(SetHelpers.Set, SetHelpers.add, false) }); diff --git a/packages/core-js/modules/esnext.weak-map.of.js b/packages/core-js/modules/esnext.weak-map.of.js index 8ed0be03b165..e411172b09c9 100644 --- a/packages/core-js/modules/esnext.weak-map.of.js +++ b/packages/core-js/modules/esnext.weak-map.of.js @@ -1,9 +1,10 @@ 'use strict'; var $ = require('../internals/export'); -var of = require('../internals/collection-of'); +var WeakMapHelpers = require('../internals/weak-map-helpers'); +var createCollectionOf = require('../internals/collection-of'); // `WeakMap.of` method // https://tc39.github.io/proposal-setmap-offrom/#sec-weakmap.of $({ target: 'WeakMap', stat: true, forced: true }, { - of: of + of: createCollectionOf(WeakMapHelpers.WeakMap, WeakMapHelpers.set, true) }); diff --git a/packages/core-js/modules/esnext.weak-set.of.js b/packages/core-js/modules/esnext.weak-set.of.js index 451c51e31108..92cfd49df84c 100644 --- a/packages/core-js/modules/esnext.weak-set.of.js +++ b/packages/core-js/modules/esnext.weak-set.of.js @@ -1,9 +1,10 @@ 'use strict'; var $ = require('../internals/export'); -var of = require('../internals/collection-of'); +var WeakSetHelpers = require('../internals/weak-set-helpers'); +var createCollectionOf = require('../internals/collection-of'); // `WeakSet.of` method // https://tc39.github.io/proposal-setmap-offrom/#sec-weakset.of $({ target: 'WeakSet', stat: true, forced: true }, { - of: of + of: createCollectionOf(WeakSetHelpers.WeakSet, WeakSetHelpers.add, false) }); diff --git a/tests/unit-global/esnext.map.of.js b/tests/unit-global/esnext.map.of.js index 9c7ce9e26a31..a8e111e4af6f 100644 --- a/tests/unit-global/esnext.map.of.js +++ b/tests/unit-global/esnext.map.of.js @@ -6,14 +6,7 @@ QUnit.test('Map.of', assert => { assert.name(of, 'of'); assert.looksNative(of); assert.nonEnumerable(Map, 'of'); - assert.true(Map.of() instanceof Map); - assert.deepEqual(toArray(Map.of([1, 2])), [[1, 2]]); - assert.deepEqual(toArray(Map.of([1, 2], [2, 3], [1, 4])), [[1, 4], [2, 3]]); - assert.throws(() => of(1)); - let arg = null; - function F(it) { - return arg = it; - } - of.call(F, 1, 2, 3); - assert.deepEqual(arg, [1, 2, 3]); + assert.true(of() instanceof Map); + assert.deepEqual(toArray(of([1, 2])), [[1, 2]]); + assert.deepEqual(toArray(of([1, 2], [2, 3], [1, 4])), [[1, 4], [2, 3]]); }); diff --git a/tests/unit-global/esnext.set.of.js b/tests/unit-global/esnext.set.of.js index 62d5a3ce4458..a3772de00ad9 100644 --- a/tests/unit-global/esnext.set.of.js +++ b/tests/unit-global/esnext.set.of.js @@ -6,14 +6,7 @@ QUnit.test('Set.of', assert => { assert.name(of, 'of'); assert.looksNative(of); assert.nonEnumerable(Set, 'of'); - assert.true(Set.of() instanceof Set); - assert.deepEqual(toArray(Set.of(1)), [1]); - assert.deepEqual(toArray(Set.of(1, 2, 3, 2, 1)), [1, 2, 3]); - assert.throws(() => of(1)); - let arg = null; - function F(it) { - return arg = it; - } - of.call(F, 1, 2, 3); - assert.deepEqual(arg, [1, 2, 3]); + assert.true(of() instanceof Set); + assert.deepEqual(toArray(of(1)), [1]); + assert.deepEqual(toArray(of(1, 2, 3, 2, 1)), [1, 2, 3]); }); diff --git a/tests/unit-global/esnext.weak-map.of.js b/tests/unit-global/esnext.weak-map.of.js index 1f044c2e181a..719ae24d696d 100644 --- a/tests/unit-global/esnext.weak-map.of.js +++ b/tests/unit-global/esnext.weak-map.of.js @@ -6,13 +6,6 @@ QUnit.test('WeakMap.of', assert => { assert.looksNative(of); assert.nonEnumerable(WeakMap, 'of'); const array = []; - assert.true(WeakMap.of() instanceof WeakMap); - assert.same(WeakMap.of([array, 2]).get(array), 2); - assert.throws(() => of(1)); - let arg = null; - function F(it) { - return arg = it; - } - of.call(F, 1, 2, 3); - assert.deepEqual(arg, [1, 2, 3]); + assert.true(of() instanceof WeakMap); + assert.same(of([array, 2]).get(array), 2); }); diff --git a/tests/unit-global/esnext.weak-set.of.js b/tests/unit-global/esnext.weak-set.of.js index 59e4275f8614..056eacadeabd 100644 --- a/tests/unit-global/esnext.weak-set.of.js +++ b/tests/unit-global/esnext.weak-set.of.js @@ -6,13 +6,6 @@ QUnit.test('WeakSet.of', assert => { assert.looksNative(of); assert.nonEnumerable(WeakSet, 'of'); const array = []; - assert.true(WeakSet.of() instanceof WeakSet); - assert.true(WeakSet.of(array).has(array)); - assert.throws(() => of(1)); - let arg = null; - function F(it) { - arg = it; - } - of.call(F, 1, 2, 3); - assert.deepEqual(arg, [1, 2, 3]); + assert.true(of() instanceof WeakSet); + assert.true(of(array).has(array)); }); diff --git a/tests/unit-pure/esnext.map.of.js b/tests/unit-pure/esnext.map.of.js index 760c4707dddb..e38981493476 100644 --- a/tests/unit-pure/esnext.map.of.js +++ b/tests/unit-pure/esnext.map.of.js @@ -5,14 +5,7 @@ QUnit.test('Map.of', assert => { const { of } = Map; assert.isFunction(of); assert.arity(of, 0); - assert.true(Map.of() instanceof Map); - assert.deepEqual(from(Map.of([1, 2])), [[1, 2]]); - assert.deepEqual(from(Map.of([1, 2], [2, 3], [1, 4])), [[1, 4], [2, 3]]); - assert.throws(() => of(1)); - let arg = null; - function F(it) { - return arg = it; - } - of.call(F, 1, 2, 3); - assert.deepEqual(arg, [1, 2, 3]); + assert.true(of() instanceof Map); + assert.deepEqual(from(of([1, 2])), [[1, 2]]); + assert.deepEqual(from(of([1, 2], [2, 3], [1, 4])), [[1, 4], [2, 3]]); }); diff --git a/tests/unit-pure/esnext.set.of.js b/tests/unit-pure/esnext.set.of.js index 6f8bb158723b..1cb64ebd840b 100644 --- a/tests/unit-pure/esnext.set.of.js +++ b/tests/unit-pure/esnext.set.of.js @@ -5,14 +5,7 @@ QUnit.test('Set.of', assert => { const { of } = Set; assert.isFunction(of); assert.arity(of, 0); - assert.true(Set.of() instanceof Set); - assert.deepEqual(from(Set.of(1)), [1]); - assert.deepEqual(from(Set.of(1, 2, 3, 2, 1)), [1, 2, 3]); - assert.throws(() => of(1)); - let arg = null; - function F(it) { - return arg = it; - } - of.call(F, 1, 2, 3); - assert.deepEqual(arg, [1, 2, 3]); + assert.true(of() instanceof Set); + assert.deepEqual(from(of(1)), [1]); + assert.deepEqual(from(of(1, 2, 3, 2, 1)), [1, 2, 3]); }); diff --git a/tests/unit-pure/esnext.weak-map.of.js b/tests/unit-pure/esnext.weak-map.of.js index e193832c8786..19e6a0299b18 100644 --- a/tests/unit-pure/esnext.weak-map.of.js +++ b/tests/unit-pure/esnext.weak-map.of.js @@ -5,13 +5,6 @@ QUnit.test('WeakMap.of', assert => { assert.isFunction(of); assert.arity(of, 0); const array = []; - assert.true(WeakMap.of() instanceof WeakMap); - assert.same(WeakMap.of([array, 2]).get(array), 2); - assert.throws(() => of(1)); - let arg = null; - function F(it) { - return arg = it; - } - of.call(F, 1, 2, 3); - assert.deepEqual(arg, [1, 2, 3]); + assert.true(of() instanceof WeakMap); + assert.same(of([array, 2]).get(array), 2); }); diff --git a/tests/unit-pure/esnext.weak-set.of.js b/tests/unit-pure/esnext.weak-set.of.js index 8bc3ad1f6402..7d8abafdef44 100644 --- a/tests/unit-pure/esnext.weak-set.of.js +++ b/tests/unit-pure/esnext.weak-set.of.js @@ -5,13 +5,6 @@ QUnit.test('WeakSet.of', assert => { assert.isFunction(of); assert.arity(of, 0); const array = []; - assert.true(WeakSet.of() instanceof WeakSet); - assert.true(WeakSet.of(array).has(array)); - assert.throws(() => of(1)); - let arg = null; - function F(it) { - arg = it; - } - of.call(F, 1, 2, 3); - assert.deepEqual(arg, [1, 2, 3]); + assert.true(of() instanceof WeakSet); + assert.true(of(array).has(array)); });