Debian Codegraph @

js/src/tests/non262/WeakMap/getOrInsertComputed/returns-value-if-key-is-not-present-object-key.js

raw
1 // |reftest| shell-option(--enable-upsert) skip-if(!WeakMap.prototype.getOrInsertComputed)
2 // Copyright (C) 2015 the V8 project authors. All rights reserved.
3 // Copyright (C) 2025 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 Returns the value from the specified Object key
9 info: |
10 WeakMap.prototype.getOrInsertComputed ( key, callbackfn )
11
12 ...
13 8. Let p be the Record { [[Key]]: key, [[Value]]: value }.
14 9. Append p to M.[[WeakMapData]].
15 10. Return value.
16 features: [WeakMap]
17 ---*/
18
19 var foo = {};
20 var bar = {};
21 var baz = [];
22 var map = new WeakMap();
23
24 assertEq(map.getOrInsertComputed(foo, () => 0), 0);
25
26 assertEq(map.getOrInsertComputed(bar, () => 1), 1);
27
28 assertEq(map.getOrInsertComputed(baz, () => 2), 2);
29
30 reportCompare(0, 0);