Debian Codegraph @

js/src/tests/non262/Map/getOrInsertComputed/append-new-values-normalizes-zero-key.js

raw
1 // |reftest| shell-option(--enable-upsert) skip-if(!Map.prototype.getOrInsertComputed)
2 // Copyright (C) 2015 the V8 project authors. All rights reserved.
3 // Copyright (C) 2024 Jonas Haukenes, Mathias Ness. All rights reserved.
4 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: proposal-upsert
7 description: >
8 Append a new value in the map normalizing +0 and -0.
9 info: |
10 Map.prototype.getOrInsertComputed ( key , callbackfn )
11
12 ...
13 4. Set key to CanonicalizeKeyedCollectionKey(key).
14 5. For each Record { [[Key]], [[Value]] } p of M.[[MapData]], do
15 a. If p.[[Key]] is not empty and SameValue(p.[[Key]], key) is true, return p.[[Value]].
16 6. Let value be ? Call(callbackfn, key).
17 7. Let p be the Record { [[Key]]: key, [[Value]]: value }.
18 8. Append p to M.[[MapData]].
19 ...
20 features: [Symbol, arrow-function]
21 ---*/
22
23 var map = new Map();
24 map.getOrInsertComputed(-0, () => 42);
25 assertEq(map.get(0), 42);
26
27 map = new Map();
28 map.getOrInsertComputed(+0, () => 43);
29 assertEq(map.get(0), 43);
30
31 reportCompare(0, 0);