From 81ba0de350b486cd0ad663c1dd3826dff400e407 Mon Sep 17 00:00:00 2001 From: Daniel Minor Date: Sun, 8 Jun 2025 23:14:26 +0200 Subject: [PATCH] Move Map.prototype.getOrInsertComputed tests from staging to built-ins --- .../append-new-values-normalizes-zero-key.js | 3 +- .../getOrInsertComputed/append-new-values.js | 3 +- ...-key-is-not-present-different-key-types.js | 20 ++++--- .../getOrInsertComputed/callbackfn-throws.js | 5 +- .../check-callback-fn-args.js | 23 ++++++++ .../check-state-after-callback-fn-throws.js | 57 +++++++++++++++++++ ...ypes-function-callbackfn-does-not-throw.js | 33 +++-------- ...-not-evaluate-callbackfn-if-key-present.js | 6 +- ...does-not-have-mapdata-internal-slot-set.js | 10 ++-- ...-not-have-mapdata-internal-slot-weakmap.js | 10 ++-- .../getOrInsertComputed.js | 13 +---- .../getOrInsertComputed/not-a-constructor.js | 6 +- .../not-a-function-callbackfn-throws.js | 24 ++++---- .../overwrites-mutation-from-callbackfn.js | 3 +- ...-key-is-not-present-different-key-types.js | 17 +++--- ...e-if-key-is-present-different-key-types.js | 50 ++++++++++++++++ .../returns-value-normalized-zero-key.js | 3 +- .../this-not-object-throw.js | 6 +- .../upsert/Map/getOrInsertComputed/length.js | 22 ------- .../upsert/Map/getOrInsertComputed/name.js | 22 ------- ...e-if-key-is-present-different-key-types.js | 56 ------------------ 21 files changed, 201 insertions(+), 191 deletions(-) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/append-new-values-normalizes-zero-key.js (95%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/append-new-values.js (96%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/append-value-if-key-is-not-present-different-key-types.js (75%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/callbackfn-throws.js (91%) create mode 100644 test/built-ins/Map/prototype/getOrInsertComputed/check-callback-fn-args.js create mode 100644 test/built-ins/Map/prototype/getOrInsertComputed/check-state-after-callback-fn-throws.js rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/different-types-function-callbackfn-does-not-throw.js (55%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js (88%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/does-not-have-mapdata-internal-slot-set.js (74%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/does-not-have-mapdata-internal-slot-weakmap.js (73%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/getOrInsertComputed.js (65%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/not-a-constructor.js (90%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/not-a-function-callbackfn-throws.js (60%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/overwrites-mutation-from-callbackfn.js (96%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js (71%) create mode 100644 test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/returns-value-normalized-zero-key.js (94%) rename test/{staging/upsert/Map => built-ins/Map/prototype}/getOrInsertComputed/this-not-object-throw.js (88%) delete mode 100644 test/staging/upsert/Map/getOrInsertComputed/length.js delete mode 100644 test/staging/upsert/Map/getOrInsertComputed/name.js delete mode 100644 test/staging/upsert/Map/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js diff --git a/test/staging/upsert/Map/getOrInsertComputed/append-new-values-normalizes-zero-key.js b/test/built-ins/Map/prototype/getOrInsertComputed/append-new-values-normalizes-zero-key.js similarity index 95% rename from test/staging/upsert/Map/getOrInsertComputed/append-new-values-normalizes-zero-key.js rename to test/built-ins/Map/prototype/getOrInsertComputed/append-new-values-normalizes-zero-key.js index a66b824423..75a3f77867 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/append-new-values-normalizes-zero-key.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/append-new-values-normalizes-zero-key.js @@ -2,7 +2,7 @@ // Copyright (C) 2024 Jonas Haukenes, Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Append a new value in the map normalizing +0 and -0. info: | @@ -17,7 +17,6 @@ info: | 8. Append p to M.[[MapData]]. ... features: [Symbol, arrow-function, upsert] -flags: [noStrict] ---*/ var map = new Map(); map.getOrInsertComputed(-0, () => 42); diff --git a/test/staging/upsert/Map/getOrInsertComputed/append-new-values.js b/test/built-ins/Map/prototype/getOrInsertComputed/append-new-values.js similarity index 96% rename from test/staging/upsert/Map/getOrInsertComputed/append-new-values.js rename to test/built-ins/Map/prototype/getOrInsertComputed/append-new-values.js index c530cab728..555a379dc5 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/append-new-values.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/append-new-values.js @@ -2,7 +2,7 @@ // Copyright (C) 2024 Jonas Haukenes, Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Append a new value as the last element of entries. info: | @@ -17,7 +17,6 @@ info: | 8. Append p to M.[[MapData]]. ... features: [Symbol, arrow-function, upsert] -flags: [noStrict] ---*/ var s = Symbol(2); var map = new Map([[4, 4], ['foo3', 3], [s, 2]]); diff --git a/test/staging/upsert/Map/getOrInsertComputed/append-value-if-key-is-not-present-different-key-types.js b/test/built-ins/Map/prototype/getOrInsertComputed/append-value-if-key-is-not-present-different-key-types.js similarity index 75% rename from test/staging/upsert/Map/getOrInsertComputed/append-value-if-key-is-not-present-different-key-types.js rename to test/built-ins/Map/prototype/getOrInsertComputed/append-value-if-key-is-not-present-different-key-types.js index 6f1833bf54..178988b4da 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/append-value-if-key-is-not-present-different-key-types.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/append-value-if-key-is-not-present-different-key-types.js @@ -2,7 +2,7 @@ // Copyright (C) 2024 Sune Eriksson Lianes, Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Inserts the value for the specified key on different types, when key not present. info: | @@ -13,20 +13,22 @@ info: | 8. Append p to M.[[MapData]]. ... features: [Symbol, arrow-function, upsert] -flags: [noStrict] ---*/ var map = new Map(); -map.getOrInsertComputed('bar', () => 0); -assert.sameValue(map.get('bar'), 0); +var item = 'bar'; +map.getOrInsertComputed(item, () => 0); +assert.sameValue(map.get(item), 0); -map.getOrInsertComputed(1, () => 42); -assert.sameValue(map.get(1), 42); +item = 1; +map.getOrInsertComputed(item, () => 42); +assert.sameValue(map.get(item), 42); -map.getOrInsertComputed(NaN, () => 1); -assert.sameValue(map.get(NaN), 1); +item = NaN; +map.getOrInsertComputed(item, () => 1); +assert.sameValue(map.get(item), 1); -var item = {}; +item = {}; map.getOrInsertComputed(item, () => 2); assert.sameValue(map.get(item), 2); diff --git a/test/staging/upsert/Map/getOrInsertComputed/callbackfn-throws.js b/test/built-ins/Map/prototype/getOrInsertComputed/callbackfn-throws.js similarity index 91% rename from test/staging/upsert/Map/getOrInsertComputed/callbackfn-throws.js rename to test/built-ins/Map/prototype/getOrInsertComputed/callbackfn-throws.js index f011a0367f..862a85f1aa 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/callbackfn-throws.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/callbackfn-throws.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Map.getOrInsertComputed throws when callbackfn throws return if abrubt completion Call(callbackfn, key) info: | @@ -13,7 +13,6 @@ info: | 6. Let value be ? Call(callbackfn, key). ... features: [upsert] -flags: [noStrict] ---*/ var map = new Map(); @@ -21,5 +20,5 @@ assert.throws(Error, function() { map.getOrInsertComputed(1, function() { throw new Error('throw in callback'); }) -}, Error); +}); diff --git a/test/built-ins/Map/prototype/getOrInsertComputed/check-callback-fn-args.js b/test/built-ins/Map/prototype/getOrInsertComputed/check-callback-fn-args.js new file mode 100644 index 0000000000..489d81d2da --- /dev/null +++ b/test/built-ins/Map/prototype/getOrInsertComputed/check-callback-fn-args.js @@ -0,0 +1,23 @@ +// Copyright (C) 2025 Daniel Minor. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.getorinsertcomputed +description: | + Check that callbackfn receives undefined for this and exactly one argument. +info: | + Map.prototype.getOrInsertComputed ( key , callbackfn ) + + ... + + 6. Let value be ? Call(callbackfn, key). + ... +features: [upsert] +flags: [onlyStrict] +---*/ +var map = new Map(); + +map.getOrInsertComputed(1, function(...args) { + assert.sameValue(this, undefined); + assert.sameValue(args.length, 1); + assert.sameValue(args[0], 1); +}); diff --git a/test/built-ins/Map/prototype/getOrInsertComputed/check-state-after-callback-fn-throws.js b/test/built-ins/Map/prototype/getOrInsertComputed/check-state-after-callback-fn-throws.js new file mode 100644 index 0000000000..95c1301481 --- /dev/null +++ b/test/built-ins/Map/prototype/getOrInsertComputed/check-state-after-callback-fn-throws.js @@ -0,0 +1,57 @@ +// Copyright (C) 2025 Daniel Minor. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.getorinsertcomputed +description: | + Check state after callback function throws +info: | + Map.prototype.getOrInsertComputed ( key , callbackfn ) + + ... + + 6. Let value be ? Call(callbackfn, key). + ... +features: [upsert] +---*/ +var map = new Map(); +map.set(0, 'zero'); +map.set(1, 'one'); +map.set(2, 'two'); + +assert.throws(Error, function() { + map.getOrInsertComputed(3, function() { + throw new Error('throw in callback'); + }) +}); + +// Check the values after throwing in callbackfn. +assert.sameValue(map.get(0), 'zero'); +assert.sameValue(map.get(1), 'one'); +assert.sameValue(map.get(2), 'two'); +assert.sameValue(map.has(3), false) + +assert.throws(Error, function() { + map.getOrInsertComputed(3, function() { + map.set(1, 'mutated'); + throw new Error('throw in callback'); + }) +}); + +// Check the values after throwing in callbackfn, with mutation. +assert.sameValue(map.get(0), 'zero'); +assert.sameValue(map.get(1), 'mutated',); +assert.sameValue(map.get(2), 'two'); +assert.sameValue(map.has(3), false) + +assert.throws(Error, function() { + map.getOrInsertComputed(3, function() { + map.set(3, 'mutated'); + throw new Error('throw in callback'); + }) +}); + +// Check the values after throwing in callbackfn, with mutation. +assert.sameValue(map.get(0), 'zero'); +assert.sameValue(map.get(1), 'mutated',); +assert.sameValue(map.get(2), 'two'); +assert.sameValue(map.get(3), 'mutated') diff --git a/test/staging/upsert/Map/getOrInsertComputed/different-types-function-callbackfn-does-not-throw.js b/test/built-ins/Map/prototype/getOrInsertComputed/different-types-function-callbackfn-does-not-throw.js similarity index 55% rename from test/staging/upsert/Map/getOrInsertComputed/different-types-function-callbackfn-does-not-throw.js rename to test/built-ins/Map/prototype/getOrInsertComputed/different-types-function-callbackfn-does-not-throw.js index c5bc7951fc..b0a878d397 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/different-types-function-callbackfn-does-not-throw.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/different-types-function-callbackfn-does-not-throw.js @@ -1,7 +1,7 @@ // Copyright (C) 2024 Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Does not throw if `callbackfn` is callable. info: | @@ -12,40 +12,21 @@ info: | ... features: [arrow-function, upsert] -flags: [noStrict] ---*/ var m = new Map(); - -assert.sameValue( - m.getOrInsertComputed(1, function() {return 1;}) - , 1); +assert.sameValue(m.getOrInsertComputed(1, function () { return 1; }), 1); assert.sameValue(m.get(1), 1); - -assert.sameValue( - m.getOrInsertComputed(2, () => 2) - , 2); +assert.sameValue(m.getOrInsertComputed(2, () => 2), 2); assert.sameValue(m.get(2), 2); - -function three() {return 3;} - -assert.sameValue( - m.getOrInsertComputed(3, three) - , 3); +function three() { return 3; } +assert.sameValue(m.getOrInsertComputed(3, three), 3); assert.sameValue(m.get(3), 3); - -assert.sameValue( - m.getOrInsertComputed(4, new Function()) - , undefined); +assert.sameValue(m.getOrInsertComputed(4, new Function()), undefined); assert.sameValue(m.get(4), undefined); - -assert.sameValue( - m.getOrInsertComputed(5, (function() {return 5;}).bind(m)) - , 5); +assert.sameValue(m.getOrInsertComputed(5, (function () { return 5; }).bind(m)), 5); assert.sameValue(m.get(5), 5); - - diff --git a/test/staging/upsert/Map/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js b/test/built-ins/Map/prototype/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js similarity index 88% rename from test/staging/upsert/Map/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js rename to test/built-ins/Map/prototype/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js index 50e4d4ada0..1fa1976c8c 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js @@ -1,7 +1,7 @@ // Copyright (C) 2025 Jonas Haukenes. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Does not evaluate the callback function if the key is already in the map. info: | @@ -13,13 +13,14 @@ info: | 6. Let value be ? Call(callbackfn, undefined, « key »). ... features: [WeakMap, upsert] -flags: [noStrict] ---*/ var map = new Map([ [1, 0] ]); +var callbackCalls = 0; function callback() { + callbackCalls += 1; throw new Error('Callbackfn should not be evaluated if key is present'); } @@ -35,3 +36,4 @@ assert.throws(Error, function() { map.getOrInsertComputed(4, callback)} , Error); +assert.sameValue(callbackCalls, 1); diff --git a/test/staging/upsert/Map/getOrInsertComputed/does-not-have-mapdata-internal-slot-set.js b/test/built-ins/Map/prototype/getOrInsertComputed/does-not-have-mapdata-internal-slot-set.js similarity index 74% rename from test/staging/upsert/Map/getOrInsertComputed/does-not-have-mapdata-internal-slot-set.js rename to test/built-ins/Map/prototype/getOrInsertComputed/does-not-have-mapdata-internal-slot-set.js index c4323b9653..4757378ee2 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/does-not-have-mapdata-internal-slot-set.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/does-not-have-mapdata-internal-slot-set.js @@ -2,7 +2,7 @@ // Copyright (C) 2024 Sune Eriksson Lianes, Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Throws a TypeError if `this` is a Set Object info: | @@ -13,14 +13,14 @@ info: | 2. Perform ? RequireInternalSlot(M, [[MapData]]) ... features: [Set, arrow-function, upsert] -flags: [noStrict] ---*/ +var set = new Set(); assert.throws(TypeError, function () { - Map.prototype.getOrInsertComputed.call(new Set(), 1, () => 1); + Map.prototype.getOrInsertComputed.call(set, 1, () => 1); }); +var map = new Map(); assert.throws(TypeError, function () { - var map = new Map(); - map.getOrInsertComputed.call(new Set(), 1, () => 1); + map.getOrInsertComputed.call(set, 1, () => 1); }); diff --git a/test/staging/upsert/Map/getOrInsertComputed/does-not-have-mapdata-internal-slot-weakmap.js b/test/built-ins/Map/prototype/getOrInsertComputed/does-not-have-mapdata-internal-slot-weakmap.js similarity index 73% rename from test/staging/upsert/Map/getOrInsertComputed/does-not-have-mapdata-internal-slot-weakmap.js rename to test/built-ins/Map/prototype/getOrInsertComputed/does-not-have-mapdata-internal-slot-weakmap.js index 644bedb8a3..733fd99a24 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/does-not-have-mapdata-internal-slot-weakmap.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/does-not-have-mapdata-internal-slot-weakmap.js @@ -2,7 +2,7 @@ // Copyright (C) 2024 Sune Eriksson Lianes, Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Throws a TypeError if `this` is a WeakMap object. info: | @@ -13,14 +13,14 @@ info: | 2. Perform ? RequireInternalSlot(M, [[MapData]]). ... features: [WeakMap, arrow-function, upsert] -flags: [noStrict] ---*/ +var weakmap = new WeakMap(); assert.throws(TypeError, function() { - Map.prototype.getOrInsertComputed.call(new WeakMap(), 1, () => 1); + Map.prototype.getOrInsertComputed.call(weakmap, 1, () => 1); }); +var map = new Map(); assert.throws(TypeError, function() { - var map = new Map(); - map.getOrInsertComputed.call(new WeakMap(), 1, () => 1); + map.getOrInsertComputed.call(weakmap, 1, () => 1); }); diff --git a/test/staging/upsert/Map/getOrInsertComputed/getOrInsertComputed.js b/test/built-ins/Map/prototype/getOrInsertComputed/getOrInsertComputed.js similarity index 65% rename from test/staging/upsert/Map/getOrInsertComputed/getOrInsertComputed.js rename to test/built-ins/Map/prototype/getOrInsertComputed/getOrInsertComputed.js index 14474c76c7..1ec57f23c8 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/getOrInsertComputed.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/getOrInsertComputed.js @@ -2,7 +2,7 @@ // Copyright (C) 2024 Jonas Haukenes, Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Property type and descriptor. info: | @@ -10,16 +10,9 @@ info: | 17 ECMAScript Standard Built-in Objects includes: [propertyHelper.js] -features: [arrow-function, upsert] -flags: [noStrict] +features: [upsert] ---*/ -assert.sameValue( - typeof Map.prototype.getOrInsertComputed, - 'function', - '`typeof Map.prototype.getOrInsertComputed` is `function`' -); - -verifyProperty(Map.prototype, "getOrInsertComputed", { +verifyPrimordialCallableProperty(Map.prototype, "getOrInsertComputed", "getOrInsertComputed", 2, { value: Map.prototype.getOrInsertComputed, writable: true, enumerable: false, diff --git a/test/staging/upsert/Map/getOrInsertComputed/not-a-constructor.js b/test/built-ins/Map/prototype/getOrInsertComputed/not-a-constructor.js similarity index 90% rename from test/staging/upsert/Map/getOrInsertComputed/not-a-constructor.js rename to test/built-ins/Map/prototype/getOrInsertComputed/not-a-constructor.js index c059cb40fb..1a7c6731fd 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/not-a-constructor.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/not-a-constructor.js @@ -3,7 +3,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Map.prototype.getOrInsertComputed does not implement [[Construct]], is not new-able info: | @@ -20,11 +20,11 @@ info: | ... includes: [isConstructor.js] features: [Map, Reflect.construct, arrow-function, upsert] -flags: [noStrict] ---*/ assert.sameValue(isConstructor(Map.prototype.getOrInsertComputed), false, 'isConstructor(Map.prototype.getOrInsertComputed) must return false'); +var m = new Map(); assert.throws(TypeError, () => { - let m = new Map(); new m.getOrInsertComputed(); + new m.getOrInsertComputed(); }); diff --git a/test/staging/upsert/Map/getOrInsertComputed/not-a-function-callbackfn-throws.js b/test/built-ins/Map/prototype/getOrInsertComputed/not-a-function-callbackfn-throws.js similarity index 60% rename from test/staging/upsert/Map/getOrInsertComputed/not-a-function-callbackfn-throws.js rename to test/built-ins/Map/prototype/getOrInsertComputed/not-a-function-callbackfn-throws.js index 6adc1eeabe..7d4366a979 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/not-a-function-callbackfn-throws.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/not-a-function-callbackfn-throws.js @@ -2,7 +2,7 @@ // Copyright (C) 2024 Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Throws a TypeError if `callbackfn` is not callable. info: | @@ -12,39 +12,43 @@ info: | 3. If IsCallable(callbackfn) is false, throw a TypeError exception. ... features: [Symbol, upsert] -flags: [noStrict] ---*/ var m = new Map(); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, 1, 1); + m.getOrInsertComputed(1, 1); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, 1, ""); + m.getOrInsertComputed(1, ""); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, 1, true); + m.getOrInsertComputed(1, true); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, 1, undefined); + m.getOrInsertComputed(1, undefined); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, 1, null); + m.getOrInsertComputed(1, null); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, 1, {}); + m.getOrInsertComputed(1, {}); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, 1, []); + m.getOrInsertComputed(1, []); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, 1, Symbol()); + m.getOrInsertComputed(1, Symbol()); }); +// Check that it also throws if the key is already present (thus it does not try to call the callback) +m.set(1, "foo"); +assert.throws(TypeError, function () { + m.getOrInsertComputed(1, 1); +}); diff --git a/test/staging/upsert/Map/getOrInsertComputed/overwrites-mutation-from-callbackfn.js b/test/built-ins/Map/prototype/getOrInsertComputed/overwrites-mutation-from-callbackfn.js similarity index 96% rename from test/staging/upsert/Map/getOrInsertComputed/overwrites-mutation-from-callbackfn.js rename to test/built-ins/Map/prototype/getOrInsertComputed/overwrites-mutation-from-callbackfn.js index 3a2d1b054d..32ab867b31 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/overwrites-mutation-from-callbackfn.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/overwrites-mutation-from-callbackfn.js @@ -1,7 +1,7 @@ // Copyright (C) 2025 Jonas Haukenes. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | If the callbackfn inserts a value on the given key, the value is overwritten. info: | @@ -16,7 +16,6 @@ info: | 8. Let p be the Record { [[Key]]: key, [[Value]]: value }. 9. Append p to M.[[WeakMapData]]. ... -flags: [noStrict] features: [upsert] ---*/ var map = new Map(); diff --git a/test/staging/upsert/Map/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js b/test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js similarity index 71% rename from test/staging/upsert/Map/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js rename to test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js index 6ee7df8bca..01ec990b58 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-different-key-types.js @@ -2,9 +2,9 @@ // Copyright (C) 2024 Jonas Haukenes, Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | - Returns the value from the specified key on different types, when key not present. + Test insertion of value returned from callback with different key types. info: | Map.prototype.getOrInsertComputed ( key , callbackfn ) @@ -14,17 +14,18 @@ info: | 9. Return p.[[Value]]. ... features: [Symbol, arrow-function, upsert] -flags: [noStrict] ---*/ var map = new Map(); +var item = 'bar'; +assert.sameValue(map.getOrInsertComputed(item, () => 0), 0); -assert.sameValue(map.getOrInsertComputed('bar', () => 0), 0); +item = 1; +assert.sameValue(map.getOrInsertComputed(item, () => 42), 42); -assert.sameValue(map.getOrInsertComputed(1, () => 42), 42); +item = NaN; +assert.sameValue(map.getOrInsertComputed(item, () => 1), 1); -assert.sameValue(map.getOrInsertComputed(NaN, () => 1), 1); - -var item = {}; +item = {}; assert.sameValue(map.getOrInsertComputed(item, () => 2), 2); item = []; diff --git a/test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js b/test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js new file mode 100644 index 0000000000..758eaaeb97 --- /dev/null +++ b/test/built-ins/Map/prototype/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js @@ -0,0 +1,50 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// Copyright (C) 2024 Sune Eriksson Lianes, Mathias Ness. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.getorinsertcomputed +description: | + Returns the value set before getOrInsertComputed from the specified key on different types. +info: | + Map.prototype.getOrInsertComputed ( key , callbackfn ) + + ... + 5. For each Record { [[Key]], [[Value]] } p of M.[[MapData]], do + a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, return p.[[Value]]. + ... +features: [Symbol, arrow-function, upsert] +---*/ +var map = new Map(); + +var item = 'bar'; +map.set(item, 0); +assert.sameValue(map.getOrInsertComputed(item, () => 1), 0); + +item = 1; +map.set(item, 42); +assert.sameValue(map.getOrInsertComputed(item, () => 43), 42); + +item = NaN; +map.set(item, 1); +assert.sameValue(map.getOrInsertComputed(item, () => 2), 1); + +item = {}; +map.set(item, 2); +assert.sameValue(map.getOrInsertComputed(item, () => 3), 2); + +item = []; +map.set(item, 3); +assert.sameValue(map.getOrInsertComputed(item, () => 4), 3); + +item = Symbol('item'); +map.set(item, 4); +assert.sameValue(map.getOrInsertComputed(item, () => 5), 4); + +item = null; +map.set(item, 5); +assert.sameValue(map.getOrInsertComputed(item, () => 6), 5); + +item = undefined; +map.set(item, 6); +assert.sameValue(map.getOrInsertComputed(item, () => 7), 6); + diff --git a/test/staging/upsert/Map/getOrInsertComputed/returns-value-normalized-zero-key.js b/test/built-ins/Map/prototype/getOrInsertComputed/returns-value-normalized-zero-key.js similarity index 94% rename from test/staging/upsert/Map/getOrInsertComputed/returns-value-normalized-zero-key.js rename to test/built-ins/Map/prototype/getOrInsertComputed/returns-value-normalized-zero-key.js index a08f873ef6..70a55b24c7 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/returns-value-normalized-zero-key.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/returns-value-normalized-zero-key.js @@ -2,7 +2,7 @@ // Copyright (C) 2024 Jonas Haukenes, Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Returns the value from the specified key normalizing +0 and -0. info: | @@ -14,7 +14,6 @@ info: | ... features: [arrow-function, upsert] -flags: [noStrict] ---*/ var map = new Map(); diff --git a/test/staging/upsert/Map/getOrInsertComputed/this-not-object-throw.js b/test/built-ins/Map/prototype/getOrInsertComputed/this-not-object-throw.js similarity index 88% rename from test/staging/upsert/Map/getOrInsertComputed/this-not-object-throw.js rename to test/built-ins/Map/prototype/getOrInsertComputed/this-not-object-throw.js index a671766289..8c96f99028 100644 --- a/test/staging/upsert/Map/getOrInsertComputed/this-not-object-throw.js +++ b/test/built-ins/Map/prototype/getOrInsertComputed/this-not-object-throw.js @@ -2,7 +2,7 @@ // Copyright (C) 2024 Sune Eriksson Lianes, Mathias Ness. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-map.prototype.getorinsertcomputed description: | Throws a TypeError if `this` is not an Object. info: | @@ -12,7 +12,6 @@ info: | 2. Perform ? RequireInternalSlot(M, [[MapData]]) ... features: [Symbol, arrow-function, upsert] -flags: [noStrict] ---*/ var m = new Map(); @@ -40,3 +39,6 @@ assert.throws(TypeError, function () { m.getOrInsertComputed.call(Symbol(), 1, () => 1); }); +assert.throws(TypeError, function () { + m.getOrInsertComputed.call(1n, 1, () => 1); +}); diff --git a/test/staging/upsert/Map/getOrInsertComputed/length.js b/test/staging/upsert/Map/getOrInsertComputed/length.js deleted file mode 100644 index c440a5895a..0000000000 --- a/test/staging/upsert/Map/getOrInsertComputed/length.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// Copyright (C) 2024 Jonas Haukenes, Mathias Ness. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: proposal-upsert -description: | - Map.prototype.getOrInsert.length value and descriptor. -info: | - Map.prototype.getOrInsertComputed ( key , callbackfn ) - - 17 ECMAScript Standard Built-in Objects -includes: [propertyHelper.js] -features: [upsert] -flags: [noStrict] ----*/ -verifyProperty(Map.prototype.getOrInsertComputed, "length", { - value: 2, - writable: false, - enumerable: false, - configurable: true -}); - diff --git a/test/staging/upsert/Map/getOrInsertComputed/name.js b/test/staging/upsert/Map/getOrInsertComputed/name.js deleted file mode 100644 index e03adc274a..0000000000 --- a/test/staging/upsert/Map/getOrInsertComputed/name.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// Copyright (C) 2024 Jonas Haukenes, Mathias Ness. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: proposal-upsert -description: | - Map.prototype.getOrInsertComputed.name value and descriptor. -info: | - Map.prototype.getOrInsertComputed ( key , callbackfn ) - - 17 ECMAScript Standard Built-in Objects -includes: [propertyHelper.js] -features: [upsert] -flags: [noStrict] ----*/ -verifyProperty(Map.prototype.getOrInsertComputed, "name", { - value: "getOrInsertComputed", - writable: false, - enumerable: false, - configurable: true -}); - diff --git a/test/staging/upsert/Map/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js b/test/staging/upsert/Map/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js deleted file mode 100644 index 92790e0645..0000000000 --- a/test/staging/upsert/Map/getOrInsertComputed/returns-value-if-key-is-present-different-key-types.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// Copyright (C) 2024 Sune Eriksson Lianes, Mathias Ness. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: proposal-upsert -description: | - Returns the value set before getOrInsertComputed from the specified key on different types. -info: | - Map.prototype.getOrInsertComputed ( key , callbackfn ) - - ... - 5. For each Record { [[Key]], [[Value]] } p of M.[[MapData]], do - a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, return p.[[Value]]. - ... -features: [Symbol, arrow-function, upsert] -flags: [noStrict] ----*/ -var map = new Map(); - -map.set('bar', 0); -assert.sameValue(map.get('bar'), map.getOrInsertComputed('bar', () => 1)); -assert.sameValue(0, map.getOrInsertComputed('bar', () => 1)); - -map.set(1, 42); -assert.sameValue(map.get(1), map.getOrInsertComputed(1, () => 43)); -assert.sameValue(42, map.getOrInsertComputed(1, () => 43)); - -map.set(NaN, 1); -assert.sameValue(map.get(NaN), map.getOrInsertComputed(NaN, () => 2)); -assert.sameValue(1, map.getOrInsertComputed(NaN, () => 2)); - -var item = {}; -map.set(item, 2); -assert.sameValue(map.get(item), map.getOrInsertComputed(item, () => 3)); -assert.sameValue(2, map.getOrInsertComputed(item, () => 3)); - -item = []; -map.set(item, 3); -assert.sameValue(map.get(item), map.getOrInsertComputed(item, () => 4)); -assert.sameValue(3, map.getOrInsertComputed(item, () => 4)); - -item = Symbol('item'); -map.set(item, 4); -assert.sameValue(map.get(item), map.getOrInsertComputed(item, () => 5)); -assert.sameValue(4, map.getOrInsertComputed(item, () => 5)); - -item = null; -map.set(item, 5); -assert.sameValue(map.get(item), map.getOrInsertComputed(item, () => 6)); -assert.sameValue(5, map.getOrInsertComputed(item, () => 6)); - -item = undefined; -map.set(item, 6); -assert.sameValue(map.get(item), map.getOrInsertComputed(item, () => 7)); -assert.sameValue(6, map.getOrInsertComputed(item, () => 7)); -