| <!doctype html> |
| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/inspector-test.js"></script> |
| <script> |
| function test() |
| { |
| function makeNode(text, isExpression, isModule) |
| { |
| const target = null, url = null; |
| let sourceType = isModule ? WI.Script.SourceType.Module : WI.Script.SourceType.Program; |
| let script = new WI.Script(target, 1, new WI.TextRange(0, text.length), url, sourceType); |
| let scriptSyntaxTree = new WI.ScriptSyntaxTree(text, script); |
| let syntaxTree = scriptSyntaxTree._syntaxTree; |
| |
| InspectorTest.assert(scriptSyntaxTree.parsedSuccessfully, "ScriptSyntaxTree should be able to parse: \"" + text + "\""); |
| InspectorTest.assert(syntaxTree.type === WI.ScriptSyntaxTree.NodeType.Program, "Should be program."); |
| InspectorTest.assert(syntaxTree.body.length === 1, "Calling makeNode should return one node in the program."); |
| if (isExpression) { |
| InspectorTest.assert(syntaxTree.body[0].type === WI.ScriptSyntaxTree.NodeType.ExpressionStatement); |
| return syntaxTree.body[0].expression; |
| } else if (isModule) { |
| InspectorTest.assert(syntaxTree.sourceType === "module"); |
| return syntaxTree.body[0]; |
| } else { |
| InspectorTest.assert(syntaxTree.sourceType === "script"); |
| return syntaxTree.body[0]; |
| } |
| } |
| |
| function makeNodeForModule(text) |
| { |
| return makeNode(text, false, true); |
| } |
| |
| let node = null; |
| |
| node = makeNode("x = 20;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.AssignmentExpression); |
| InspectorTest.assert(node.left); |
| InspectorTest.assert(node.left.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.right); |
| InspectorTest.assert(node.right.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.operator === "="); |
| node = makeNode("[x, y] = foo;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.AssignmentExpression); |
| InspectorTest.assert(node.left); |
| InspectorTest.assert(node.left.type === WI.ScriptSyntaxTree.NodeType.ArrayPattern); |
| InspectorTest.assert(node.left.elements.length === 2); |
| InspectorTest.assert(node.left.elements[0].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.left.elements[0].name === "x"); |
| InspectorTest.assert(node.left.elements[1].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.left.elements[1].name === "y"); |
| node = makeNode("x += 20;", true); |
| InspectorTest.assert(node.operator === "+="); |
| node = makeNode("x -= 20;", true); |
| InspectorTest.assert(node.operator === "-="); |
| InspectorTest.log("passed AssignmentExpression"); |
| |
| node = makeNode("[1, 2]", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ArrayExpression); |
| InspectorTest.assert(Array.isArray(node.elements)); |
| InspectorTest.assert(node.elements.length === 2); |
| InspectorTest.assert(node.elements[0].type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.elements[1].type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.log("passed ArrayExpression"); |
| |
| node = makeNode("{foo();}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| InspectorTest.assert(node.body); |
| InspectorTest.assert(node.body.length === 1); |
| InspectorTest.assert(node.body[0].expression.type === WI.ScriptSyntaxTree.NodeType.CallExpression); |
| InspectorTest.log("passed BlockStatement"); |
| |
| node = makeNode("2 + 2", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.BinaryExpression); |
| InspectorTest.assert(node.left); |
| InspectorTest.assert(node.right); |
| InspectorTest.assert(node.operator === "+"); |
| node = makeNode("2 - 2", true); |
| InspectorTest.assert(node.operator === "-"); |
| node = makeNode("2 * 2", true); |
| InspectorTest.assert(node.operator === "*"); |
| node = makeNode("2 / 2", true); |
| InspectorTest.assert(node.operator === "/"); |
| node = makeNode("2 % 2", true); |
| InspectorTest.assert(node.operator === "%"); |
| node = makeNode("2 | 2", true); |
| InspectorTest.assert(node.operator === "|"); |
| node = makeNode("2 ^ 2", true); |
| InspectorTest.assert(node.operator === "^"); |
| node = makeNode("2 == 2", true); |
| InspectorTest.assert(node.operator === "=="); |
| node = makeNode("2 === 2", true); |
| InspectorTest.assert(node.operator === "==="); |
| InspectorTest.log("passed BinaryExpression"); |
| |
| node = makeNode("label:while(true) {break label;}", false); |
| InspectorTest.assert(node.body.body.body[0].type === WI.ScriptSyntaxTree.NodeType.BreakStatement); |
| InspectorTest.assert(node.body.body.body[0].label.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.body.body.body[0].label.name === "label"); |
| InspectorTest.log("passed BreakStatement"); |
| |
| node = makeNode("foo(20, 25)", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.CallExpression); |
| InspectorTest.assert(node.arguments); |
| InspectorTest.assert(node.arguments.length === 2); |
| InspectorTest.assert(node.arguments[0].type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.arguments[1].type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.log("passed CallExpression"); |
| |
| node = makeNode("try {} catch(e) {}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.TryStatement); |
| InspectorTest.assert(node.handler.type === WI.ScriptSyntaxTree.NodeType.CatchClause); |
| InspectorTest.assert(node.handler.param.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(!node.finalizer); |
| node = makeNode("try {} catch {}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.TryStatement); |
| InspectorTest.assert(node.handler.type === WI.ScriptSyntaxTree.NodeType.CatchClause); |
| InspectorTest.assert(!node.handler.param); |
| node = makeNode("try {} finally {}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.TryStatement); |
| InspectorTest.assert(!node.handler); |
| InspectorTest.assert(node.finalizer.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| InspectorTest.log("passed TryStatement"); |
| InspectorTest.log("passed CatchClause"); |
| |
| node = makeNode("foo ? bar : baz;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ConditionalExpression); |
| InspectorTest.assert(node.test); |
| InspectorTest.assert(node.consequent); |
| InspectorTest.assert(node.alternate); |
| InspectorTest.assert(node.test.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.consequent.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.alternate.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.log("passed ConditionalExpression"); |
| |
| node = makeNode("label:while(true) {continue label;}", false); |
| InspectorTest.assert(node.body.body.body[0].type === WI.ScriptSyntaxTree.NodeType.ContinueStatement); |
| InspectorTest.assert(node.body.body.body[0].label.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.body.body.body[0].label.name === "label"); |
| InspectorTest.log("passed ContinueStatement"); |
| |
| node = makeNode("do{}while(true);", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.DoWhileStatement); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| InspectorTest.assert(node.body.body.length === 0); |
| InspectorTest.assert(node.test); |
| InspectorTest.assert(node.test.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.log("passed DoWhileStatement"); |
| |
| node = makeNode("debugger;", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.DebuggerStatement); |
| InspectorTest.log("passed DebuggerStatement"); |
| |
| node = makeNode(";", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.EmptyStatement); |
| InspectorTest.log("passed EmptyStatement"); |
| |
| node = makeNode("2 + 2", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ExpressionStatement); |
| InspectorTest.assert(node.expression); |
| InspectorTest.assert(node.expression.type === WI.ScriptSyntaxTree.NodeType.BinaryExpression); |
| InspectorTest.log("passed ExpressionStatement"); |
| |
| node = makeNode("for(x = 0;x < 20;x++){}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ForStatement); |
| InspectorTest.assert(node.init); |
| InspectorTest.assert(node.init.type === WI.ScriptSyntaxTree.NodeType.AssignmentExpression); |
| InspectorTest.assert(node.test); |
| InspectorTest.assert(node.test.type === WI.ScriptSyntaxTree.NodeType.BinaryExpression); |
| InspectorTest.assert(node.update); |
| InspectorTest.assert(node.update.type === WI.ScriptSyntaxTree.NodeType.UpdateExpression); |
| InspectorTest.assert(node.body); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| node = makeNode("for(x = 0;x < 20;x++);", false); |
| InspectorTest.assert(node.body); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.EmptyStatement); |
| InspectorTest.log("passed ForStatement"); |
| |
| node = makeNode("for(var x in {}){}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ForInStatement); |
| InspectorTest.assert(node.left); |
| InspectorTest.assert(node.left.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.right); |
| InspectorTest.assert(node.right.type === WI.ScriptSyntaxTree.NodeType.ObjectExpression); |
| InspectorTest.assert(node.body); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| node = makeNode("for(var x in {});", false); |
| InspectorTest.assert(node.body); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.EmptyStatement); |
| InspectorTest.log("passed ForInStatement"); |
| |
| node = makeNode("for(var x of {});", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ForOfStatement); |
| InspectorTest.assert(!node.await); |
| InspectorTest.assert(node.left); |
| InspectorTest.assert(node.left.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.right); |
| InspectorTest.assert(node.right.type === WI.ScriptSyntaxTree.NodeType.ObjectExpression); |
| InspectorTest.assert(node.body); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.EmptyStatement); |
| node = makeNode("for(var {x} of {});", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ForOfStatement); |
| InspectorTest.assert(!node.await); |
| InspectorTest.assert(node.left); |
| InspectorTest.assert(node.left.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.left.declarations[0].id.type === WI.ScriptSyntaxTree.NodeType.ObjectPattern); |
| InspectorTest.assert(node.left.declarations[0].id.properties[0].value.name === "x"); |
| node = makeNode("async function foo() { for await (x of []); }", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.FunctionDeclaration); |
| InspectorTest.assert(node.async); |
| InspectorTest.assert(node.body.body[0].type === WI.ScriptSyntaxTree.NodeType.ForOfStatement); |
| InspectorTest.assert(node.body.body[0].await); |
| InspectorTest.log("passed ForOfStatement"); |
| |
| node = makeNode("function foo(x,y){}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.FunctionDeclaration); |
| InspectorTest.assert(node.params); |
| InspectorTest.assert(node.params.length === 2); |
| InspectorTest.assert(node.params[0].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.params[1].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.body); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| InspectorTest.assert(!node.generator); |
| node = makeNode("x = {get foo(){return 20}}", true); |
| InspectorTest.assert(node.right.properties[0].value.type === WI.ScriptSyntaxTree.NodeType.FunctionExpression); |
| node = makeNode("x = {set foo(x){return 20}}", true); |
| InspectorTest.assert(node.right.properties[0].value.type === WI.ScriptSyntaxTree.NodeType.FunctionExpression); |
| InspectorTest.log("passed FunctionDeclaration"); |
| |
| node = makeNode("foo(function(x,y){})", true); |
| InspectorTest.assert(node.arguments[0].type === WI.ScriptSyntaxTree.NodeType.FunctionExpression); |
| InspectorTest.assert(node.arguments[0].params); |
| InspectorTest.assert(node.arguments[0].params.length === 2); |
| InspectorTest.assert(node.arguments[0].params[0].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.arguments[0].params[1].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.arguments[0].body); |
| InspectorTest.assert(node.arguments[0].body.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| InspectorTest.assert(!node.arguments[0].generator); |
| InspectorTest.log("passed FunctionExpression"); |
| |
| node = makeNode("foo;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.name); |
| InspectorTest.assert(node.name === "foo"); |
| InspectorTest.log("passed Identifier"); |
| |
| node = makeNode("if (true) baz; else bar;", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.IfStatement); |
| InspectorTest.assert(node.test); |
| InspectorTest.assert(node.test.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.consequent); |
| InspectorTest.assert(node.consequent.type === WI.ScriptSyntaxTree.NodeType.ExpressionStatement); |
| InspectorTest.assert(node.alternate); |
| InspectorTest.assert(node.alternate.type === WI.ScriptSyntaxTree.NodeType.ExpressionStatement); |
| InspectorTest.log("passed IfStatement"); |
| |
| node = makeNode("true;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.value === true); |
| InspectorTest.assert(node.raw === "true"); |
| node = makeNode("false;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.value === false); |
| InspectorTest.assert(node.raw === "false"); |
| node = makeNode("20;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.value === 20); |
| InspectorTest.assert(node.raw === "20"); |
| node = makeNode("'20';", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.value === '20'); |
| InspectorTest.assert(node.raw === "'20'"); |
| node = makeNode("null;", true); |
| InspectorTest.assert(node.value === null); |
| InspectorTest.assert(node.raw === "null"); |
| node = makeNode("/regex/gi;", true); |
| InspectorTest.assert(node.value instanceof RegExp); |
| InspectorTest.assert(node.value.toString() === "/regex/gi"); |
| InspectorTest.assert(node.raw === "/regex/gi"); |
| node = makeNode("0x10", true); |
| InspectorTest.assert(node.value === 0x10); |
| InspectorTest.assert(node.raw === "0x10"); |
| node = makeNode("0777", true); |
| InspectorTest.assert(node.value === 0777); |
| InspectorTest.assert(node.raw === "0777"); |
| node = makeNode("\"a\"", true); |
| InspectorTest.assert(node.value === "a"); |
| InspectorTest.assert(node.raw === "\"a\""); |
| node = makeNode("'abc'", true); |
| InspectorTest.assert(node.value === "abc"); |
| InspectorTest.assert(node.raw === "'abc'"); |
| InspectorTest.log("passed Literal"); |
| |
| node = makeNode("`abc`", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.TemplateLiteral); |
| InspectorTest.assert(node.quasis.length === 1); |
| InspectorTest.assert(node.expressions.length === 0); |
| InspectorTest.assert(node.quasis[0].type === WI.ScriptSyntaxTree.NodeType.TemplateElement); |
| InspectorTest.assert(node.quasis[0].value.raw === "abc"); |
| node = makeNode("`abc${1}def`", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.TemplateLiteral); |
| InspectorTest.assert(node.quasis.length === 2); |
| InspectorTest.assert(node.expressions.length === 1); |
| InspectorTest.assert(node.quasis[0].type === WI.ScriptSyntaxTree.NodeType.TemplateElement); |
| InspectorTest.assert(node.quasis[0].value.raw === "abc"); |
| InspectorTest.assert(node.quasis[1].type === WI.ScriptSyntaxTree.NodeType.TemplateElement); |
| InspectorTest.assert(node.quasis[1].value.raw === "def"); |
| InspectorTest.assert(node.expressions[0].type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.expressions[0].value === 1); |
| InspectorTest.log("passed TemplateLiteral, TemplateElement"); |
| |
| node = makeNode("tag`abcd`", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.TaggedTemplateExpression); |
| InspectorTest.assert(node.tag.name === "tag"); |
| InspectorTest.assert(node.quasi.type === WI.ScriptSyntaxTree.NodeType.TemplateLiteral); |
| InspectorTest.assert(node.quasi.quasis.length === 1); |
| InspectorTest.assert(node.quasi.expressions.length === 0); |
| InspectorTest.assert(node.quasi.quasis[0].type === WI.ScriptSyntaxTree.NodeType.TemplateElement); |
| InspectorTest.assert(node.quasi.quasis[0].value.raw === "abcd"); |
| InspectorTest.log("passed TaggedTemplateExpression"); |
| |
| node = makeNode("label:while(true)20;", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.LabeledStatement); |
| InspectorTest.assert(node.label); |
| InspectorTest.assert(node.label.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.label.name === "label"); |
| InspectorTest.log("passed LabeledStatement"); |
| |
| node = makeNode("x && 20", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.LogicalExpression); |
| InspectorTest.assert(node.left); |
| InspectorTest.assert(node.left.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.right); |
| InspectorTest.assert(node.right.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| //InspectorTest.assert(node.operator === "&&"); |
| node = makeNode("x || 20", true); |
| InspectorTest.assert(node.operator === "||"); |
| InspectorTest.log("passed LogicalExpression"); |
| |
| node = makeNode("foo[20]", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.MemberExpression); |
| InspectorTest.assert(node.computed); |
| InspectorTest.assert(node.object); |
| InspectorTest.assert(node.object.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.property); |
| InspectorTest.assert(node.property.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| node = makeNode("foo.bar", true); |
| InspectorTest.assert(!node.computed); |
| InspectorTest.assert(node.property.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.log("passed MemberExpression"); |
| |
| node = makeNode("new Foo(20)", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.NewExpression); |
| InspectorTest.assert(node.callee); |
| InspectorTest.assert(node.callee.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.arguments); |
| InspectorTest.assert(node.arguments.length === 1); |
| node = makeNode("new Foo", true); |
| InspectorTest.assert(node.arguments); |
| InspectorTest.assert(node.arguments.length === 0); |
| InspectorTest.log("passed NewExpression"); |
| |
| node = makeNode("x = {foo:bar};", true); |
| InspectorTest.assert(node.right.type === WI.ScriptSyntaxTree.NodeType.ObjectExpression); |
| InspectorTest.assert(node.right.properties); |
| InspectorTest.assert(node.right.properties.length === 1); |
| InspectorTest.log("passed ObjectExpression"); |
| |
| // Program is tested in makeNode |
| |
| node = makeNode("x = {foo:20};", true); |
| InspectorTest.assert(node.right.properties[0].type === WI.ScriptSyntaxTree.NodeType.Property); |
| InspectorTest.assert(node.right.properties[0].key); |
| InspectorTest.assert(node.right.properties[0].key.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.right.properties[0].value); |
| InspectorTest.assert(node.right.properties[0].value.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| node = makeNode("x = {'foo':20};", true); |
| InspectorTest.assert(node.right.properties[0].key); |
| InspectorTest.assert(node.right.properties[0].key.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.log("passed Property"); |
| |
| node = makeNode("let { ...rest } = { x: 1, y: 0 }", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.kind === "let"); |
| InspectorTest.assert(node.declarations.length === 1); |
| InspectorTest.assert(node.declarations[0].type === WI.ScriptSyntaxTree.NodeType.VariableDeclarator); |
| InspectorTest.assert(node.declarations[0].id.type === WI.ScriptSyntaxTree.NodeType.ObjectPattern); |
| InspectorTest.assert(node.declarations[0].id.properties.length === 1); |
| InspectorTest.assert(node.declarations[0].id.properties[0].type === WI.ScriptSyntaxTree.NodeType.RestElement); |
| InspectorTest.assert(node.declarations[0].id.properties[0].argument.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.declarations[0].id.properties[0].argument.name === "rest"); |
| node = makeNode("function foo(...things) { return things; }", false); |
| InspectorTest.assert(node.params.length === 1); |
| InspectorTest.assert(node.params[0].type === WI.ScriptSyntaxTree.NodeType.RestElement); |
| InspectorTest.assert(node.params[0].argument.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.params[0].argument.name === "things"); |
| InspectorTest.log("passed RestElement"); |
| |
| node = makeNode("function foo() { return 20; }", false); |
| InspectorTest.assert(node.body.body[0].type === WI.ScriptSyntaxTree.NodeType.ReturnStatement); |
| InspectorTest.assert(node.body.body[0].argument.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| node = makeNode("function foo() { return; }", false); |
| InspectorTest.assert(node.body.body[0].argument === null); |
| InspectorTest.log("passed ReturnStatement"); |
| |
| node = makeNode("(x, y)", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.SequenceExpression); |
| InspectorTest.assert(node.expressions); |
| InspectorTest.assert(node.expressions.length === 2); |
| InspectorTest.assert(node.expressions[0].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.expressions[1].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.log("passed SequenceExpression"); |
| |
| node = makeNode("switch(x){case y:break;}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.SwitchStatement); |
| InspectorTest.assert(node.discriminant.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.log("passed SwitchStatement"); |
| InspectorTest.assert(node.cases[0].type === WI.ScriptSyntaxTree.NodeType.SwitchCase); |
| InspectorTest.assert(node.cases[0].test.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.cases[0].consequent); |
| InspectorTest.assert(Array.isArray(node.cases[0].consequent)); |
| InspectorTest.assert(node.cases[0].consequent.length === 1); |
| InspectorTest.log("passed SwitchCase"); |
| |
| node = makeNode("this;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ThisExpression); |
| InspectorTest.log("passed ThisExpression"); |
| |
| node = makeNode("throw new Error;", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ThrowStatement); |
| InspectorTest.assert(node.argument); |
| InspectorTest.assert(node.argument.type === WI.ScriptSyntaxTree.NodeType.NewExpression); |
| InspectorTest.log("passed ThrowStatement"); |
| |
| node = makeNode("!foo;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.UnaryExpression); |
| InspectorTest.assert(node.argument); |
| InspectorTest.assert(node.argument.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.operator === "!"); |
| node = makeNode("~foo;", true); |
| InspectorTest.assert(node.operator === "~"); |
| node = makeNode("-foo;", true); |
| InspectorTest.assert(node.operator === "-"); |
| InspectorTest.log("passed UnaryExpression"); |
| |
| node = makeNode("foo++;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.UpdateExpression); |
| InspectorTest.assert(node.argument); |
| InspectorTest.assert(node.argument.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.operator === "++"); |
| InspectorTest.assert(node.prefix === false); |
| node = makeNode("++foo;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.UpdateExpression); |
| InspectorTest.assert(node.argument); |
| InspectorTest.assert(node.argument.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.prefix === true); |
| InspectorTest.assert(node.operator === "++"); |
| node = makeNode("--foo;", true); |
| InspectorTest.assert(node.operator === "--"); |
| node = makeNode("foo--;", true); |
| InspectorTest.assert(node.operator === "--"); |
| InspectorTest.log("passed UpdateExpression"); |
| |
| node = makeNode("var foo = 20;", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.declarations); |
| InspectorTest.assert(node.declarations.length === 1); |
| InspectorTest.log("passed VariableDeclaration"); |
| InspectorTest.assert(node.declarations[0].type === WI.ScriptSyntaxTree.NodeType.VariableDeclarator); |
| InspectorTest.assert(node.declarations[0].id); |
| InspectorTest.assert(node.declarations[0].id.type); |
| InspectorTest.assert(node.declarations[0].id.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.declarations[0].init); |
| InspectorTest.assert(node.declarations[0].init.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| node = makeNode("var foo;", false); |
| InspectorTest.assert(node.declarations[0].init === null); |
| node = makeNode("var {x, y: foo} = bar;", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.declarations.length === 1); |
| node = node.declarations[0].id; |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ObjectPattern); |
| InspectorTest.assert(node.properties.length === 2); |
| InspectorTest.assert(node.properties[0].type === WI.ScriptSyntaxTree.NodeType.Property); |
| InspectorTest.assert(node.properties[0].key.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.properties[0].value.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.properties[0].key.name === node.properties[0].value.name && node.properties[0].key.name === "x"); |
| InspectorTest.assert(node.properties[1].type === WI.ScriptSyntaxTree.NodeType.Property); |
| InspectorTest.assert(node.properties[1].key.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.properties[1].value.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.properties[1].key.name === "y"); |
| InspectorTest.assert(node.properties[1].value.name === "foo"); |
| node = makeNode("var [x, y] = foo;", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.declarations.length === 1); |
| node = node.declarations[0].id; |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ArrayPattern); |
| InspectorTest.assert(node.elements.length === 2); |
| InspectorTest.assert(node.elements[0].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.elements[0].name === "x"); |
| InspectorTest.assert(node.elements[1].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.elements[1].name === "y"); |
| InspectorTest.log("passed VariableDeclarator"); |
| |
| node = makeNode("while(true)boo;", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.WhileStatement); |
| InspectorTest.assert(node.test); |
| InspectorTest.assert(node.test.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.body); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.ExpressionStatement); |
| node = makeNode("while(true){}", false); |
| InspectorTest.assert(node.body); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| InspectorTest.log("passed WhileStatement"); |
| |
| node = makeNode("with(o) {}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.WithStatement); |
| InspectorTest.assert(node.object); |
| InspectorTest.assert(node.object.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.body); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| InspectorTest.log("passed WithStatement"); |
| |
| node = makeNode("function* gen() { yield 1; yield* [1,2]; }", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.FunctionDeclaration); |
| InspectorTest.assert(node.generator); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| InspectorTest.assert(node.body.body.length === 2); |
| InspectorTest.assert(node.body.body[0].type === WI.ScriptSyntaxTree.NodeType.ExpressionStatement); |
| InspectorTest.assert(node.body.body[0].expression.type === WI.ScriptSyntaxTree.NodeType.YieldExpression); |
| InspectorTest.assert(!node.body.body[0].expression.delegate); |
| InspectorTest.assert(node.body.body[0].expression.argument.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.body.body[1].type === WI.ScriptSyntaxTree.NodeType.ExpressionStatement); |
| InspectorTest.assert(node.body.body[1].expression.type === WI.ScriptSyntaxTree.NodeType.YieldExpression); |
| InspectorTest.assert(node.body.body[1].expression.delegate); |
| InspectorTest.assert(node.body.body[1].expression.argument.type === WI.ScriptSyntaxTree.NodeType.ArrayExpression); |
| InspectorTest.log("passed YieldExpression"); |
| |
| node = makeNode("class C { constructor() { super(); new.target; } }", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ClassDeclaration); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.ClassBody); |
| InspectorTest.assert(node.body.body[0].type === WI.ScriptSyntaxTree.NodeType.MethodDefinition); |
| InspectorTest.assert(node.body.body[0].value.type === WI.ScriptSyntaxTree.NodeType.FunctionExpression); |
| InspectorTest.assert(node.body.body[0].value.body.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| InspectorTest.assert(node.body.body[0].value.body.body.length === 2); |
| InspectorTest.assert(node.body.body[0].value.body.body[0].type === WI.ScriptSyntaxTree.NodeType.ExpressionStatement); |
| InspectorTest.assert(node.body.body[0].value.body.body[0].expression.type === WI.ScriptSyntaxTree.NodeType.CallExpression); |
| InspectorTest.assert(node.body.body[0].value.body.body[0].expression.callee.type === WI.ScriptSyntaxTree.NodeType.Super); |
| InspectorTest.assert(node.body.body[0].value.body.body[1].type === WI.ScriptSyntaxTree.NodeType.ExpressionStatement); |
| InspectorTest.assert(node.body.body[0].value.body.body[1].expression.type === WI.ScriptSyntaxTree.NodeType.MetaProperty); |
| InspectorTest.assert(node.body.body[0].value.body.body[1].expression.meta.name === "new"); |
| InspectorTest.assert(node.body.body[0].value.body.body[1].expression.property.name === "target"); |
| InspectorTest.log("passed ClassStatement, Super, MetaProperty"); |
| |
| node = makeNode("import('./Cocoa.js')", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.CallExpression); |
| InspectorTest.assert(node.callee.type === WI.ScriptSyntaxTree.NodeType.Import); |
| InspectorTest.assert(node.arguments); |
| InspectorTest.assert(node.arguments.length === 1); |
| InspectorTest.assert(node.arguments[0].type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.log("passed Import"); |
| |
| node = makeNode("let n = { ...spread }", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.kind === "let"); |
| InspectorTest.assert(node.declarations.length === 1); |
| InspectorTest.assert(node.declarations[0].type === WI.ScriptSyntaxTree.NodeType.VariableDeclarator); |
| InspectorTest.assert(node.declarations[0].init.type === WI.ScriptSyntaxTree.NodeType.ObjectExpression); |
| InspectorTest.assert(node.declarations[0].init.properties.length === 1); |
| InspectorTest.assert(node.declarations[0].init.properties[0].type === WI.ScriptSyntaxTree.NodeType.SpreadElement); |
| InspectorTest.assert(node.declarations[0].init.properties[0].argument.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.declarations[0].init.properties[0].argument.name === "spread"); |
| InspectorTest.log("passed SpreadElement"); |
| |
| node = makeNode("let [x=20] = [];", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.kind === "let"); |
| InspectorTest.assert(node.declarations.length === 1); |
| InspectorTest.assert(node.declarations[0].type === WI.ScriptSyntaxTree.NodeType.VariableDeclarator); |
| InspectorTest.assert(node.declarations[0].id.type === WI.ScriptSyntaxTree.NodeType.ArrayPattern); |
| InspectorTest.assert(node.declarations[0].id.elements.length === 1); |
| InspectorTest.assert(node.declarations[0].id.elements[0].type === WI.ScriptSyntaxTree.NodeType.AssignmentPattern); |
| InspectorTest.assert(node.declarations[0].id.elements[0].left.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.declarations[0].id.elements[0].left.name === "x"); |
| InspectorTest.assert(node.declarations[0].id.elements[0].right.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.declarations[0].id.elements[0].right.value === 20); |
| node = makeNode("function foo(a, b=1) { return a + b; }", false); |
| InspectorTest.assert(node.params.length === 2); |
| InspectorTest.assert(node.params[0].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.params[0].name === "a"); |
| InspectorTest.assert(node.params[1].type === WI.ScriptSyntaxTree.NodeType.AssignmentPattern); |
| InspectorTest.assert(node.params[1].left.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.params[1].left.name === "b"); |
| InspectorTest.assert(node.params[1].right.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.params[1].right.value === 1); |
| InspectorTest.log("passed AssignmentPattern"); |
| |
| node = makeNode("(x) => x;", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ArrowFunctionExpression); |
| InspectorTest.assert(node.params.length === 1); |
| InspectorTest.assert(node.params[0].type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.params[0].name === "x"); |
| InspectorTest.assert(node.expression === true); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| |
| node = makeNode("(x = 20) => { return x; };", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ArrowFunctionExpression); |
| InspectorTest.assert(node.params.length === 1); |
| InspectorTest.assert(node.params[0].type === WI.ScriptSyntaxTree.NodeType.AssignmentPattern); |
| InspectorTest.assert(node.params[0].left.type === WI.ScriptSyntaxTree.NodeType.Identifier); |
| InspectorTest.assert(node.params[0].left.name === "x"); |
| InspectorTest.assert(node.params[0].right.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.params[0].right.value === 20); |
| InspectorTest.assert(node.expression === false); |
| InspectorTest.assert(node.body.type === WI.ScriptSyntaxTree.NodeType.BlockStatement); |
| InspectorTest.log("passed ArrowFunctionExpression"); |
| |
| node = makeNode("async function foo() {}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.FunctionDeclaration); |
| InspectorTest.assert(node.async); |
| node = makeNode("function foo() {}", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.FunctionDeclaration); |
| InspectorTest.assert(!node.async); |
| node = makeNode("(async function() {})", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.FunctionExpression); |
| InspectorTest.assert(node.async); |
| node = makeNode("(function() {})", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.FunctionExpression); |
| InspectorTest.assert(!node.async); |
| node = makeNode("async () => {}", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ArrowFunctionExpression); |
| InspectorTest.assert(node.async); |
| node = makeNode("() => {}", true); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ArrowFunctionExpression); |
| InspectorTest.assert(!node.async); |
| InspectorTest.log("passed Async Functions"); |
| |
| node = makeNode("async function foo() { await foo(); }", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.FunctionDeclaration); |
| InspectorTest.assert(node.async); |
| InspectorTest.assert(node.body.body[0].expression.type === WI.ScriptSyntaxTree.NodeType.AwaitExpression); |
| InspectorTest.assert(node.body.body[0].expression.argument.type === WI.ScriptSyntaxTree.NodeType.CallExpression); |
| node = makeNode("async function foo() { await 1; }", false); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.FunctionDeclaration); |
| InspectorTest.assert(node.async); |
| InspectorTest.assert(node.body.body[0].expression.type === WI.ScriptSyntaxTree.NodeType.AwaitExpression); |
| InspectorTest.assert(node.body.body[0].expression.argument.type === WI.ScriptSyntaxTree.NodeType.Literal); |
| InspectorTest.assert(node.body.body[0].expression.argument.value === 1); |
| InspectorTest.log("passed AwaitExpression"); |
| |
| |
| // Modules |
| |
| node = makeNodeForModule(`import {a,b as x,c} from "module.js"`); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ImportDeclaration); |
| InspectorTest.assert(node.source.value === "module.js"); |
| InspectorTest.assert(node.specifiers.length === 3); |
| InspectorTest.assert(node.specifiers[0].type === WI.ScriptSyntaxTree.NodeType.ImportSpecifier); |
| InspectorTest.assert(node.specifiers[0].local.name === "a"); |
| InspectorTest.assert(node.specifiers[0].imported.name === "a"); |
| InspectorTest.assert(node.specifiers[1].type === WI.ScriptSyntaxTree.NodeType.ImportSpecifier); |
| InspectorTest.assert(node.specifiers[1].local.name === "x"); |
| InspectorTest.assert(node.specifiers[1].imported.name === "b"); |
| InspectorTest.assert(node.specifiers[2].type === WI.ScriptSyntaxTree.NodeType.ImportSpecifier); |
| InspectorTest.assert(node.specifiers[2].local.name === "c"); |
| InspectorTest.assert(node.specifiers[2].imported.name === "c"); |
| InspectorTest.log("passed ImportDeclaration, ImportSpecifier"); |
| |
| node = makeNodeForModule(`import x from "module.js"`); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ImportDeclaration); |
| InspectorTest.assert(node.source.value === "module.js"); |
| InspectorTest.assert(node.specifiers.length === 1); |
| InspectorTest.assert(node.specifiers[0].type === WI.ScriptSyntaxTree.NodeType.ImportDefaultSpecifier); |
| InspectorTest.log("passed ImportDefaultSpecifier"); |
| |
| node = makeNodeForModule(`import * as A from "module.js"`); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ImportDeclaration); |
| InspectorTest.assert(node.source.value === "module.js"); |
| InspectorTest.assert(node.specifiers.length === 1); |
| InspectorTest.assert(node.specifiers[0].type === WI.ScriptSyntaxTree.NodeType.ImportNamespaceSpecifier); |
| InspectorTest.assert(node.specifiers[0].local.name === "A"); |
| InspectorTest.log("passed ImportNamespaceSpecifier"); |
| |
| node = makeNodeForModule(`export {a, b as x, c}`); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ExportNamedDeclaration); |
| InspectorTest.assert(node.specifiers.length === 3); |
| InspectorTest.assert(node.specifiers[0].type === WI.ScriptSyntaxTree.NodeType.ExportSpecifier); |
| InspectorTest.assert(node.specifiers[0].local.name === "a"); |
| InspectorTest.assert(node.specifiers[0].exported.name === "a"); |
| InspectorTest.assert(node.specifiers[1].type === WI.ScriptSyntaxTree.NodeType.ExportSpecifier); |
| InspectorTest.assert(node.specifiers[1].local.name === "b"); |
| InspectorTest.assert(node.specifiers[1].exported.name === "x"); |
| InspectorTest.assert(node.specifiers[2].type === WI.ScriptSyntaxTree.NodeType.ExportSpecifier); |
| InspectorTest.assert(node.specifiers[2].local.name === "c"); |
| InspectorTest.assert(node.specifiers[2].exported.name === "c"); |
| InspectorTest.log("passed ExportNamedDeclaration, ExportSpecifier"); |
| |
| node = makeNodeForModule(`export default x`); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ExportDefaultDeclaration); |
| InspectorTest.assert(node.declaration.name === "x"); |
| InspectorTest.log("passed ExportDefaultDeclaration"); |
| |
| node = makeNodeForModule(`export * from "module.js"`); |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.ExportAllDeclaration); |
| InspectorTest.assert(node.source.value === "module.js"); |
| InspectorTest.log("passed ExportAllDeclaration"); |
| |
| |
| // Divots |
| |
| node = makeNode("var o = {['c']() { }};", false); |
| // ^ |
| // type profiling return divot. |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.declarations.length === 1); |
| InspectorTest.assert(node.declarations[0].type === WI.ScriptSyntaxTree.NodeType.VariableDeclarator); |
| InspectorTest.assert(node.declarations[0].init.type === WI.ScriptSyntaxTree.NodeType.ObjectExpression); |
| InspectorTest.assert(node.declarations[0].init.properties.length === 1); |
| InspectorTest.assert(node.declarations[0].init.properties[0].type === WI.ScriptSyntaxTree.NodeType.Property); |
| InspectorTest.assert(!!node.declarations[0].init.properties[0].method); |
| InspectorTest.assert(!!node.declarations[0].init.properties[0].computed); |
| InspectorTest.assert(node.declarations[0].init.properties[0].value.type === WI.ScriptSyntaxTree.NodeType.FunctionExpression); |
| InspectorTest.assert(node.declarations[0].init.properties[0].value.typeProfilingReturnDivot === 9); |
| InspectorTest.log("passed computed method on object literal"); |
| |
| node = makeNode("var o = { m(){ } };", false); |
| // ^ |
| // type profiling return divot. |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.declarations.length === 1); |
| InspectorTest.assert(node.declarations[0].type === WI.ScriptSyntaxTree.NodeType.VariableDeclarator); |
| InspectorTest.assert(node.declarations[0].init.type === WI.ScriptSyntaxTree.NodeType.ObjectExpression); |
| InspectorTest.assert(node.declarations[0].init.properties.length === 1); |
| InspectorTest.assert(node.declarations[0].init.properties[0].type === WI.ScriptSyntaxTree.NodeType.Property); |
| InspectorTest.assert(!!node.declarations[0].init.properties[0].method); |
| InspectorTest.assert(!node.declarations[0].init.properties[0].computed); |
| InspectorTest.assert(node.declarations[0].init.properties[0].value.type === WI.ScriptSyntaxTree.NodeType.FunctionExpression); |
| InspectorTest.assert(node.declarations[0].init.properties[0].value.typeProfilingReturnDivot === 10); |
| InspectorTest.log("passed method on object literal"); |
| |
| node = makeNode("var o = {['c']: function(){ } };", false); |
| // ^ |
| // type profiling return divot. |
| InspectorTest.assert(node.type === WI.ScriptSyntaxTree.NodeType.VariableDeclaration); |
| InspectorTest.assert(node.declarations.length === 1); |
| InspectorTest.assert(node.declarations[0].type === WI.ScriptSyntaxTree.NodeType.VariableDeclarator); |
| InspectorTest.assert(node.declarations[0].init.type === WI.ScriptSyntaxTree.NodeType.ObjectExpression); |
| InspectorTest.assert(node.declarations[0].init.properties.length === 1); |
| InspectorTest.assert(node.declarations[0].init.properties[0].type === WI.ScriptSyntaxTree.NodeType.Property); |
| InspectorTest.assert(!node.declarations[0].init.properties[0].method); |
| InspectorTest.assert(!!node.declarations[0].init.properties[0].computed); |
| InspectorTest.assert(node.declarations[0].init.properties[0].value.type === WI.ScriptSyntaxTree.NodeType.FunctionExpression); |
| InspectorTest.assert(node.declarations[0].init.properties[0].value.typeProfilingReturnDivot === 16); |
| InspectorTest.log("passed computed method property on object literal"); |
| |
| InspectorTest.log("passed ALL TESTS"); |
| InspectorTest.completeTest(); |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| </body> |
| </html> |