Debian Codegraph @

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

raw
1 // |reftest| shell-option(--enable-upsert) skip-if(!Map.prototype.getOrInsert)
2 // Copyright (C) 2015 the V8 project authors. All rights reserved.
3 // Copyright (C) 2024 Jonas Haukenes. 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.getOrInsert ( key , value )
11
12 ...
13 3. Set key to CanonicalizeKeyedCollectionKey(key).
14 4. 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 5. Let p be the Record { [[Key]]: key, [[Value]]: value }.
17 6. Append p to M.[[MapData]].
18 ...
19 features: [Symbol]
20 ---*/
21
22 var map = new Map();
23 map.getOrInsert(-0, 42);
24 assertEq(map.get(0), 42);
25
26 map = new Map();
27 map.getOrInsert(+0, 43);
28 assertEq(map.get(0), 43);
29
30 reportCompare(0, 0);