]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/trailing-comma-in-patterns.js
1 function shouldBe(actual
, expected
) {
2 if (actual
!== expected
)
3 throw new Error('bad value: ' + actual
);
6 function iterator(array
) {
9 var original
= array
.values();
17 return original
.next();
22 return { done: true };
36 var iter
= iterator([1, 2, 3]);
38 shouldBe(iter
.reportNext(), 0);
39 shouldBe(iter
.reportReturn(), 1);
43 var iter
= iterator([1, 2, 3]);
45 shouldBe(iter
.reportNext(), 1);
46 shouldBe(iter
.reportReturn(), 1);
50 var iter
= iterator([1, 2, 3]);
52 shouldBe(iter
.reportNext(), 2);
53 shouldBe(iter
.reportReturn(), 1);
57 var iter
= iterator([1, 2, 3]);
59 shouldBe(iter
.reportNext(), 3);
60 shouldBe(iter
.reportReturn(), 1);
64 var iter
= iterator([1, 2, 3]);
66 shouldBe(iter
.reportNext(), 4);
67 shouldBe(iter
.reportReturn(), 0);
71 var iter
= iterator([1, 2, 3]);
73 shouldBe(iter
.reportNext(), 4);
74 shouldBe(iter
.reportReturn(), 0);
78 var iter
= iterator([1, 2, 3]);
80 shouldBe(iter
.reportNext(), 2);
81 shouldBe(iter
.reportReturn(), 1);
86 var iter
= iterator([1, 2, 3]);
88 shouldBe(iter
.reportNext(), 1);
89 shouldBe(iter
.reportReturn(), 1);
94 var iter
= iterator([1, 2, 3]);
96 shouldBe(iter
.reportNext(), 2);
97 shouldBe(iter
.reportReturn(), 1);
102 var iter
= iterator([1, 2, 3]);
103 var [a
,b
= 42,] = iter
;
104 shouldBe(iter
.reportNext(), 2);
105 shouldBe(iter
.reportReturn(), 1);
111 var {} = { Cocoa: 15, Cappuccino: 13 };
115 var {Cocoa
,} = { Cocoa: 15, Cappuccino: 13 };
120 var {Cocoa
= 'Cocoa',} = { Cocoa: 15, Cappuccino: 13 };
125 var {Cocoa
, Kilimanjaro
= 'Coffee'} = { Cocoa: 15, Cappuccino: 13 };
127 shouldBe(Kilimanjaro
, 'Coffee');
131 var {Cocoa
, Kilimanjaro
= 'Coffee'} = {};
132 shouldBe(Cocoa
, undefined);
133 shouldBe(Kilimanjaro
, 'Coffee');
137 var {Cocoa
, Kilimanjaro
= 'Coffee',} = { Cocoa: 15, Cappuccino: 13 };
139 shouldBe(Kilimanjaro
, 'Coffee');
142 function testSyntaxError(script
, message
) {
150 throw new Error("Expected syntax error not thrown");
152 if (String(error
) !== message
)
153 throw new Error("Bad error: " + String(error
));
156 testSyntaxError(String
.raw
`var {,} = {Cocoa: 15}`, String
.raw
`SyntaxError: Unexpected token ','. Expected a property name.`);
157 testSyntaxError(String
.raw
`var {,} = {}`, String
.raw
`SyntaxError: Unexpected token ','. Expected a property name.`);