Web Inspector: Type bubbles missing for computed methods and methods on object literals
[WebKit-https.git] / LayoutTests / inspector / model / parse-script-syntax-tree.html
1 <!doctype html>
2 <html>
3 <head>
4 <script type="text/javascript" src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script>
6 function test()
7 {
8     function makeNode(text, isExpression)
9     {
10         var script = new WebInspector.Script(1, new WebInspector.TextRange(0, text.length));
11         var scriptSyntaxTree = new WebInspector.ScriptSyntaxTree(text, script);
12         var syntaxTree = scriptSyntaxTree._syntaxTree;
13
14         InspectorTest.assert(scriptSyntaxTree.parsedSuccessfully, "ScriptSyntaxTree should be able to parse: \"" + text + "\"");
15         InspectorTest.assert(syntaxTree.type === WebInspector.ScriptSyntaxTree.NodeType.Program, "Should be program.");
16         InspectorTest.assert(syntaxTree.body.length === 1, "Calling makeNode should return one node in the program.");
17         if (isExpression) {
18             InspectorTest.assert(syntaxTree.body[0].type === WebInspector.ScriptSyntaxTree.NodeType.ExpressionStatement);
19             return syntaxTree.body[0].expression;
20         } else
21             return syntaxTree.body[0];
22     }
23
24     var node = null;
25
26     node = makeNode("x = 20;", true);
27     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.AssignmentExpression);
28     InspectorTest.assert(node.left);
29     InspectorTest.assert(node.left.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
30     InspectorTest.assert(node.right);
31     InspectorTest.assert(node.right.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
32     InspectorTest.assert(node.operator === "=");
33     node = makeNode("[x, y] = foo;", true);
34     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.AssignmentExpression);
35     InspectorTest.assert(node.left);
36     InspectorTest.assert(node.left.type === WebInspector.ScriptSyntaxTree.NodeType.ArrayPattern);
37     InspectorTest.assert(node.left.elements.length === 2);
38     InspectorTest.assert(node.left.elements[0].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
39     InspectorTest.assert(node.left.elements[0].name === "x");
40     InspectorTest.assert(node.left.elements[1].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
41     InspectorTest.assert(node.left.elements[1].name === "y");
42     node = makeNode("x += 20;", true);
43     InspectorTest.assert(node.operator === "+=");
44     node = makeNode("x -= 20;", true);
45     InspectorTest.assert(node.operator === "-=");
46     InspectorTest.log("passed AssignmentExpression");
47
48     node = makeNode("[1, 2]", true);
49     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ArrayExpression);
50     InspectorTest.assert(Array.isArray(node.elements));
51     InspectorTest.assert(node.elements.length === 2);
52     InspectorTest.assert(node.elements[0].type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
53     InspectorTest.assert(node.elements[1].type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
54     InspectorTest.log("passed ArrayExpression");
55     
56     node = makeNode("{foo();}", false);
57     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
58     InspectorTest.assert(node.body);
59     InspectorTest.assert(node.body.length === 1);
60     InspectorTest.assert(node.body[0].expression.type === WebInspector.ScriptSyntaxTree.NodeType.CallExpression);
61     InspectorTest.log("passed BlockStatement");
62
63     node = makeNode("2 + 2", true);
64     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.BinaryExpression);
65     InspectorTest.assert(node.left);
66     InspectorTest.assert(node.right);
67     InspectorTest.assert(node.operator === "+");
68     node = makeNode("2 - 2", true);
69     InspectorTest.assert(node.operator === "-");
70     node = makeNode("2 * 2", true);
71     InspectorTest.assert(node.operator === "*");
72     node = makeNode("2 / 2", true);
73     InspectorTest.assert(node.operator === "/");
74     node = makeNode("2 % 2", true);
75     InspectorTest.assert(node.operator === "%");
76     node = makeNode("2 | 2", true);
77     InspectorTest.assert(node.operator === "|");
78     node = makeNode("2 ^ 2", true);
79     InspectorTest.assert(node.operator === "^");
80     node = makeNode("2 == 2", true);
81     InspectorTest.assert(node.operator === "==");
82     node = makeNode("2 === 2", true);
83     InspectorTest.assert(node.operator === "===");
84     InspectorTest.log("passed BinaryExpression");
85
86     node = makeNode("label:while(true) {break label;}", false);
87     InspectorTest.assert(node.body.body.body[0].type === WebInspector.ScriptSyntaxTree.NodeType.BreakStatement);
88     InspectorTest.assert(node.body.body.body[0].label.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
89     InspectorTest.assert(node.body.body.body[0].label.name === "label");
90     InspectorTest.log("passed BreakStatement");
91
92     node = makeNode("foo(20, 25)", true);
93     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.CallExpression);
94     InspectorTest.assert(node.arguments);
95     InspectorTest.assert(node.arguments.length === 2);
96     InspectorTest.assert(node.arguments[0].type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
97     InspectorTest.assert(node.arguments[1].type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
98     InspectorTest.log("passed CallExpression");
99
100     node = makeNode("try {} catch(e) {} ", false);
101     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.TryStatement);
102     InspectorTest.log("passed TryStatement");
103     InspectorTest.assert(node.handler.type === WebInspector.ScriptSyntaxTree.NodeType.CatchClause);
104     InspectorTest.log("passed CatchClause");
105
106     node = makeNode("foo ? bar : baz;", true);
107     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ConditionalExpression);
108     InspectorTest.assert(node.test);
109     InspectorTest.assert(node.consequent);
110     InspectorTest.assert(node.alternate);
111     InspectorTest.assert(node.test.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
112     InspectorTest.assert(node.consequent.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
113     InspectorTest.assert(node.alternate.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
114     InspectorTest.log("passed ConditionalExpression");
115     
116     node = makeNode("label:while(true) {continue label;}", false);
117     InspectorTest.assert(node.body.body.body[0].type === WebInspector.ScriptSyntaxTree.NodeType.ContinueStatement);
118     InspectorTest.assert(node.body.body.body[0].label.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
119     InspectorTest.assert(node.body.body.body[0].label.name === "label");
120     InspectorTest.log("passed ContinueStatement");
121
122     node = makeNode("do{}while(true);", false);
123     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.DoWhileStatement);
124     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
125     InspectorTest.assert(node.body.body.length === 0);
126     InspectorTest.assert(node.test);
127     InspectorTest.assert(node.test.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
128     InspectorTest.log("passed DoWhileStatement");
129
130     node = makeNode("debugger;", false);
131     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.DebuggerStatement);
132     InspectorTest.log("passed DebuggerStatement");
133
134     node = makeNode(";", false);
135     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.EmptyStatement);
136     InspectorTest.log("passed EmptyStatement");
137
138     node = makeNode("2 + 2", false);
139     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ExpressionStatement);
140     InspectorTest.assert(node.expression);
141     InspectorTest.assert(node.expression.type === WebInspector.ScriptSyntaxTree.NodeType.BinaryExpression);
142     InspectorTest.log("passed ExpressionStatement");
143
144     node = makeNode("for(x = 0;x < 20;x++){}", false);
145     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ForStatement);
146     InspectorTest.assert(node.init);
147     InspectorTest.assert(node.init.type === WebInspector.ScriptSyntaxTree.NodeType.AssignmentExpression);
148     InspectorTest.assert(node.test);
149     InspectorTest.assert(node.test.type === WebInspector.ScriptSyntaxTree.NodeType.BinaryExpression);
150     InspectorTest.assert(node.update);
151     InspectorTest.assert(node.update.type === WebInspector.ScriptSyntaxTree.NodeType.UpdateExpression);
152     InspectorTest.assert(node.body);
153     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
154     node = makeNode("for(x = 0;x < 20;x++);", false);
155     InspectorTest.assert(node.body);
156     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.EmptyStatement);
157     InspectorTest.log("passed ForStatement");
158
159     node = makeNode("for(var x in {}){}", false);
160     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ForInStatement);
161     InspectorTest.assert(node.left);
162     InspectorTest.assert(node.left.type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclaration);
163     InspectorTest.assert(node.right);
164     InspectorTest.assert(node.right.type === WebInspector.ScriptSyntaxTree.NodeType.ObjectExpression);
165     InspectorTest.assert(node.body);
166     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
167     node = makeNode("for(var x in {});", false);
168     InspectorTest.assert(node.body);
169     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.EmptyStatement);
170     InspectorTest.log("passed ForInStatement");
171
172     node = makeNode("for(var x of {});", false);
173     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ForOfStatement);
174     InspectorTest.assert(node.left);
175     InspectorTest.assert(node.left.type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclaration);
176     InspectorTest.assert(node.right);
177     InspectorTest.assert(node.right.type === WebInspector.ScriptSyntaxTree.NodeType.ObjectExpression);
178     InspectorTest.assert(node.body);
179     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.EmptyStatement);
180     node = makeNode("for(var {x} of {});", false);
181     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ForOfStatement);
182     InspectorTest.assert(node.left);
183     InspectorTest.assert(node.left.type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclaration);
184     InspectorTest.assert(node.left.declarations[0].id.type === WebInspector.ScriptSyntaxTree.NodeType.ObjectPattern);
185     InspectorTest.assert(node.left.declarations[0].id.properties[0].value.name === "x");
186     InspectorTest.log("passed ForOfStatement");
187
188     node = makeNode("function foo(x,y){}", false);
189     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.FunctionDeclaration);
190     InspectorTest.assert(node.params);
191     InspectorTest.assert(node.params.length === 2);
192     InspectorTest.assert(node.params[0].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
193     InspectorTest.assert(node.params[1].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
194     InspectorTest.assert(node.body);
195     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
196     node = makeNode("x = {get foo(){return 20}}", true);
197     InspectorTest.assert(node.right.properties[0].value.type === WebInspector.ScriptSyntaxTree.NodeType.FunctionExpression);
198     node = makeNode("x = {set foo(x){return 20}}", true);
199     InspectorTest.assert(node.right.properties[0].value.type === WebInspector.ScriptSyntaxTree.NodeType.FunctionExpression);
200     InspectorTest.log("passed FunctionDeclaration");
201
202     node = makeNode("foo(function(x,y){})", true);
203     InspectorTest.assert(node.arguments[0].type === WebInspector.ScriptSyntaxTree.NodeType.FunctionExpression);
204     InspectorTest.assert(node.arguments[0].params);
205     InspectorTest.assert(node.arguments[0].params.length === 2);
206     InspectorTest.assert(node.arguments[0].params[0].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
207     InspectorTest.assert(node.arguments[0].params[1].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
208     InspectorTest.assert(node.arguments[0].body);
209     InspectorTest.assert(node.arguments[0].body.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
210     InspectorTest.log("passed FunctionExpression");
211
212     node = makeNode("foo;", true);
213     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
214     InspectorTest.assert(node.name);
215     InspectorTest.assert(node.name === "foo");
216     InspectorTest.log("passed Identifier");
217
218     node = makeNode("if (true) baz; else bar;", false);
219     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.IfStatement);
220     InspectorTest.assert(node.test);
221     InspectorTest.assert(node.test.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
222     InspectorTest.assert(node.consequent);
223     InspectorTest.assert(node.consequent.type === WebInspector.ScriptSyntaxTree.NodeType.ExpressionStatement);
224     InspectorTest.assert(node.alternate);
225     InspectorTest.assert(node.alternate.type === WebInspector.ScriptSyntaxTree.NodeType.ExpressionStatement);
226     InspectorTest.log("passed IfStatement");
227
228     node = makeNode("true;", true);
229     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
230     InspectorTest.assert(node.value === true);
231     InspectorTest.assert(node.raw === "true");
232     node = makeNode("false;", true);
233     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
234     InspectorTest.assert(node.value === false);
235     InspectorTest.assert(node.raw === "false");
236     node = makeNode("20;", true);
237     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
238     InspectorTest.assert(node.value === 20);
239     InspectorTest.assert(node.raw === "20");
240     node = makeNode("'20';", true);
241     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
242     InspectorTest.assert(node.value === '20');
243     InspectorTest.assert(node.raw === "'20'");
244     node = makeNode("null;", true);
245     InspectorTest.assert(node.value === null);
246     InspectorTest.assert(node.raw === "null");
247     node = makeNode("/regex/gi;", true);
248     InspectorTest.assert(node.value instanceof RegExp);
249     InspectorTest.assert(node.value.toString() === "/regex/gi");
250     InspectorTest.assert(node.raw === "/regex/gi");
251     node = makeNode("0x10", true);
252     InspectorTest.assert(node.value === 0x10);
253     InspectorTest.assert(node.raw === "0x10");
254     node = makeNode("0777", true);
255     InspectorTest.assert(node.value === 0777);
256     InspectorTest.assert(node.raw === "0777");
257     node = makeNode("\"a\"", true);
258     InspectorTest.assert(node.value === "a");
259     InspectorTest.assert(node.raw === "\"a\"");
260     InspectorTest.log("passed Literal");
261
262     node = makeNode("label:while(true)20;", false);
263     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.LabeledStatement);
264     InspectorTest.assert(node.label);
265     InspectorTest.assert(node.label.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
266     InspectorTest.assert(node.label.name === "label");
267     InspectorTest.log("passed LabeledStatement");
268
269     node = makeNode("x && 20", true);
270     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.LogicalExpression);
271     InspectorTest.assert(node.left);
272     InspectorTest.assert(node.left.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
273     InspectorTest.assert(node.right);
274     InspectorTest.assert(node.right.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
275     //InspectorTest.assert(node.operator === "&&");
276     node = makeNode("x || 20", true);
277     InspectorTest.assert(node.operator === "||");
278     InspectorTest.log("passed LogicalExpression");
279
280     node = makeNode("foo[20]", true);
281     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.MemberExpression);
282     InspectorTest.assert(node.computed);
283     InspectorTest.assert(node.object);
284     InspectorTest.assert(node.object.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
285     InspectorTest.assert(node.property);
286     InspectorTest.assert(node.property.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
287     node = makeNode("foo.bar", true);
288     InspectorTest.assert(!node.computed);
289     InspectorTest.assert(node.property.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
290     InspectorTest.log("passed MemberExpression");
291
292     node = makeNode("new Foo(20)", true);
293     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.NewExpression);
294     InspectorTest.assert(node.callee);
295     InspectorTest.assert(node.callee.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
296     InspectorTest.assert(node.arguments);
297     InspectorTest.assert(node.arguments.length === 1);
298     node = makeNode("new Foo", true);
299     InspectorTest.assert(node.arguments);
300     InspectorTest.assert(node.arguments.length === 0);
301     InspectorTest.log("passed NewExpression");
302
303     node = makeNode("x = {foo:bar};", true);
304     InspectorTest.assert(node.right.type === WebInspector.ScriptSyntaxTree.NodeType.ObjectExpression);
305     InspectorTest.assert(node.right.properties);
306     InspectorTest.assert(node.right.properties.length === 1);
307     InspectorTest.log("passed ObjectExpression");
308
309     // Program is tested in makeNode
310
311     node = makeNode("x = {foo:20};", true);
312     InspectorTest.assert(node.right.properties[0].type === WebInspector.ScriptSyntaxTree.NodeType.Property);
313     InspectorTest.assert(node.right.properties[0].key);
314     InspectorTest.assert(node.right.properties[0].key.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
315     InspectorTest.assert(node.right.properties[0].value);
316     InspectorTest.assert(node.right.properties[0].value.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
317     node = makeNode("x = {'foo':20};", true);
318     InspectorTest.assert(node.right.properties[0].key);
319     InspectorTest.assert(node.right.properties[0].key.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
320     InspectorTest.log("passed Property");
321
322     node = makeNode("function foo() { return 20; }", false);
323     InspectorTest.assert(node.body.body[0].type === WebInspector.ScriptSyntaxTree.NodeType.ReturnStatement);
324     InspectorTest.assert(node.body.body[0].argument.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
325     node = makeNode("function foo() { return; }", false);
326     InspectorTest.assert(node.body.body[0].argument === null);
327     InspectorTest.log("passed ReturnStatement");
328
329     node = makeNode("(x, y)", true);
330     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.SequenceExpression);
331     InspectorTest.assert(node.expressions);
332     InspectorTest.assert(node.expressions.length === 2);
333     InspectorTest.assert(node.expressions[0].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
334     InspectorTest.assert(node.expressions[1].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
335     InspectorTest.log("passed SequenceExpression");
336
337     node = makeNode("switch(x){case y:break;}", false);
338     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.SwitchStatement);
339     InspectorTest.assert(node.discriminant.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
340     InspectorTest.log("passed SwitchStatement");
341     InspectorTest.assert(node.cases[0].type === WebInspector.ScriptSyntaxTree.NodeType.SwitchCase);
342     InspectorTest.assert(node.cases[0].test.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
343     InspectorTest.assert(node.cases[0].consequent);
344     InspectorTest.assert(Array.isArray(node.cases[0].consequent));
345     InspectorTest.assert(node.cases[0].consequent.length === 1);
346     InspectorTest.log("passed SwitchCase");
347
348     node = makeNode("this;", true);
349     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ThisExpression);
350     InspectorTest.log("passed ThisExpression");
351
352     node = makeNode("throw new Error;", false);
353     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ThrowStatement);
354     InspectorTest.assert(node.argument);
355     InspectorTest.assert(node.argument.type === WebInspector.ScriptSyntaxTree.NodeType.NewExpression);
356     InspectorTest.log("passed ThrowStatement");
357
358     node = makeNode("!foo;", true);
359     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.UnaryExpression);
360     InspectorTest.assert(node.argument);
361     InspectorTest.assert(node.argument.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
362     InspectorTest.assert(node.operator === "!");
363     node = makeNode("~foo;", true);
364     InspectorTest.assert(node.operator === "~");
365     node = makeNode("-foo;", true);
366     InspectorTest.assert(node.operator === "-");
367     InspectorTest.log("passed UnaryExpression");
368
369     node = makeNode("foo++;", true);
370     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.UpdateExpression);
371     InspectorTest.assert(node.argument);
372     InspectorTest.assert(node.argument.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
373     InspectorTest.assert(node.operator === "++");
374     InspectorTest.assert(node.prefix === false);
375     node = makeNode("++foo;", true);
376     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.UpdateExpression);
377     InspectorTest.assert(node.argument);
378     InspectorTest.assert(node.argument.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
379     InspectorTest.assert(node.prefix === true);
380     InspectorTest.assert(node.operator === "++");
381     node = makeNode("--foo;", true);
382     InspectorTest.assert(node.operator === "--");
383     node = makeNode("foo--;", true);
384     InspectorTest.assert(node.operator === "--");
385     InspectorTest.log("passed UpdateExpression");
386
387     node = makeNode("var foo = 20;", false);
388     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclaration);
389     InspectorTest.assert(node.declarations);
390     InspectorTest.assert(node.declarations.length === 1);
391     InspectorTest.log("passed VariableDeclaration");
392     InspectorTest.assert(node.declarations[0].type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclarator);
393     InspectorTest.assert(node.declarations[0].id);
394     InspectorTest.assert(node.declarations[0].id.type);
395     InspectorTest.assert(node.declarations[0].id.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
396     InspectorTest.assert(node.declarations[0].init);
397     InspectorTest.assert(node.declarations[0].init.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
398     node = makeNode("var foo;", false);
399     InspectorTest.assert(node.declarations[0].init === null);
400     node = makeNode("var {x, y: foo} = bar;", false);
401     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclaration);
402     InspectorTest.assert(node.declarations.length === 1);
403     node = node.declarations[0].id;
404     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ObjectPattern);
405     InspectorTest.assert(node.properties.length === 2);
406     InspectorTest.assert(node.properties[0].type === WebInspector.ScriptSyntaxTree.NodeType.Property);
407     InspectorTest.assert(node.properties[0].key.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
408     InspectorTest.assert(node.properties[0].value.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
409     InspectorTest.assert(node.properties[0].key.name === node.properties[0].value.name && node.properties[0].key.name === "x");
410     InspectorTest.assert(node.properties[1].type === WebInspector.ScriptSyntaxTree.NodeType.Property);
411     InspectorTest.assert(node.properties[1].key.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
412     InspectorTest.assert(node.properties[1].value.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
413     InspectorTest.assert(node.properties[1].key.name === "y");
414     InspectorTest.assert(node.properties[1].value.name === "foo");
415     node = makeNode("var [x, y] = foo;", false);
416     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclaration);
417     InspectorTest.assert(node.declarations.length === 1);
418     node = node.declarations[0].id;
419     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ArrayPattern);
420     InspectorTest.assert(node.elements.length === 2);
421     InspectorTest.assert(node.elements[0].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
422     InspectorTest.assert(node.elements[0].name === "x");
423     InspectorTest.assert(node.elements[1].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
424     InspectorTest.assert(node.elements[1].name === "y");
425     InspectorTest.log("passed VariableDeclarator");
426
427     node = makeNode("while(true)boo;", false);
428     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.WhileStatement);
429     InspectorTest.assert(node.test);
430     InspectorTest.assert(node.test.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
431     InspectorTest.assert(node.body);
432     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.ExpressionStatement);
433     node = makeNode("while(true){}", false);
434     InspectorTest.assert(node.body);
435     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
436     InspectorTest.log("passed WhileStatement");
437
438     node = makeNode("with(o) {}", false);
439     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.WithStatement);
440     InspectorTest.assert(node.object);
441     InspectorTest.assert(node.object.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
442     InspectorTest.assert(node.body);
443     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
444     InspectorTest.log("passed WithStatement");
445
446     node = makeNode("class C { constructor() { super(); new.target; } }", false);
447     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ClassDeclaration);
448     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.ClassBody);
449     InspectorTest.assert(node.body.body[0].type === WebInspector.ScriptSyntaxTree.NodeType.MethodDefinition);
450     InspectorTest.assert(node.body.body[0].value.type === WebInspector.ScriptSyntaxTree.NodeType.FunctionExpression);
451     InspectorTest.assert(node.body.body[0].value.body.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
452     InspectorTest.assert(node.body.body[0].value.body.body.length === 2);
453     InspectorTest.assert(node.body.body[0].value.body.body[0].type === WebInspector.ScriptSyntaxTree.NodeType.ExpressionStatement);
454     InspectorTest.assert(node.body.body[0].value.body.body[0].expression.type === WebInspector.ScriptSyntaxTree.NodeType.CallExpression);
455     InspectorTest.assert(node.body.body[0].value.body.body[0].expression.callee.type === WebInspector.ScriptSyntaxTree.NodeType.Super);
456     InspectorTest.assert(node.body.body[0].value.body.body[1].type === WebInspector.ScriptSyntaxTree.NodeType.ExpressionStatement);
457     InspectorTest.assert(node.body.body[0].value.body.body[1].expression.type === WebInspector.ScriptSyntaxTree.NodeType.MetaProperty);
458     InspectorTest.assert(node.body.body[0].value.body.body[1].expression.meta === "new");
459     InspectorTest.assert(node.body.body[0].value.body.body[1].expression.property === "target");
460     InspectorTest.log("passed ClassStatement, Super, MetaProperty");
461
462     node = makeNode("let [x=20] = [];", false);
463     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclaration);
464     InspectorTest.assert(node.kind === "let");
465     InspectorTest.assert(node.declarations.length === 1);
466     InspectorTest.assert(node.declarations[0].type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclarator);
467     InspectorTest.assert(node.declarations[0].id.type === WebInspector.ScriptSyntaxTree.NodeType.ArrayPattern);
468     InspectorTest.assert(node.declarations[0].id.elements.length === 1);
469     InspectorTest.assert(node.declarations[0].id.elements[0].type === WebInspector.ScriptSyntaxTree.NodeType.AssignmentPattern);
470     InspectorTest.assert(node.declarations[0].id.elements[0].left.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
471     InspectorTest.assert(node.declarations[0].id.elements[0].left.name === "x");
472     InspectorTest.assert(node.declarations[0].id.elements[0].right.type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
473     InspectorTest.assert(node.declarations[0].id.elements[0].right.value === 20);
474     InspectorTest.log("passed AssignmentPattern");
475
476     node = makeNode("(x) => x;", true);
477     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ArrowFunctionExpression);
478     InspectorTest.assert(node.params.length === 1);
479     InspectorTest.assert(node.params[0].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
480     InspectorTest.assert(node.params[0].name === "x");
481     InspectorTest.assert(node.expression === true);
482     InspectorTest.assert(node.defaults.length === 0);
483     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
484
485     node = makeNode("(x = 20) => { return x; };", true);
486     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.ArrowFunctionExpression);
487     InspectorTest.assert(node.params.length === 1);
488     InspectorTest.assert(node.params[0].type === WebInspector.ScriptSyntaxTree.NodeType.Identifier);
489     InspectorTest.assert(node.params[0].name === "x");
490     InspectorTest.assert(node.expression === false);
491     InspectorTest.assert(node.defaults.length === 1);
492     InspectorTest.assert(node.defaults[0].type === WebInspector.ScriptSyntaxTree.NodeType.Literal);
493     InspectorTest.assert(node.body.type === WebInspector.ScriptSyntaxTree.NodeType.BlockStatement);
494     InspectorTest.log("passed ArrowFunctionExpression");
495
496     node = makeNode("var o = {['c']() { }};", false);
497     //                        ^
498     //                 type profiling return divot.
499     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclaration);
500     InspectorTest.assert(node.declarations.length === 1);
501     InspectorTest.assert(node.declarations[0].type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclarator);
502     InspectorTest.assert(node.declarations[0].init.type === WebInspector.ScriptSyntaxTree.NodeType.ObjectExpression);
503     InspectorTest.assert(node.declarations[0].init.properties.length === 1);
504     InspectorTest.assert(node.declarations[0].init.properties[0].type === WebInspector.ScriptSyntaxTree.NodeType.Property);
505     InspectorTest.assert(!!node.declarations[0].init.properties[0].method);
506     InspectorTest.assert(!!node.declarations[0].init.properties[0].computed);
507     InspectorTest.assert(node.declarations[0].init.properties[0].value.type === WebInspector.ScriptSyntaxTree.NodeType.FunctionExpression);
508     InspectorTest.assert(node.declarations[0].init.properties[0].value.typeProfilingReturnDivot === 9);
509     InspectorTest.log("passed computed method on object literal");
510
511     node = makeNode("var o = { m(){ } };", false);
512     //                         ^
513     //                 type profiling return divot.
514     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclaration);
515     InspectorTest.assert(node.declarations.length === 1);
516     InspectorTest.assert(node.declarations[0].type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclarator);
517     InspectorTest.assert(node.declarations[0].init.type === WebInspector.ScriptSyntaxTree.NodeType.ObjectExpression);
518     InspectorTest.assert(node.declarations[0].init.properties.length === 1);
519     InspectorTest.assert(node.declarations[0].init.properties[0].type === WebInspector.ScriptSyntaxTree.NodeType.Property);
520     InspectorTest.assert(!!node.declarations[0].init.properties[0].method);
521     InspectorTest.assert(!node.declarations[0].init.properties[0].computed);
522     InspectorTest.assert(node.declarations[0].init.properties[0].value.type === WebInspector.ScriptSyntaxTree.NodeType.FunctionExpression);
523     InspectorTest.assert(node.declarations[0].init.properties[0].value.typeProfilingReturnDivot === 10);
524     InspectorTest.log("passed method on object literal");
525
526     node = makeNode("var o = {['c']: function(){ } };", false);
527     //                               ^
528     //                    type profiling return divot.
529     InspectorTest.assert(node.type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclaration);
530     InspectorTest.assert(node.declarations.length === 1);
531     InspectorTest.assert(node.declarations[0].type === WebInspector.ScriptSyntaxTree.NodeType.VariableDeclarator);
532     InspectorTest.assert(node.declarations[0].init.type === WebInspector.ScriptSyntaxTree.NodeType.ObjectExpression);
533     InspectorTest.assert(node.declarations[0].init.properties.length === 1);
534     InspectorTest.assert(node.declarations[0].init.properties[0].type === WebInspector.ScriptSyntaxTree.NodeType.Property);
535     InspectorTest.assert(!node.declarations[0].init.properties[0].method);
536     InspectorTest.assert(!!node.declarations[0].init.properties[0].computed);
537     InspectorTest.assert(node.declarations[0].init.properties[0].value.type === WebInspector.ScriptSyntaxTree.NodeType.FunctionExpression);
538     InspectorTest.assert(node.declarations[0].init.properties[0].value.typeProfilingReturnDivot === 16);
539     InspectorTest.log("passed computed method property on object literal");
540
541     InspectorTest.log("passed ALL TESTS");
542     InspectorTest.completeTest();
543 }
544 </script>
545 </head>
546 <body onload="runTest()">
547 </body>
548 </html>