Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80556 views
1
// This is modified from Mozilla Reflect.parse test suite (the file is located
2
// at js/src/tests/js1_8_5/extensions/reflect-parse.js in the source tree).
3
//
4
// Some notable changes:
5
// * Removed unsupported features (destructuring, let, comprehensions...).
6
// * Removed tests for E4X (ECMAScript for XML).
7
// * Removed everything related to builder.
8
// * Enclosed every 'Pattern' construct with a scope.
9
// * Removed the test for bug 632030 and bug 632024.
10
11
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
12
/*
13
* Any copyright is dedicated to the Public Domain.
14
* http://creativecommons.org/licenses/publicdomain/
15
*/
16
17
(function (exports) {
18
19
function testReflect(Reflect, Pattern) {
20
21
function program(elts) { return Pattern({ type: "Program", body: elts }) }
22
function exprStmt(expr) { return Pattern({ type: "ExpressionStatement", expression: expr }) }
23
function throwStmt(expr) { return Pattern({ type: "ThrowStatement", argument: expr }) }
24
function returnStmt(expr) { return Pattern({ type: "ReturnStatement", argument: expr }) }
25
function yieldExpr(expr) { return Pattern({ type: "YieldExpression", argument: expr }) }
26
function lit(val) { return Pattern({ type: "Literal", value: val }) }
27
var thisExpr = Pattern({ type: "ThisExpression" });
28
function funDecl(id, params, body) { return Pattern({ type: "FunctionDeclaration",
29
id: id,
30
params: params,
31
defaults: [],
32
body: body,
33
rest: null,
34
generator: false,
35
expression: false
36
}) }
37
function genFunDecl(id, params, body) { return Pattern({ type: "FunctionDeclaration",
38
id: id,
39
params: params,
40
defaults: [],
41
body: body,
42
rest: null,
43
generator: true,
44
expression: false
45
}) }
46
function declarator(id, init) { return Pattern({ type: "VariableDeclarator", id: id, init: init }) }
47
function varDecl(decls) { return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "var" }) }
48
function letDecl(decls) { return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "let" }) }
49
function constDecl(decls) { return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "const" }) }
50
function ident(name) { return Pattern({ type: "Identifier", name: name }) }
51
function dotExpr(obj, id) { return Pattern({ type: "MemberExpression", computed: false, object: obj, property: id }) }
52
function memExpr(obj, id) { return Pattern({ type: "MemberExpression", computed: true, object: obj, property: id }) }
53
function forStmt(init, test, update, body) { return Pattern({ type: "ForStatement", init: init, test: test, update: update, body: body }) }
54
function forInStmt(lhs, rhs, body) { return Pattern({ type: "ForInStatement", left: lhs, right: rhs, body: body, each: false }) }
55
function forEachInStmt(lhs, rhs, body) { return Pattern({ type: "ForInStatement", left: lhs, right: rhs, body: body, each: true }) }
56
function breakStmt(lab) { return Pattern({ type: "BreakStatement", label: lab }) }
57
function continueStmt(lab) { return Pattern({ type: "ContinueStatement", label: lab }) }
58
function blockStmt(body) { return Pattern({ type: "BlockStatement", body: body }) }
59
var emptyStmt = Pattern({ type: "EmptyStatement" });
60
function ifStmt(test, cons, alt) { return Pattern({ type: "IfStatement", test: test, alternate: alt, consequent: cons }) }
61
function labStmt(lab, stmt) { return Pattern({ type: "LabeledStatement", label: lab, body: stmt }) }
62
function withStmt(obj, stmt) { return Pattern({ type: "WithStatement", object: obj, body: stmt }) }
63
function whileStmt(test, stmt) { return Pattern({ type: "WhileStatement", test: test, body: stmt }) }
64
function doStmt(stmt, test) { return Pattern({ type: "DoWhileStatement", test: test, body: stmt }) }
65
function switchStmt(disc, cases) { return Pattern({ type: "SwitchStatement", discriminant: disc, cases: cases }) }
66
function caseClause(test, stmts) { return Pattern({ type: "SwitchCase", test: test, consequent: stmts }) }
67
function defaultClause(stmts) { return Pattern({ type: "SwitchCase", test: null, consequent: stmts }) }
68
function catchClause(id, guard, body) { if (guard) { return Pattern({ type: "GuardedCatchClause", param: id, guard: guard, body: body }) } else { return Pattern({ type: "CatchClause", param: id, body: body }) } }
69
function tryStmt(body, guarded, catches, fin) { return Pattern({ type: "TryStatement", block: body, guardedHandlers: guarded, handlers: catches, finalizer: fin }) }
70
function letStmt(head, body) { return Pattern({ type: "LetStatement", head: head, body: body }) }
71
function funExpr(id, args, body, gen) { return Pattern({ type: "FunctionExpression",
72
id: id,
73
params: args,
74
defaults: [],
75
body: body,
76
rest: null,
77
generator: false,
78
expression: false
79
}) }
80
function genFunExpr(id, args, body) { return Pattern({ type: "FunctionExpression",
81
id: id,
82
params: args,
83
defaults: [],
84
body: body,
85
rest: null,
86
generator: true,
87
expression: false
88
}) }
89
90
function unExpr(op, arg) { return Pattern({ type: "UnaryExpression", operator: op, argument: arg, prefix: true }) }
91
function binExpr(op, left, right) { return Pattern({ type: "BinaryExpression", operator: op, left: left, right: right }) }
92
function aExpr(op, left, right) { return Pattern({ type: "AssignmentExpression", operator: op, left: left, right: right }) }
93
function updExpr(op, arg, prefix) { return Pattern({ type: "UpdateExpression", operator: op, argument: arg, prefix: prefix }) }
94
function logExpr(op, left, right) { return Pattern({ type: "LogicalExpression", operator: op, left: left, right: right }) }
95
96
function condExpr(test, cons, alt) { return Pattern({ type: "ConditionalExpression", test: test, consequent: cons, alternate: alt }) }
97
function seqExpr(exprs) { return Pattern({ type: "SequenceExpression", expressions: exprs }) }
98
function newExpr(callee, args) { return Pattern({ type: "NewExpression", callee: callee, arguments: args }) }
99
function callExpr(callee, args) { return Pattern({ type: "CallExpression", callee: callee, arguments: args }) }
100
function arrExpr(elts) { return Pattern({ type: "ArrayExpression", elements: elts }) }
101
function objExpr(elts) { return Pattern({ type: "ObjectExpression", properties: elts }) }
102
function objProp(key, value, kind) { return Pattern({ type: "Property", key: key, value: value, kind: kind, method: false, shorthand: false, computed: false }) }
103
104
function arrPatt(elts) { return Pattern({ type: "ArrayPattern", elements: elts }) }
105
function objPatt(elts) { return Pattern({ type: "ObjectPattern", properties: elts }) }
106
107
function localSrc(src) { return "(function(){ " + src + " })" }
108
function localPatt(patt) { return program([exprStmt(funExpr(null, [], blockStmt([patt])))]) }
109
function blockSrc(src) { return "(function(){ { " + src + " } })" }
110
function blockPatt(patt) { return program([exprStmt(funExpr(null, [], blockStmt([blockStmt([patt])])))]) }
111
112
function assertBlockStmt(src, patt) {
113
blockPatt(patt).assert(Reflect.parse(blockSrc(src)));
114
}
115
116
function assertBlockExpr(src, patt) {
117
assertBlockStmt(src, exprStmt(patt));
118
}
119
120
function assertBlockDecl(src, patt, builder) {
121
blockPatt(patt).assert(Reflect.parse(blockSrc(src), {builder: builder}));
122
}
123
124
function assertLocalStmt(src, patt) {
125
localPatt(patt).assert(Reflect.parse(localSrc(src)));
126
}
127
128
function assertLocalExpr(src, patt) {
129
assertLocalStmt(src, exprStmt(patt));
130
}
131
132
function assertLocalDecl(src, patt) {
133
localPatt(patt).assert(Reflect.parse(localSrc(src)));
134
}
135
136
function assertGlobalStmt(src, patt, builder) {
137
program([patt]).assert(Reflect.parse(src, {builder: builder}));
138
}
139
140
function assertGlobalExpr(src, patt, builder) {
141
program([exprStmt(patt)]).assert(Reflect.parse(src, {builder: builder}));
142
//assertStmt(src, exprStmt(patt));
143
}
144
145
function assertGlobalDecl(src, patt) {
146
program([patt]).assert(Reflect.parse(src));
147
}
148
149
function assertProg(src, patt) {
150
program(patt).assert(Reflect.parse(src));
151
}
152
153
function assertStmt(src, patt) {
154
assertLocalStmt(src, patt);
155
assertGlobalStmt(src, patt);
156
assertBlockStmt(src, patt);
157
}
158
159
function assertExpr(src, patt) {
160
assertLocalExpr(src, patt);
161
assertGlobalExpr(src, patt);
162
assertBlockExpr(src, patt);
163
}
164
165
function assertDecl(src, patt) {
166
assertLocalDecl(src, patt);
167
assertGlobalDecl(src, patt);
168
assertBlockDecl(src, patt);
169
}
170
171
function assertError(src, errorType) {
172
try {
173
Reflect.parse(src);
174
} catch (e) {
175
return;
176
}
177
throw new Error("expected " + errorType.name + " for " + uneval(src));
178
}
179
180
181
// general tests
182
183
// NB: These are useful but for now jit-test doesn't do I/O reliably.
184
185
//program(_).assert(Reflect.parse(snarf('data/flapjax.txt')));
186
//program(_).assert(Reflect.parse(snarf('data/jquery-1.4.2.txt')));
187
//program(_).assert(Reflect.parse(snarf('data/prototype.js')));
188
//program(_).assert(Reflect.parse(snarf('data/dojo.js.uncompressed.js')));
189
//program(_).assert(Reflect.parse(snarf('data/mootools-1.2.4-core-nc.js')));
190
191
192
// declarations
193
194
assertDecl("var x = 1, y = 2, z = 3",
195
varDecl([declarator(ident("x"), lit(1)),
196
declarator(ident("y"), lit(2)),
197
declarator(ident("z"), lit(3))]));
198
assertDecl("var x, y, z",
199
varDecl([declarator(ident("x"), null),
200
declarator(ident("y"), null),
201
declarator(ident("z"), null)]));
202
assertDecl("function foo() { }",
203
funDecl(ident("foo"), [], blockStmt([])));
204
assertDecl("function foo() { return 42 }",
205
funDecl(ident("foo"), [], blockStmt([returnStmt(lit(42))])));
206
207
208
// Bug 591437: rebound args have their defs turned into uses
209
assertDecl("function f(a) { function a() { } }",
210
funDecl(ident("f"), [ident("a")], blockStmt([funDecl(ident("a"), [], blockStmt([]))])));
211
assertDecl("function f(a,b,c) { function b() { } }",
212
funDecl(ident("f"), [ident("a"),ident("b"),ident("c")], blockStmt([funDecl(ident("b"), [], blockStmt([]))])));
213
214
// expressions
215
216
assertExpr("true", lit(true));
217
assertExpr("false", lit(false));
218
assertExpr("42", lit(42));
219
assertExpr("(/asdf/)", lit(/asdf/));
220
assertExpr("this", thisExpr);
221
assertExpr("foo", ident("foo"));
222
assertExpr("foo.bar", dotExpr(ident("foo"), ident("bar")));
223
assertExpr("foo[bar]", memExpr(ident("foo"), ident("bar")));
224
assertExpr("(function(){})", funExpr(null, [], blockStmt([])));
225
assertExpr("(function f() {})", funExpr(ident("f"), [], blockStmt([])));
226
assertExpr("(function f(x,y,z) {})", funExpr(ident("f"), [ident("x"),ident("y"),ident("z")], blockStmt([])));
227
assertExpr("(++x)", updExpr("++", ident("x"), true));
228
assertExpr("(x++)", updExpr("++", ident("x"), false));
229
assertExpr("(+x)", unExpr("+", ident("x")));
230
assertExpr("(-x)", unExpr("-", ident("x")));
231
assertExpr("(!x)", unExpr("!", ident("x")));
232
assertExpr("(~x)", unExpr("~", ident("x")));
233
assertExpr("(delete x)", unExpr("delete", ident("x")));
234
assertExpr("(typeof x)", unExpr("typeof", ident("x")));
235
assertExpr("(void x)", unExpr("void", ident("x")));
236
assertExpr("(x == y)", binExpr("==", ident("x"), ident("y")));
237
assertExpr("(x != y)", binExpr("!=", ident("x"), ident("y")));
238
assertExpr("(x === y)", binExpr("===", ident("x"), ident("y")));
239
assertExpr("(x !== y)", binExpr("!==", ident("x"), ident("y")));
240
assertExpr("(x < y)", binExpr("<", ident("x"), ident("y")));
241
assertExpr("(x <= y)", binExpr("<=", ident("x"), ident("y")));
242
assertExpr("(x > y)", binExpr(">", ident("x"), ident("y")));
243
assertExpr("(x >= y)", binExpr(">=", ident("x"), ident("y")));
244
assertExpr("(x << y)", binExpr("<<", ident("x"), ident("y")));
245
assertExpr("(x >> y)", binExpr(">>", ident("x"), ident("y")));
246
assertExpr("(x >>> y)", binExpr(">>>", ident("x"), ident("y")));
247
assertExpr("(x + y)", binExpr("+", ident("x"), ident("y")));
248
assertExpr("(w + x + y + z)", binExpr("+", binExpr("+", binExpr("+", ident("w"), ident("x")), ident("y")), ident("z")));
249
assertExpr("(x - y)", binExpr("-", ident("x"), ident("y")));
250
assertExpr("(w - x - y - z)", binExpr("-", binExpr("-", binExpr("-", ident("w"), ident("x")), ident("y")), ident("z")));
251
assertExpr("(x * y)", binExpr("*", ident("x"), ident("y")));
252
assertExpr("(x / y)", binExpr("/", ident("x"), ident("y")));
253
assertExpr("(x % y)", binExpr("%", ident("x"), ident("y")));
254
assertExpr("(x | y)", binExpr("|", ident("x"), ident("y")));
255
assertExpr("(x ^ y)", binExpr("^", ident("x"), ident("y")));
256
assertExpr("(x & y)", binExpr("&", ident("x"), ident("y")));
257
assertExpr("(x in y)", binExpr("in", ident("x"), ident("y")));
258
assertExpr("(x instanceof y)", binExpr("instanceof", ident("x"), ident("y")));
259
assertExpr("(x = y)", aExpr("=", ident("x"), ident("y")));
260
assertExpr("(x += y)", aExpr("+=", ident("x"), ident("y")));
261
assertExpr("(x -= y)", aExpr("-=", ident("x"), ident("y")));
262
assertExpr("(x *= y)", aExpr("*=", ident("x"), ident("y")));
263
assertExpr("(x /= y)", aExpr("/=", ident("x"), ident("y")));
264
assertExpr("(x %= y)", aExpr("%=", ident("x"), ident("y")));
265
assertExpr("(x <<= y)", aExpr("<<=", ident("x"), ident("y")));
266
assertExpr("(x >>= y)", aExpr(">>=", ident("x"), ident("y")));
267
assertExpr("(x >>>= y)", aExpr(">>>=", ident("x"), ident("y")));
268
assertExpr("(x |= y)", aExpr("|=", ident("x"), ident("y")));
269
assertExpr("(x ^= y)", aExpr("^=", ident("x"), ident("y")));
270
assertExpr("(x &= y)", aExpr("&=", ident("x"), ident("y")));
271
assertExpr("(x || y)", logExpr("||", ident("x"), ident("y")));
272
assertExpr("(x && y)", logExpr("&&", ident("x"), ident("y")));
273
assertExpr("(w || x || y || z)", logExpr("||", logExpr("||", logExpr("||", ident("w"), ident("x")), ident("y")), ident("z")))
274
assertExpr("(x ? y : z)", condExpr(ident("x"), ident("y"), ident("z")));
275
assertExpr("(x,y)", seqExpr([ident("x"),ident("y")]))
276
assertExpr("(x,y,z)", seqExpr([ident("x"),ident("y"),ident("z")]))
277
assertExpr("(a,b,c,d,e,f,g)", seqExpr([ident("a"),ident("b"),ident("c"),ident("d"),ident("e"),ident("f"),ident("g")]));
278
assertExpr("(new Object)", newExpr(ident("Object"), []));
279
assertExpr("(new Object())", newExpr(ident("Object"), []));
280
assertExpr("(new Object(42))", newExpr(ident("Object"), [lit(42)]));
281
assertExpr("(new Object(1,2,3))", newExpr(ident("Object"), [lit(1),lit(2),lit(3)]));
282
assertExpr("(String())", callExpr(ident("String"), []));
283
assertExpr("(String(42))", callExpr(ident("String"), [lit(42)]));
284
assertExpr("(String(1,2,3))", callExpr(ident("String"), [lit(1),lit(2),lit(3)]));
285
assertExpr("[]", arrExpr([]));
286
assertExpr("[1]", arrExpr([lit(1)]));
287
assertExpr("[1,2]", arrExpr([lit(1),lit(2)]));
288
assertExpr("[1,2,3]", arrExpr([lit(1),lit(2),lit(3)]));
289
assertExpr("[1,,2,3]", arrExpr([lit(1),,lit(2),lit(3)]));
290
assertExpr("[1,,,2,3]", arrExpr([lit(1),,,lit(2),lit(3)]));
291
assertExpr("[1,,,2,,3]", arrExpr([lit(1),,,lit(2),,lit(3)]));
292
assertExpr("[1,,,2,,,3]", arrExpr([lit(1),,,lit(2),,,lit(3)]));
293
assertExpr("[,1,2,3]", arrExpr([,lit(1),lit(2),lit(3)]));
294
assertExpr("[,,1,2,3]", arrExpr([,,lit(1),lit(2),lit(3)]));
295
assertExpr("[,,,1,2,3]", arrExpr([,,,lit(1),lit(2),lit(3)]));
296
assertExpr("[,,,1,2,3,]", arrExpr([,,,lit(1),lit(2),lit(3)]));
297
assertExpr("[,,,1,2,3,,]", arrExpr([,,,lit(1),lit(2),lit(3),undefined]));
298
assertExpr("[,,,1,2,3,,,]", arrExpr([,,,lit(1),lit(2),lit(3),undefined,undefined]));
299
assertExpr("[,,,,,]", arrExpr([undefined,undefined,undefined,undefined,undefined]));
300
assertExpr("({})", objExpr([]));
301
assertExpr("({x:1})", objExpr([objProp(ident("x"), lit(1), "init")]));
302
assertExpr("({x:1, y:2})", objExpr([objProp(ident("x"), lit(1), "init"),
303
objProp(ident("y"), lit(2), "init")]));
304
assertExpr("({x:1, y:2, z:3})", objExpr([objProp(ident("x"), lit(1), "init"),
305
objProp(ident("y"), lit(2), "init"),
306
objProp(ident("z"), lit(3), "init") ]));
307
assertExpr("({x:1, 'y':2, z:3})", objExpr([objProp(ident("x"), lit(1), "init"),
308
objProp(lit("y"), lit(2), "init"),
309
objProp(ident("z"), lit(3), "init") ]));
310
assertExpr("({'x':1, 'y':2, z:3})", objExpr([objProp(lit("x"), lit(1), "init"),
311
objProp(lit("y"), lit(2), "init"),
312
objProp(ident("z"), lit(3), "init") ]));
313
assertExpr("({'x':1, 'y':2, 3:3})", objExpr([objProp(lit("x"), lit(1), "init"),
314
objProp(lit("y"), lit(2), "init"),
315
objProp(lit(3), lit(3), "init") ]));
316
317
// Bug 571617: eliminate constant-folding
318
assertExpr("2 + 3", binExpr("+", lit(2), lit(3)));
319
320
// Bug 632026: constant-folding
321
assertExpr("typeof(0?0:a)", unExpr("typeof", condExpr(lit(0), lit(0), ident("a"))));
322
323
// Bug 632056: constant-folding
324
program([exprStmt(ident("f")),
325
ifStmt(lit(1),
326
funDecl(ident("f"), [], blockStmt([])),
327
null)]).assert(Reflect.parse("f; if (1) function f(){}"));
328
329
// statements
330
331
assertStmt("throw 42", throwStmt(lit(42)));
332
assertStmt("for (;;) break", forStmt(null, null, null, breakStmt(null)));
333
assertStmt("for (x; y; z) break", forStmt(ident("x"), ident("y"), ident("z"), breakStmt(null)));
334
assertStmt("for (var x; y; z) break", forStmt(varDecl([declarator(ident("x"), null)]), ident("y"), ident("z"), breakStmt(null)));
335
assertStmt("for (var x = 42; y; z) break", forStmt(varDecl([declarator(ident("x"), lit(42))]), ident("y"), ident("z"), breakStmt(null)));
336
assertStmt("for (x; ; z) break", forStmt(ident("x"), null, ident("z"), breakStmt(null)));
337
assertStmt("for (var x; ; z) break", forStmt(varDecl([declarator(ident("x"), null)]), null, ident("z"), breakStmt(null)));
338
assertStmt("for (var x = 42; ; z) break", forStmt(varDecl([declarator(ident("x"), lit(42))]), null, ident("z"), breakStmt(null)));
339
assertStmt("for (x; y; ) break", forStmt(ident("x"), ident("y"), null, breakStmt(null)));
340
assertStmt("for (var x; y; ) break", forStmt(varDecl([declarator(ident("x"), null)]), ident("y"), null, breakStmt(null)));
341
assertStmt("for (var x = 42; y; ) break", forStmt(varDecl([declarator(ident("x"),lit(42))]), ident("y"), null, breakStmt(null)));
342
assertStmt("for (var x in y) break", forInStmt(varDecl([declarator(ident("x"),null)]), ident("y"), breakStmt(null)));
343
assertStmt("for (x in y) break", forInStmt(ident("x"), ident("y"), breakStmt(null)));
344
assertStmt("{ }", blockStmt([]));
345
assertStmt("{ throw 1; throw 2; throw 3; }", blockStmt([ throwStmt(lit(1)), throwStmt(lit(2)), throwStmt(lit(3))]));
346
assertStmt(";", emptyStmt);
347
assertStmt("if (foo) throw 42;", ifStmt(ident("foo"), throwStmt(lit(42)), null));
348
assertStmt("if (foo) throw 42; else true;", ifStmt(ident("foo"), throwStmt(lit(42)), exprStmt(lit(true))));
349
assertStmt("if (foo) { throw 1; throw 2; throw 3; }",
350
ifStmt(ident("foo"),
351
blockStmt([throwStmt(lit(1)), throwStmt(lit(2)), throwStmt(lit(3))]),
352
null));
353
assertStmt("if (foo) { throw 1; throw 2; throw 3; } else true;",
354
ifStmt(ident("foo"),
355
blockStmt([throwStmt(lit(1)), throwStmt(lit(2)), throwStmt(lit(3))]),
356
exprStmt(lit(true))));
357
assertStmt("foo: for(;;) break foo;", labStmt(ident("foo"), forStmt(null, null, null, breakStmt(ident("foo")))));
358
assertStmt("foo: for(;;) continue foo;", labStmt(ident("foo"), forStmt(null, null, null, continueStmt(ident("foo")))));
359
assertStmt("with (obj) { }", withStmt(ident("obj"), blockStmt([])));
360
assertStmt("with (obj) { obj; }", withStmt(ident("obj"), blockStmt([exprStmt(ident("obj"))])));
361
assertStmt("while (foo) { }", whileStmt(ident("foo"), blockStmt([])));
362
assertStmt("while (foo) { foo; }", whileStmt(ident("foo"), blockStmt([exprStmt(ident("foo"))])));
363
assertStmt("do { } while (foo);", doStmt(blockStmt([]), ident("foo")));
364
assertStmt("do { foo; } while (foo)", doStmt(blockStmt([exprStmt(ident("foo"))]), ident("foo")));
365
assertStmt("switch (foo) { case 1: 1; break; case 2: 2; break; default: 3; }",
366
switchStmt(ident("foo"),
367
[ caseClause(lit(1), [ exprStmt(lit(1)), breakStmt(null) ]),
368
caseClause(lit(2), [ exprStmt(lit(2)), breakStmt(null) ]),
369
defaultClause([ exprStmt(lit(3)) ]) ]));
370
assertStmt("switch (foo) { case 1: 1; break; case 2: 2; break; default: 3; case 42: 42; }",
371
switchStmt(ident("foo"),
372
[ caseClause(lit(1), [ exprStmt(lit(1)), breakStmt(null) ]),
373
caseClause(lit(2), [ exprStmt(lit(2)), breakStmt(null) ]),
374
defaultClause([ exprStmt(lit(3)) ]),
375
caseClause(lit(42), [ exprStmt(lit(42)) ]) ]));
376
assertStmt("try { } catch (e) { }",
377
tryStmt(blockStmt([]),
378
[],
379
[ catchClause(ident("e"), null, blockStmt([])) ],
380
null));
381
assertStmt("try { } catch (e) { } finally { }",
382
tryStmt(blockStmt([]),
383
[],
384
[ catchClause(ident("e"), null, blockStmt([])) ],
385
blockStmt([])));
386
assertStmt("try { } finally { }",
387
tryStmt(blockStmt([]),
388
[],
389
[],
390
blockStmt([])));
391
392
// redeclarations (TOK_NAME nodes with lexdef)
393
394
assertStmt("function f() { function g() { } function g() { } }",
395
funDecl(ident("f"), [], blockStmt([funDecl(ident("g"), [], blockStmt([])),
396
funDecl(ident("g"), [], blockStmt([]))])));
397
398
assertStmt("function f() { function g() { } function g() { return 42 } }",
399
funDecl(ident("f"), [], blockStmt([funDecl(ident("g"), [], blockStmt([])),
400
funDecl(ident("g"), [], blockStmt([returnStmt(lit(42))]))])));
401
402
assertStmt("function f() { var x = 42; var x = 43; }",
403
funDecl(ident("f"), [], blockStmt([varDecl([declarator(ident("x"),lit(42))]),
404
varDecl([declarator(ident("x"),lit(43))])])));
405
406
// getters and setters
407
408
assertExpr("({ get x() { return 42 } })",
409
objExpr([ objProp(ident("x"),
410
funExpr(null, [], blockStmt([returnStmt(lit(42))])),
411
"get" ) ]));
412
assertExpr("({ set x(v) { return 42 } })",
413
objExpr([ objProp(ident("x"),
414
funExpr(null, [ident("v")], blockStmt([returnStmt(lit(42))])),
415
"set" ) ]));
416
417
}
418
419
exports.testReflect = testReflect;
420
421
}(typeof exports === 'undefined' ? this : exports));
422
423