test262 icon indicating copy to clipboard operation
test262 copied to clipboard

Upsert testing plan

Open dminor opened this issue 7 months ago • 10 comments

Proposal: https://github.com/tc39/proposal-upsert Rendered specification text: https://tc39.es/proposal-upsert/ Implementations: engine262, SpiderMonkey

Map.getOrInsert

  • [x] Appending a new value normalizes -0 and +0
  • [x] Appending new values
  • [x] Appending new values with missing key
  • [x] Throw a type error if this is a Set
  • [x] Throw a type error if this is a WeakMap
  • [x] Throw a type error if this is does not have a [[MapData]] slot
  • [x] Verify properties of getOrInsert
  • [x] Verify length of getOrInsert
  • [x] Verify name of getOrInsert
  • [x] Verify getOrInsert is not a constructor
  • [x] Check return value when key is not present
  • [x] Check return value when key is present
  • [x] Check return value for normalized key
  • [x] Throw a type error if this is not an Object

Map.getOrInsertComputed

  • [x] Appending a new value normalizes -0 and +0
  • [x] Appending new values
  • [x] Appending new values with missing key
  • [x] Check abrupt completion from callback function
  • [x] Verify behaviour for callable callback function
  • [x] Verify that callback function is not called if key is present
  • [x] Verify that this is undefined and the callback receives exactly one argument
  • [x] Throw a type error if this is a Set
  • [x] Throw a type error if this is a WeakMap
  • [x] Throw a type error if this is does not have a [[MapData]] slot
  • [x] Verify properties of getOrInsertComputed
  • [x] Verify length of getOrInsertComputed
  • [x] Verify name of getOrInsertComputed
  • [x] Verify getOrInsertComputed is not a constructor
  • [x] Verify that a TypeError is thrown if callback function is not callable
  • [x] Verify that a TypeError is thrown if callback function is not callable even when key is present
  • [x] Verify that mutation of value corresponding to the key during callback function execution is overwritten
  • [x] Verify state of the Map after getOrInsertComputed if the callback throws
  • [x] Verify state of the Map after getOrInsertComputed if the callback mutates the Map and then throws
  • [x] Map does not contain the key, but the callback inserts it, then returns a different value from the one it inserted
  • [x] Check return value when key is not present
  • [x] Check return value when key is present
  • [x] Check return value for normalized key
  • [x] Throw a type error if this is not an Object

WeakMap.getOrInsert

  • [x] Add object key if key is not present in the map
  • [x] Add symbol key if key is not present in the map
  • [x] Throw TypeError if this does not have a [[WeakMapData]] slot
  • [x] Verify properties of getOrInsert
  • [x] Verify length of getOrInsert
  • [x] Verify name of getOrInsert
  • [x] Verify getOrInsert is not a constructor
  • [x] Check return value when object key is not present
  • [x] Check return value when symbol key is not present
  • [x] Check return value when object key is present
  • [x] Check return value when symbol key is present
  • [x] Throw a type error if this is not an Object
  • [x] Throw a type error if key is not weakly holdable

WeakMap.getOrInsertComputed

  • [ ] Add object key if key is not present in the map
  • [ ] Add symbol key if key is not present in the map
  • [ ] Appending new values with missing key
  • [ ] Check abrupt completion from callback function
  • [ ] Verify that callback function is not called if key is present
  • [ ] Verify that this is undefined and the callback receives exactly one argument
  • [ ] Throw TypeError if this does not have a [[WeakMapData]] slot
  • [ ] Verify properties of getOrInsertComputed
  • [ ] Verify length of getOrInsertComputed
  • [ ] Verify name of getOrInsertComputed
  • [ ] Verify getOrInsertComputed is not a constructor
  • [ ] Verify that a TypeError is thrown if callback function is not callable
  • [ ] Verify that a TypeError is thrown if callback function is not callable even when key is present
  • [ ] Verify that mutation of value corresponding to the key during callback function execution is overwritten
  • [ ] Verify state of the WeakMap after getOrInsertComputed if the callback throws
  • [ ] Verify state of the WeakMap after getOrInsertComputed if the callback mutates the WeakMap and then throws
  • [ ] Map does not contain the key, but the callback inserts it, then returns a different value from the one it inserted
  • [ ] Check return value when object key is not present
  • [ ] Check return value when symbol key is not present
  • [ ] Check return value when object key is present
  • [ ] Check return value when symbol key is present
  • [ ] Throw a type error if this is not an Object
  • [ ] Throw a type error if key is not weakly holdable

dminor avatar May 06 '25 14:05 dminor

For the callback cases, maybe also check that this is undefined and that it receives exactly one argument (since in other built-in callbacks the object that the callback-taking method is called on would be passed as this).

Verify that a TypeError is thrown if callback function is not callable

This needs to check that is also throws if the key is already present (thus it does not try to call the callback).


(sorry I didn't read the tests, these are just drive-by comments about this list)

nicolo-ribaudo avatar May 06 '25 16:05 nicolo-ribaudo

In getOrInsertComputed, check the state of the map after catching an exception thrown by the callback (both after mutating and non-mutating).

michaelficarra avatar May 06 '25 20:05 michaelficarra

In getOrInsertComputed, check the state of the map after catching an exception thrown by the callback (both after mutating and non-mutating).

Checking the state would mean to check that the keys and values are what we expect, with what we expect depending on whether the callback mutates the map or not?

dminor avatar May 07 '25 15:05 dminor

yep

michaelficarra avatar May 07 '25 15:05 michaelficarra

Thanks for putting this together! I'd suggest one more case for getOrInsertComputed: the map does not contain the key, but the callback inserts it, then returns a different value from the one it inserted.

ptomato avatar May 08 '25 16:05 ptomato

Map.prototype.getOrInsert tests were merged in https://github.com/tc39/test262/pull/4472

dminor avatar May 13 '25 13:05 dminor

Thanks for putting this together! I'd suggest one more case for getOrInsertComputed: the map does not contain the key, but the callback inserts it, then returns a different value from the one it inserted.

Turns out there was already coverage for this case in overwrites-mutation-from-callback.js.

dminor avatar May 15 '25 17:05 dminor

Map.prototype.getOrInsertComputed tests: #4491

michaelficarra avatar May 19 '25 23:05 michaelficarra

WeakMap.prototype.getOrInsert tests were merged in: https://github.com/tc39/test262/pull/4476

dminor avatar Jun 09 '25 13:06 dminor

WeakMap.prototype.getOrInsertComputed tests: https://github.com/tc39/test262/pull/4520

dminor avatar Jun 09 '25 18:06 dminor

WeakMap.prototype.getOrInsertComputed test: #4578 Add check to verify that callbackfn has not been called if the key cannot be held weakly.

WeakMap.prototype.getOrInsertComputed test: #4579 Add missing feature, symbols-as-weakmap-keys.

johauke avatar Sep 14 '25 16:09 johauke