Upsert testing plan
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
thisis a Set - [x] Throw a type error if
thisis a WeakMap - [x] Throw a type error if
thisis does not have a [[MapData]] slot - [x] Verify properties of
getOrInsert - [x] Verify
lengthofgetOrInsert - [x] Verify
nameofgetOrInsert - [x] Verify
getOrInsertis not a constructor - [x] Check return value when
keyis not present - [x] Check return value when
keyis present - [x] Check return value for normalized
key - [x] Throw a type error if
thisis 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
thisis undefined and the callback receives exactly one argument - [x] Throw a type error if
thisis a Set - [x] Throw a type error if
thisis a WeakMap - [x] Throw a type error if
thisis does not have a [[MapData]] slot - [x] Verify properties of
getOrInsertComputed - [x] Verify
lengthofgetOrInsertComputed - [x] Verify
nameofgetOrInsertComputed - [x] Verify
getOrInsertComputedis 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
getOrInsertComputedif the callback throws - [x] Verify state of the Map after
getOrInsertComputedif 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
keyis not present - [x] Check return value when
keyis present - [x] Check return value for normalized
key - [x] Throw a type error if
thisis 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
thisdoes not have a [[WeakMapData]] slot - [x] Verify properties of
getOrInsert - [x] Verify
lengthofgetOrInsert - [x] Verify
nameofgetOrInsert - [x] Verify
getOrInsertis not a constructor - [x] Check return value when object
keyis not present - [x] Check return value when symbol
keyis not present - [x] Check return value when object
keyis present - [x] Check return value when symbol
keyis present - [x] Throw a type error if
thisis 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
thisis undefined and the callback receives exactly one argument - [ ] Throw TypeError if
thisdoes not have a [[WeakMapData]] slot - [ ] Verify properties of
getOrInsertComputed - [ ] Verify
lengthofgetOrInsertComputed - [ ] Verify
nameofgetOrInsertComputed - [ ] Verify
getOrInsertComputedis 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
getOrInsertComputedif the callback throws - [ ] Verify state of the WeakMap after
getOrInsertComputedif 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
keyis not present - [ ] Check return value when symbol
keyis not present - [ ] Check return value when object
keyis present - [ ] Check return value when symbol
keyis present - [ ] Throw a type error if
thisis not an Object - [ ] Throw a type error if key is not weakly holdable
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)
In getOrInsertComputed, check the state of the map after catching an exception thrown by the callback (both after mutating and non-mutating).
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?
yep
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.
Map.prototype.getOrInsert tests were merged in https://github.com/tc39/test262/pull/4472
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.
Map.prototype.getOrInsertComputed tests: #4491
WeakMap.prototype.getOrInsert tests were merged in: https://github.com/tc39/test262/pull/4476
WeakMap.prototype.getOrInsertComputed tests: https://github.com/tc39/test262/pull/4520
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.