]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | // WeakMap constructor with adder change. |
2 | ||
3 | var originalAdder = WeakMap.prototype.set; | |
4 | var counter = 0; | |
5 | ||
6 | WeakMap.prototype.set = function (key, value) { | |
7 | counter++; | |
8 | return originalAdder.call(this, key, value); | |
9 | }; | |
10 | ||
11 | var obj0 = {}; | |
12 | var obj1 = {}; | |
13 | var obj2 = []; | |
14 | var obj3 = new Date(); | |
15 | var obj4 = new Error(); | |
16 | var obj5 = JSON; | |
17 | ||
18 | var values = [ | |
19 | [ obj0, 0 ], | |
20 | [ obj1, 1 ], | |
21 | [ obj2, 2 ], | |
22 | [ obj3, 3 ], | |
23 | [ obj4, 4 ], | |
24 | [ obj5, 5 ], | |
25 | [ obj4, 4 ], | |
26 | [ obj3, 3 ], | |
27 | [ obj2, 2 ], | |
28 | [ obj1, 1 ], | |
29 | [ obj0, 0 ], | |
30 | ]; | |
31 | var map = new WeakMap(values); | |
32 | if (counter !== values.length) | |
33 | throw "Error: bad counter " + counter; | |
34 | ||
35 | WeakMap.prototype.set = function () { | |
36 | throw new Error("adder called"); | |
37 | }; | |
38 | ||
39 | var map = new WeakMap(); | |
40 | var map = new WeakMap([]); | |
41 | var error = null; | |
42 | try { | |
43 | var map = new WeakMap([ [0, 0] ]); | |
44 | } catch (e) { | |
45 | error = e; | |
46 | } | |
47 | if (!error) | |
48 | throw "Error: error not thrown"; | |
49 | if (String(error) !== "Error: adder called") | |
50 | throw "Error: bad error " + String(error); | |
51 |