Debian Codegraph @

js/src/tests/non262/WeakMap/getOrInsertComputed/adds-value-different-callbackfn.js

raw
1 // |reftest| shell-option(--enable-upsert) skip-if(!WeakMap.prototype.getOrInsertComputed)
2 // Copyright (C) 2025 Jonas Haukenes, Mathias Ness. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: proposal-upsert
6 description: >
7 Does not throw if `callbackfn` is callable.
8 info: |
9 WeakMap.prototype.getOrInsertComputed ( key , callbackfn )
10
11 ...
12 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
13 ...
14 features: [arrow-function]
15 ---*/
16
17 var bar = {};
18 var baz = {};
19 var foo = {};
20 var foobar = {};
21 var foobarbaz = {};
22
23 var m = new WeakMap();
24
25 assertEq(
26 m.getOrInsertComputed(bar, function() {return 1;})
27 , 1);
28 assertEq(m.get(bar), 1);
29
30
31 assertEq(
32 m.getOrInsertComputed(baz, () => 2)
33 , 2);
34 assertEq(m.get(baz), 2);
35
36
37 function three() {return 3;}
38
39 assertEq(
40 m.getOrInsertComputed(foo, three)
41 , 3);
42 assertEq(m.get(foo), 3);
43
44
45 assertEq(
46 m.getOrInsertComputed(foobar, new Function())
47 , undefined);
48 assertEq(m.get(foobar), undefined);
49
50
51 assertEq(
52 m.getOrInsertComputed(foobarbaz, (function() {return 5;}).bind(m))
53 , 5);
54 assertEq(m.get(foobarbaz), 5);
55
56
57 reportCompare(0, 0);