]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/set-constructor.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / set-constructor.js
CommitLineData
ed1e77d3
A
1// Set constructor behaviors.
2
3if (typeof Set !== 'function')
4 throw "Error: bad value" + typeof Set;
5
6function testCallTypeError(item) {
7 var error = null;
8 try {
9 var set = Set(item);
10 } catch (e) {
11 error = e;
12 }
13 if (!error)
14 throw "Error: error not thrown";
15 if (String(error) !== "TypeError: Set cannot be called as a function")
16 throw "Error: bad error " + String(error);
17}
18
19var pass = [
20 [ null, 0 ],
21 [ undefined, 0 ],
22 [ "Cocoa", 4 ],
23 [ [0, 1, 2, 3, 4], 5 ],
24 [ [0, 0, 0, 1, 0], 2 ],
25 [ ["A", "B", "A"], 2 ],
26 [ new String("cocoa"), 3 ],
27 [ new String("Cocoa"), 4 ],
28 [ new Set([0,1,2,3,4]), 5],
29 [ new Set([1,1,1,1]), 1],
30 [ new Map([[1, 2],[1, 2]]), 1],
31 [ new Map([[1, 2],[2, 2]]), 2],
32];
33
34for (var pair of pass) {
35 var set = new Set(pair[0]);
36 if (set.size !== pair[1])
37 throw "Error: bad set size " + set.size;
38 testCallTypeError(pair[0]);
39}
40
41function testTypeError(item) {
42 var error = null;
43 try {
44 var set = new Set(item);
45 } catch (e) {
46 error = e;
47 }
48 if (!error)
49 throw "Error: error not thrown";
50 if (String(error) !== "TypeError: Type error")
51 throw "Error: bad error " + String(error);
52}
53
54var nonIterable = [
55 42,
56 Symbol("Cappuccino"),
57 true,
58 false,
59 {},
60 new Date(),
61 new Error(),
62 Object(Symbol("Matcha")),
63 (function () { }),
64];
65
66for (var item of nonIterable) {
67 testTypeError(item);
68 testCallTypeError(item);
69}