]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/weak-map-constructor-adder.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / weak-map-constructor-adder.js
CommitLineData
ed1e77d3
A
1// WeakMap constructor with adder change.
2
3var originalAdder = WeakMap.prototype.set;
4var counter = 0;
5
6WeakMap.prototype.set = function (key, value) {
7 counter++;
8 return originalAdder.call(this, key, value);
9};
10
11var obj0 = {};
12var obj1 = {};
13var obj2 = [];
14var obj3 = new Date();
15var obj4 = new Error();
16var obj5 = JSON;
17
18var 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];
31var map = new WeakMap(values);
32if (counter !== values.length)
33 throw "Error: bad counter " + counter;
34
35WeakMap.prototype.set = function () {
36 throw new Error("adder called");
37};
38
39var map = new WeakMap();
40var map = new WeakMap([]);
41var error = null;
42try {
43 var map = new WeakMap([ [0, 0] ]);
44} catch (e) {
45 error = e;
46}
47if (!error)
48 throw "Error: error not thrown";
49if (String(error) !== "Error: adder called")
50 throw "Error: bad error " + String(error);
51