Move WeakMap.prototype.getOrInsert tests from staging to built-ins (#4476)

* Fix esid and remove noStrict

* Fixup length.js and returns-value-if-key-is-not-present-symbol-key.js
This commit is contained in:
Daniel Minor 2025-05-15 14:59:43 -04:00 committed by GitHub
parent 1049f77ba3
commit c2e3e37b68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 21 additions and 38 deletions

View File

@ -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.getOrInsert
description: |
Adds a value with an Object key if key is not already in the map.
info: |
@ -13,7 +13,6 @@ info: |
6. Append p to M.[[WeakMapData]].
...
features: [WeakMap, upsert]
flags: [noStrict]
---*/
var map = new WeakMap();
var foo = {};

View File

@ -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.getOrInsert
description: |
Adds a value with a Symbol key if key is not already in the map.
info: |
@ -13,7 +13,6 @@ info: |
6. Append p to M.[[WeakMapData]].
...
features: [Symbol, WeakMap, symbols-as-weakmap-keys, upsert]
flags: [noStrict]
---*/
var map = new WeakMap();
var foo = Symbol('a description');

View File

@ -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.getOrInsert
description: |
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
info: |
@ -13,7 +13,6 @@ info: |
2. Perform ? RequireInternalSlot(M, [[WeakMapData]]).
...
features: [upsert]
flags: [noStrict]
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.getOrInsert.call([], {}, 1);

View File

@ -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.getOrInsert
description: |
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
info: |
@ -13,7 +13,6 @@ info: |
2. Perform ? RequireInternalSlot(M, [[WeakMapData]]).
...
features: [Map, upsert]
flags: [noStrict]
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.getOrInsert.call(new Map(), {}, 1);

View File

@ -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.getOrInsert
description: |
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
info: |
@ -13,7 +13,6 @@ info: |
2. Perform ? RequireInternalSlot(M, [[WeakMapData]]).
...
features: [upsert]
flags: [noStrict]
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.getOrInsert.call({}, {}, 1);

View File

@ -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.getOrInsert
description: |
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
info: |
@ -13,7 +13,6 @@ info: |
2. Perform ? RequireInternalSlot(M, [[WeakMapData]]).
...
features: [Set, upsert]
flags: [noStrict]
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.getOrInsert.call(new Set(), {}, 1);

View File

@ -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.getOrInsert
description: |
Throws TypeError if `this` doesn't have a [[WeakMapData]] internal slot.
info: |
@ -13,7 +13,6 @@ info: |
2. Perform ? RequireInternalSlot(M, [[WeakMapData]]).
...
features: [upsert]
flags: [noStrict]
---*/
assert.throws(TypeError, function() {
WeakMap.prototype.getOrInsert.call(WeakMap.prototype, {}, 1);

View File

@ -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.getOrInsert
description: |
WeakMap.prototype.getOrInsert property descriptor
info: |
@ -11,7 +11,6 @@ info: |
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
features: [upsert]
flags: [noStrict]
---*/
assert.sameValue(
typeof WeakMap.prototype.getOrInsert,

View File

@ -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.getOrInsert
description: |
WeakMap.prototype.getOrInsert.length descriptor
info: |
@ -11,7 +11,6 @@ info: |
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
features: [upsert]
flags: [noStrict]
---*/
verifyProperty(WeakMap.prototype.getOrInsert, "length", {
value: 2,

View File

@ -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.getOrInsert
description: |
WeakMap.prototype.getOrInsert.name descriptor
info: |
@ -11,7 +11,6 @@ info: |
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
features: [upsert]
flags: [noStrict]
---*/
verifyProperty(Map.prototype.getOrInsert, "name", {
value: "getOrInsert",

View File

@ -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.getOrInsert
description: |
WeakMap.prototype.getOrInsert 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.getOrInsert),

View File

@ -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.getOrInsert
description: |
Returns the value given as parameter when key is not present.
info: |
@ -15,7 +15,6 @@ info: |
6. Append p to M.[[WeakMapData]].
7. Return value.
features: [WeakMap, upsert]
flags: [noStrict]
---*/
var foo = {};
var bar = {};

View File

@ -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.getOrInsert
description: |
Returns the value given as parameter when key is not present.
info: |
@ -15,17 +15,16 @@ info: |
6. Append p to M.[[WeakMapData]].
7. Return value.
features: [Symbol, WeakMap, symbols-as-weakmap-keys, upsert]
flags: [noStrict]
---*/
var foo = Symbol('a description');
var bar = Symbol('a description');
var baz = Symbol('different description');
var map = new WeakMap();
assert.sameValue(map.getOrInsert(foo, 0), 0, 'Regular symbol as key, added in constructor');
assert.sameValue(map.getOrInsert(foo, 0), 0);
assert.sameValue(map.getOrInsert(baz, 2), 2, 'Regular symbol as key, added with set()');
assert.sameValue(map.getOrInsert(bar, 1), 1, "Symbols with the same description don't overwrite each other");
assert.sameValue(map.getOrInsert(baz, 2), 2);
assert.sameValue(map.getOrInsert(bar, 1), 1);
assert.sameValue(map.getOrInsert(Symbol.hasInstance, 3), 3, 'Well-known symbol as key');
assert.sameValue(map.getOrInsert(Symbol.hasInstance, 3), 3);

View File

@ -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.getOrInsert
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 = {};

View File

@ -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.getOrInsert
description: |
Returns the value from the specified Symbol 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: [Symbol, WeakMap, symbols-as-weakmap-keys, upsert]
flags: [noStrict]
---*/
var foo = Symbol('a description');
var bar = Symbol('a description');

View File

@ -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.getOrInsert
description: |
Throws a TypeError if `this` is not an Object.
info: |
@ -12,7 +12,6 @@ info: |
2. Perform ? RequireInternalSlot(M, [[WeakMapData]])
...
features: [Symbol, upsert]
flags: [noStrict]
---*/
var m = new WeakMap();

View File

@ -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.getOrInsert
description: |
Throws TypeError if key cannot be held weakly.
info: |
@ -12,7 +12,6 @@ info: |
3. If CanBeHeldWeakly(key) is false, throw a TypeError exception.
...
features: [Symbol, WeakMap, upsert]
flags: [noStrict]
---*/
var s = new WeakMap();