From 6a73fa8f114611269ce4442e8f19a31239cb3827 Mon Sep 17 00:00:00 2001 From: Daniel Minor Date: Mon, 9 Jun 2025 09:45:43 -0400 Subject: [PATCH] Move WeakMap.prototype.getOrInsertComputed tests from staging to built-ins --- .../adds-object-element.js | 3 +- .../adds-symbol-element.js | 3 +- .../adds-value-different-callbackfn.js | 5 +- .../getOrInsertComputed/callbackfn-throws.js | 5 +- .../check-callback-fn-args.js | 24 ++++++++ .../check-state-after-callback-fn-throws.js | 61 +++++++++++++++++++ ...-not-evaluate-callbackfn-if-key-present.js | 29 +++++---- ...ot-have-weakmapdata-internal-slot-array.js | 7 +-- ...-not-have-weakmapdata-internal-slot-map.js | 7 +-- ...t-have-weakmapdata-internal-slot-object.js | 7 +-- ...-not-have-weakmapdata-internal-slot-set.js | 7 +-- ...mapdata-internal-slot-weakmap-prototype.js | 7 +-- .../getOrInsertComputed.js | 13 +--- .../getOrInsertComputed/not-a-constructor.js | 6 +- .../not-a-function-callbackfn-throws.js | 26 ++++---- .../overwrites-mutation-from-callbackfn.js | 5 +- ...-value-if-key-is-not-present-object-key.js | 3 +- ...-value-if-key-is-not-present-symbol-key.js | 3 +- ...urns-value-if-key-is-present-object-key.js | 3 +- ...urns-value-if-key-is-present-symbol-key.js | 3 +- .../this-not-object-throw.js | 5 +- .../throw-if-key-cannot-be-held-weakly.js | 3 +- .../WeakMap/getOrInsertComputed/length.js | 22 ------- .../WeakMap/getOrInsertComputed/name.js | 22 ------- 24 files changed, 153 insertions(+), 126 deletions(-) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/adds-object-element.js (94%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/adds-symbol-element.js (95%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/adds-value-different-callbackfn.js (92%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/callbackfn-throws.js (88%) create mode 100644 test/built-ins/WeakMap/prototype/getOrInsertComputed/check-callback-fn-args.js create mode 100644 test/built-ins/WeakMap/prototype/getOrInsertComputed/check-state-after-callback-fn-throws.js rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js (52%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-array.js (86%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-map.js (86%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-object.js (86%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-set.js (85%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js (86%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/getOrInsertComputed.js (66%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/not-a-constructor.js (89%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/not-a-function-callbackfn-throws.js (58%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/overwrites-mutation-from-callbackfn.js (93%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/returns-value-if-key-is-not-present-object-key.js (93%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/returns-value-if-key-is-not-present-symbol-key.js (95%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/returns-value-if-key-is-present-object-key.js (94%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/returns-value-if-key-is-present-symbol-key.js (96%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/this-not-object-throw.js (93%) rename test/{staging/upsert/WeakMap => built-ins/WeakMap/prototype}/getOrInsertComputed/throw-if-key-cannot-be-held-weakly.js (95%) delete mode 100644 test/staging/upsert/WeakMap/getOrInsertComputed/length.js delete mode 100644 test/staging/upsert/WeakMap/getOrInsertComputed/name.js diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/adds-object-element.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/adds-object-element.js similarity index 94% rename from test/staging/upsert/WeakMap/getOrInsertComputed/adds-object-element.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/adds-object-element.js index 97972faa62..245ef184af 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/adds-object-element.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/adds-object-element.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Adds a value with an Object key if key is not already in the map. info: | @@ -13,7 +13,6 @@ info: | 9. Append p to M.[[WeakMapData]]. ... features: [WeakMap, upsert] -flags: [noStrict] ---*/ var map = new WeakMap(); var foo = {}; diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/adds-symbol-element.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/adds-symbol-element.js similarity index 95% rename from test/staging/upsert/WeakMap/getOrInsertComputed/adds-symbol-element.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/adds-symbol-element.js index 118f7a3285..7a027d02fe 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/adds-symbol-element.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/adds-symbol-element.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Adds a value with a Symbol key if key is not already in the map. info: | @@ -13,7 +13,6 @@ info: | 9. Append p to M.[[WeakMapData]]. ... features: [Symbol, WeakMap, symbols-as-weakmap-keys, upsert] -flags: [noStrict] ---*/ var map = new WeakMap(); var foo = Symbol('a description'); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/adds-value-different-callbackfn.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/adds-value-different-callbackfn.js similarity index 92% rename from test/staging/upsert/WeakMap/getOrInsertComputed/adds-value-different-callbackfn.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/adds-value-different-callbackfn.js index d52746d33c..b50bc87316 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/adds-value-different-callbackfn.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/adds-value-different-callbackfn.js @@ -1,7 +1,7 @@ // Copyright (C) 2025 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-weakmap.prototype.getorinsertcomputed description: | Does not throw if `callbackfn` is callable. info: | @@ -10,8 +10,7 @@ info: | ... 3. If IsCallable(callbackfn) is false, throw a TypeError exception. ... -features: [arrow-function, upsert] -flags: [noStrict] +features: [arrow-function, upsert, WeakMap] ---*/ var bar = {}; var baz = {}; diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/callbackfn-throws.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/callbackfn-throws.js similarity index 88% rename from test/staging/upsert/WeakMap/getOrInsertComputed/callbackfn-throws.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/callbackfn-throws.js index d5e0d89dd3..5cca558fe7 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/callbackfn-throws.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/callbackfn-throws.js @@ -1,7 +1,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-weakmap.prototype.getorinsertcomputed description: | WeakMap.getOrInsertComputed throws when callbackfn throws return if abrubt completion Call(callbackfn, key) info: | @@ -10,8 +10,7 @@ info: | ... 6. Let value be ? Call(callbackfn, undefined, key). ... -features: [upsert] -flags: [noStrict] +features: [upsert, WeakMap] ---*/ var map = new WeakMap(); diff --git a/test/built-ins/WeakMap/prototype/getOrInsertComputed/check-callback-fn-args.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/check-callback-fn-args.js new file mode 100644 index 0000000000..aa1bad4816 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/check-callback-fn-args.js @@ -0,0 +1,24 @@ +// Copyright (C) 2025 Daniel Minor. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.getorinsertcomputed +description: | + Check that callbackfn receives undefined for this and exactly one argument. +info: | + WeakMap.prototype.getOrInsertComputed ( key , callbackfn ) + + ... + + 6. Let value be ? Call(callbackfn, key). + ... +features: [upsert, Symbol, WeakMap] +flags: [onlyStrict] +---*/ +var map = new WeakMap(); +var symbol = Symbol('a description'); + +map.getOrInsertComputed(symbol, function () { + assert.sameValue(this, undefined); + assert.sameValue(arguments.length, 1); + assert.sameValue(arguments[0], symbol); +}); diff --git a/test/built-ins/WeakMap/prototype/getOrInsertComputed/check-state-after-callback-fn-throws.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/check-state-after-callback-fn-throws.js new file mode 100644 index 0000000000..27cb2c6641 --- /dev/null +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/check-state-after-callback-fn-throws.js @@ -0,0 +1,61 @@ +// Copyright (C) 2025 Daniel Minor. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-weakmap.prototype.getorinsertcomputed +description: | + Check state after callback function throws +info: | + WeakMap.prototype.getOrInsertComputed ( key , callbackfn ) + + ... + + 6. Let value be ? Call(callbackfn, key). + ... +features: [upsert, WeakMap, Symbol] +---*/ +var map = new WeakMap(); +const obj0 = {}; +const obj1 = {}; +const obj2 = {}; +const obj3 = {}; +map.set(obj0, 'zero'); +map.set(obj1, 'one'); +map.set(obj2, 'two'); + +assert.throws(Error, function() { + map.getOrInsertComputed(Symbol('3'), function() { + throw new Error('throw in callback'); + }) +}); + +// Check the values after throwing in callbackfn. +assert.sameValue(map.get(obj0), 'zero'); +assert.sameValue(map.get(obj1), 'one'); +assert.sameValue(map.get(obj2), 'two'); +assert.sameValue(map.has(obj3), false); + +assert.throws(Error, function() { + map.getOrInsertComputed(obj3, function() { + map.set(obj1, 'mutated'); + throw new Error('throw in callback'); + }) +}); + +// Check the values after throwing in callbackfn, with mutation. +assert.sameValue(map.get(obj0), 'zero'); +assert.sameValue(map.get(obj1), 'mutated'); +assert.sameValue(map.get(obj2), 'two'); +assert.sameValue(map.has(obj3), false); + +assert.throws(Error, function() { + map.getOrInsertComputed(obj3, function() { + map.set(obj3, 'mutated'); + throw new Error('throw in callback'); + }) +}); + +// Check the values after throwing in callbackfn, with mutation. +assert.sameValue(map.get(obj0), 'zero'); +assert.sameValue(map.get(obj1), 'mutated'); +assert.sameValue(map.get(obj2), 'two'); +assert.sameValue(map.get(obj3), 'mutated'); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js similarity index 52% rename from test/staging/upsert/WeakMap/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js index f3d403cbe3..dcec2c3106 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-evaluate-callbackfn-if-key-present.js +++ b/test/built-ins/WeakMap/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-weakmap.prototype.getorinsertcomputed description: | Does not evaluate the callback function if the key is already in the map. info: | @@ -13,25 +13,30 @@ info: | 6. Let value be ? Call(callbackfn, undefined, « key »). ... features: [WeakMap, upsert] -flags: [noStrict] ---*/ -var map = new Map([ - [1, 0] -]); +const obj1 = {}; +const obj2 = {}; +const obj3 = {}; +const obj4 = {}; +const map = new WeakMap(); +map.set(obj1, 0); +let callbackCalls = 0; function callback() { - throw new Error('Callbackfn should not be evaluated if key is present'); + callbackCalls += 1; + throw new Error('Callbackfn should not be evaluated if key is present'); } -assert.sameValue(map.getOrInsertComputed(1, callback), 0); +assert.sameValue(map.getOrInsertComputed(obj1, callback), 0); -map.set(2, 1); -assert.sameValue(map.getOrInsertComputed(2, callback), 1); +map.set(obj2, 1); +assert.sameValue(map.getOrInsertComputed(obj2, callback), 1); -map.set(3, 2); -assert.sameValue(map.getOrInsertComputed(3, callback), 2); +map.set(obj3, 2); +assert.sameValue(map.getOrInsertComputed(obj3, callback), 2); assert.throws(Error, function() { - map.getOrInsertComputed(4, callback) + map.getOrInsertComputed(obj4, callback) }, Error); +assert.sameValue(callbackCalls, 1); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-array.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-array.js similarity index 86% rename from test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-array.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-array.js index 5bee7861fd..bf2f92873e 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-array.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-array.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. info: | @@ -11,15 +11,14 @@ info: | ... 2. Perform ? RequireInternalSlot(M, [[WeakMapData]]). ... -features: [upsert] -flags: [noStrict] +features: [upsert, WeakMap] ---*/ assert.throws(TypeError, function() { WeakMap.prototype.getOrInsertComputed.call([], {}, () => 1); }); +var map = new WeakMap(); assert.throws(TypeError, function() { - var map = new WeakMap(); map.getOrInsertComputed.call([], {}, () => 1); }); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-map.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-map.js similarity index 86% rename from test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-map.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-map.js index 1b26135d33..a8a8835b1b 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-map.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-map.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. info: | @@ -11,15 +11,14 @@ info: | ... 2. Perform ? RequireInternalSlot(M, [[WeakMapData]]). ... -features: [Map, upsert] -flags: [noStrict] +features: [WeakMap, upsert] ---*/ assert.throws(TypeError, function() { WeakMap.prototype.getOrInsertComputed.call(new Map(), {}, () => 1); }); +var map = new WeakMap(); assert.throws(TypeError, function() { - var map = new WeakMap(); map.getOrInsertComputed.call(new Map(), {}, () => 1); }); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-object.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-object.js similarity index 86% rename from test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-object.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-object.js index e7266603ae..1f70ef0334 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-object.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-object.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. info: | @@ -11,15 +11,14 @@ info: | ... 2. Perform ? RequireInternalSlot(M, [[WeakMapData]]). ... -features: [upsert] -flags: [noStrict] +features: [upsert, WeakMap] ---*/ assert.throws(TypeError, function() { WeakMap.prototype.getOrInsertComputed.call({}, {}, () => 1); }); +var map = new WeakMap(); assert.throws(TypeError, function() { - var map = new WeakMap(); map.getOrInsertComputed.call({}, {}, () => 1); }); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-set.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-set.js similarity index 85% rename from test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-set.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-set.js index 0b09ca986c..d4e8e59875 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-set.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-set.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. info: | @@ -11,15 +11,14 @@ info: | ... 2. Perform ? RequireInternalSlot(M, [[WeakMapData]]). ... -features: [Set, upsert] -flags: [noStrict] +features: [Set, WeakMap, upsert] ---*/ assert.throws(TypeError, function() { WeakMap.prototype.getOrInsertComputed.call(new Set(), {}, () => 1); }); +var map = new WeakMap(); assert.throws(TypeError, function() { - var map = new WeakMap(); map.getOrInsertComputed.call(new Set(), {}, () => 1); }); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js similarity index 86% rename from test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js index 6e24218b80..d4c5c4b976 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/does-not-have-weakmapdata-internal-slot-weakmap-prototype.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot. info: | @@ -11,15 +11,14 @@ info: | ... 2. Perform ? RequireInternalSlot(M, [[WeakMapData]]). ... -features: [upsert] -flags: [noStrict] +features: [WeakMap, upsert] ---*/ assert.throws(TypeError, function() { WeakMap.prototype.getOrInsertComputed.call(WeakMap.prototype, {}, () => 1); }); +var map = new WeakMap(); assert.throws(TypeError, function() { - var map = new WeakMap(); map.getOrInsertComputed.call(WeakMap.prototype, {}, () => 1); }); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/getOrInsertComputed.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/getOrInsertComputed.js similarity index 66% rename from test/staging/upsert/WeakMap/getOrInsertComputed/getOrInsertComputed.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/getOrInsertComputed.js index 3e6f966737..4cd56e7320 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/getOrInsertComputed.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/getOrInsertComputed.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | WeakMap.prototype.getOrInsertComputed property descriptor info: | @@ -10,16 +10,9 @@ info: | 17 ECMAScript Standard Built-in Objects includes: [propertyHelper.js] -features: [upsert] -flags: [noStrict] +features: [WeakMap, upsert] ---*/ -assert.sameValue( - typeof WeakMap.prototype.getOrInsertComputed, - 'function', - 'typeof WeakMap.prototype.getOrInsertComputed is "function"' -); - -verifyProperty(WeakMap.prototype, "getOrInsertComputed", { +verifyPrimordialCallableProperty(WeakMap.prototype, "getOrInsertComputed", "getOrInsertComputed", 2, { value: WeakMap.prototype.getOrInsertComputed, writable: true, enumerable: false, diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/not-a-constructor.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/not-a-constructor.js similarity index 89% rename from test/staging/upsert/WeakMap/getOrInsertComputed/not-a-constructor.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/not-a-constructor.js index 6700293b9f..52d2c7bea1 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/not-a-constructor.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/not-a-constructor.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | WeakMap.prototype.getOrInsertComputed does not implement [[Construct]], is not new-able info: | @@ -19,7 +19,6 @@ info: | ... includes: [isConstructor.js] features: [Reflect.construct, WeakMap, arrow-function, upsert] -flags: [noStrict] ---*/ assert.sameValue( isConstructor(WeakMap.prototype.getOrInsertComputed), @@ -27,7 +26,8 @@ assert.sameValue( 'isConstructor(WeakMap.prototype.getOrInsertComputed) must return false' ); +let wm = new WeakMap(); assert.throws(TypeError, () => { - let wm = new WeakMap(); new wm.getOrInsertComputed({}, () => 1); + new wm.getOrInsertComputed({}, () => 1); }); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/not-a-function-callbackfn-throws.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/not-a-function-callbackfn-throws.js similarity index 58% rename from test/staging/upsert/WeakMap/getOrInsertComputed/not-a-function-callbackfn-throws.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/not-a-function-callbackfn-throws.js index 22056cfbc5..7ec7f61947 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/not-a-function-callbackfn-throws.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/not-a-function-callbackfn-throws.js @@ -2,7 +2,7 @@ // Copyright (C) 2025 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-weakmap.prototype.getorinsertcomputed description: | Throws a TypeError if `callbackfn` is not callable. info: | @@ -11,41 +11,45 @@ info: | ... 3. If IsCallable(callbackfn) is false, throw a TypeError exception. ... -features: [Symbol, upsert] -flags: [noStrict] +features: [WeakMap, Symbol, upsert] ---*/ var bar = {}; var m = new WeakMap(); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, bar, 1); + m.getOrInsertComputed(bar, 1); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, bar, ""); + m.getOrInsertComputed(bar, ""); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, bar, true); + m.getOrInsertComputed(bar, true); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, bar, undefined); + m.getOrInsertComputed(bar, undefined); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, bar, null); + m.getOrInsertComputed(bar, null); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, bar, {}); + m.getOrInsertComputed(bar, {}); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, bar, []); + m.getOrInsertComputed(bar, []); }); assert.throws(TypeError, function () { - m.getOrInsertComputed.call(m, bar, Symbol()); + m.getOrInsertComputed(bar, Symbol()); }); +// Check that it also throws if the key is already present (thus it does not try to call the callback) +m.set(bar, "foo"); +assert.throws(TypeError, function () { + m.getOrInsertComputed(bar, 1); +}); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/overwrites-mutation-from-callbackfn.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/overwrites-mutation-from-callbackfn.js similarity index 93% rename from test/staging/upsert/WeakMap/getOrInsertComputed/overwrites-mutation-from-callbackfn.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/overwrites-mutation-from-callbackfn.js index 68fa107a0f..b140ee76dc 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/overwrites-mutation-from-callbackfn.js +++ b/test/built-ins/WeakMap/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-weakmap.prototype.getorinsertcomputed description: | If the callbackfn inserts a value on the given key, the value is overwritten. info: | @@ -16,8 +16,7 @@ info: | 8. Let p be the Record { [[Key]]: key, [[Value]]: value }. 9. Append p to M.[[WeakMapData]]. ... -features: [upsert] -flags: [noStrict] +features: [WeakMap, upsert] ---*/ var map = new WeakMap(); var foo = {}; diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-not-present-object-key.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-object-key.js similarity index 93% rename from test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-not-present-object-key.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-object-key.js index f35cf5065d..7dff332759 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-not-present-object-key.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-object-key.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Returns the value from the specified Object key info: | @@ -13,7 +13,6 @@ info: | 9. Append p to M.[[WeakMapData]]. 10. Return value. features: [WeakMap, upsert] -flags: [noStrict] ---*/ var foo = {}; var bar = {}; diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-not-present-symbol-key.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-symbol-key.js similarity index 95% rename from test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-not-present-symbol-key.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-symbol-key.js index dd943fe0ba..43c14df9c7 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-not-present-symbol-key.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-not-present-symbol-key.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Returns the value from the specified Symbol key info: | @@ -13,7 +13,6 @@ info: | 9. Append p to M.[[WeakMapData]]. 10. Return value. features: [Symbol, WeakMap, symbols-as-weakmap-keys, upsert] -flags: [noStrict] ---*/ var foo = Symbol('a description'); var bar = Symbol('a description'); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-present-object-key.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-present-object-key.js similarity index 94% rename from test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-present-object-key.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-present-object-key.js index 403c6ed52f..2239b5a8cb 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-present-object-key.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-present-object-key.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Returns the value from the specified Object key info: | @@ -13,7 +13,6 @@ info: | a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, return p.[[Value]]. ... features: [WeakMap, upsert] -flags: [noStrict] ---*/ var foo = {}; var bar = {}; diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-present-symbol-key.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-present-symbol-key.js similarity index 96% rename from test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-present-symbol-key.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-present-symbol-key.js index 86a4278b07..413d6f82b5 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/returns-value-if-key-is-present-symbol-key.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/returns-value-if-key-is-present-symbol-key.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Returns the value from the specified Symbol key info: | @@ -14,7 +14,6 @@ info: | 10. Return value. features: [Symbol, WeakMap, symbols-as-weakmap-keys, upsert] -flags: [noStrict] ---*/ var foo = Symbol('a description'); var bar = Symbol('a description'); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/this-not-object-throw.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/this-not-object-throw.js similarity index 93% rename from test/staging/upsert/WeakMap/getOrInsertComputed/this-not-object-throw.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/this-not-object-throw.js index d7bf484dce..0effb219f5 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/this-not-object-throw.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/this-not-object-throw.js @@ -2,7 +2,7 @@ // Copyright (C) 2025 Jonas Haukenes, Sune Eriksson Lianes. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: proposal-upsert +esid: sec-weakmap.prototype.getorinsertcomputed description: | Throws a TypeError if `this` is not an Object. info: | @@ -11,8 +11,7 @@ info: | 1. Let M be the this value 2. Perform ? RequireInternalSlot(M, [[WeakMapData]]) ... -features: [Symbol, upsert] -flags: [noStrict] +features: [WeakMap, Symbol, upsert] ---*/ var m = new WeakMap(); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/throw-if-key-cannot-be-held-weakly.js b/test/built-ins/WeakMap/prototype/getOrInsertComputed/throw-if-key-cannot-be-held-weakly.js similarity index 95% rename from test/staging/upsert/WeakMap/getOrInsertComputed/throw-if-key-cannot-be-held-weakly.js rename to test/built-ins/WeakMap/prototype/getOrInsertComputed/throw-if-key-cannot-be-held-weakly.js index 39473522b7..23762965b7 100644 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/throw-if-key-cannot-be-held-weakly.js +++ b/test/built-ins/WeakMap/prototype/getOrInsertComputed/throw-if-key-cannot-be-held-weakly.js @@ -2,7 +2,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-weakmap.prototype.getorinsertcomputed description: | Throws TypeError if key cannot be held weakly. info: | @@ -12,7 +12,6 @@ info: | 4. If CanBeHeldWeakly(_key_) is *false*, throw a *TypeError* exception. ... features: [Symbol, WeakMap, upsert] -flags: [noStrict] ---*/ var s = new WeakMap(); diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/length.js b/test/staging/upsert/WeakMap/getOrInsertComputed/length.js deleted file mode 100644 index 171182ed16..0000000000 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/length.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// Copyright (C) 2025 Jonas Haukenes. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: proposal-upsert -description: | - WeakMap.prototype.getOrInsertComputed.length descriptor -info: | - WeakMap.prototype.getOrInsertComputed ( key, callbackfn ) - - 17 ECMAScript Standard Built-in Objects -includes: [propertyHelper.js] -features: [upsert] -flags: [noStrict] ----*/ -verifyProperty(WeakMap.prototype.getOrInsertComputed, "length", { - value: 2, - writable: false, - enumerable: false, - configurable: true -}); - diff --git a/test/staging/upsert/WeakMap/getOrInsertComputed/name.js b/test/staging/upsert/WeakMap/getOrInsertComputed/name.js deleted file mode 100644 index 200c615638..0000000000 --- a/test/staging/upsert/WeakMap/getOrInsertComputed/name.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// Copyright (C) 2025 Jonas Haukenes. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: proposal-upsert -description: | - WeakMap.prototype.getOrInsertComputed.name descriptor -info: | - WeakMap.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 -}); -