1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_parser-10.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,127 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Test that creating an evaluation string for certain nodes works properly. 1.9 + */ 1.10 + 1.11 +function test() { 1.12 + let { Parser, ParserHelpers, SyntaxTreeVisitor } = 1.13 + Cu.import("resource:///modules/devtools/Parser.jsm", {}); 1.14 + 1.15 + function verify(source, predicate, string) { 1.16 + let ast = Parser.reflectionAPI.parse(source); 1.17 + let node = SyntaxTreeVisitor.filter(ast, predicate).pop(); 1.18 + let info = ParserHelpers.getIdentifierEvalString(node); 1.19 + is(info, string, "The identifier evaluation string is correct."); 1.20 + } 1.21 + 1.22 + // Indentifier or Literal 1.23 + 1.24 + verify("foo", e => e.type == "Identifier", "foo"); 1.25 + verify("undefined", e => e.type == "Identifier", "undefined"); 1.26 + verify("null", e => e.type == "Literal", "null"); 1.27 + verify("42", e => e.type == "Literal", "42"); 1.28 + verify("true", e => e.type == "Literal", "true"); 1.29 + verify("\"nasu\"", e => e.type == "Literal", "\"nasu\""); 1.30 + 1.31 + // MemberExpression or ThisExpression 1.32 + 1.33 + verify("this", e => e.type == "ThisExpression", "this"); 1.34 + verify("foo.bar", e => e.name == "foo", "foo"); 1.35 + verify("foo.bar", e => e.name == "bar", "foo.bar"); 1.36 + 1.37 + // MemberExpression + ThisExpression 1.38 + 1.39 + verify("this.foo.bar", e => e.type == "ThisExpression", "this"); 1.40 + verify("this.foo.bar", e => e.name == "foo", "this.foo"); 1.41 + verify("this.foo.bar", e => e.name == "bar", "this.foo.bar"); 1.42 + 1.43 + verify("foo.this.bar", e => e.name == "foo", "foo"); 1.44 + verify("foo.this.bar", e => e.name == "this", "foo.this"); 1.45 + verify("foo.this.bar", e => e.name == "bar", "foo.this.bar"); 1.46 + 1.47 + // ObjectExpression + VariableDeclarator 1.48 + 1.49 + verify("let foo={bar:baz}", e => e.name == "baz", "baz"); 1.50 + verify("let foo={bar:undefined}", e => e.name == "undefined", "undefined"); 1.51 + verify("let foo={bar:null}", e => e.type == "Literal", "null"); 1.52 + verify("let foo={bar:42}", e => e.type == "Literal", "42"); 1.53 + verify("let foo={bar:true}", e => e.type == "Literal", "true"); 1.54 + verify("let foo={bar:\"nasu\"}", e => e.type == "Literal", "\"nasu\""); 1.55 + verify("let foo={bar:this}", e => e.type == "ThisExpression", "this"); 1.56 + 1.57 + verify("let foo={bar:{nested:baz}}", e => e.name == "baz", "baz"); 1.58 + verify("let foo={bar:{nested:undefined}}", e => e.name == "undefined", "undefined"); 1.59 + verify("let foo={bar:{nested:null}}", e => e.type == "Literal", "null"); 1.60 + verify("let foo={bar:{nested:42}}", e => e.type == "Literal", "42"); 1.61 + verify("let foo={bar:{nested:true}}", e => e.type == "Literal", "true"); 1.62 + verify("let foo={bar:{nested:\"nasu\"}}", e => e.type == "Literal", "\"nasu\""); 1.63 + verify("let foo={bar:{nested:this}}", e => e.type == "ThisExpression", "this"); 1.64 + 1.65 + verify("let foo={bar:baz}", e => e.name == "bar", "foo.bar"); 1.66 + verify("let foo={bar:baz}", e => e.name == "foo", "foo"); 1.67 + 1.68 + verify("let foo={bar:{nested:baz}}", e => e.name == "nested", "foo.bar.nested"); 1.69 + verify("let foo={bar:{nested:baz}}", e => e.name == "bar", "foo.bar"); 1.70 + verify("let foo={bar:{nested:baz}}", e => e.name == "foo", "foo"); 1.71 + 1.72 + // ObjectExpression + MemberExpression 1.73 + 1.74 + verify("parent.foo={bar:baz}", e => e.name == "bar", "parent.foo.bar"); 1.75 + verify("parent.foo={bar:baz}", e => e.name == "foo", "parent.foo"); 1.76 + verify("parent.foo={bar:baz}", e => e.name == "parent", "parent"); 1.77 + 1.78 + verify("parent.foo={bar:{nested:baz}}", e => e.name == "nested", "parent.foo.bar.nested"); 1.79 + verify("parent.foo={bar:{nested:baz}}", e => e.name == "bar", "parent.foo.bar"); 1.80 + verify("parent.foo={bar:{nested:baz}}", e => e.name == "foo", "parent.foo"); 1.81 + verify("parent.foo={bar:{nested:baz}}", e => e.name == "parent", "parent"); 1.82 + 1.83 + verify("this.foo={bar:{nested:baz}}", e => e.name == "nested", "this.foo.bar.nested"); 1.84 + verify("this.foo={bar:{nested:baz}}", e => e.name == "bar", "this.foo.bar"); 1.85 + verify("this.foo={bar:{nested:baz}}", e => e.name == "foo", "this.foo"); 1.86 + verify("this.foo={bar:{nested:baz}}", e => e.type == "ThisExpression", "this"); 1.87 + 1.88 + verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "nested", "this.parent.foo.bar.nested"); 1.89 + verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "bar", "this.parent.foo.bar"); 1.90 + verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "foo", "this.parent.foo"); 1.91 + verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "parent", "this.parent"); 1.92 + verify("this.parent.foo={bar:{nested:baz}}", e => e.type == "ThisExpression", "this"); 1.93 + 1.94 + verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "nested", "parent.this.foo.bar.nested"); 1.95 + verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "bar", "parent.this.foo.bar"); 1.96 + verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "foo", "parent.this.foo"); 1.97 + verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "this", "parent.this"); 1.98 + verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "parent", "parent"); 1.99 + 1.100 + // FunctionExpression 1.101 + 1.102 + verify("function foo(){}", e => e.name == "foo", "foo"); 1.103 + verify("var foo=function(){}", e => e.name == "foo", "foo"); 1.104 + verify("var foo=function bar(){}", e => e.name == "bar", "bar"); 1.105 + 1.106 + // New/CallExpression 1.107 + 1.108 + verify("foo()", e => e.name == "foo", "foo"); 1.109 + verify("new foo()", e => e.name == "foo", "foo"); 1.110 + 1.111 + verify("foo(bar)", e => e.name == "bar", "bar"); 1.112 + verify("foo(bar, baz)", e => e.name == "baz", "baz"); 1.113 + verify("foo(undefined)", e => e.name == "undefined", "undefined"); 1.114 + verify("foo(null)", e => e.type == "Literal", "null"); 1.115 + verify("foo(42)", e => e.type == "Literal", "42"); 1.116 + verify("foo(true)", e => e.type == "Literal", "true"); 1.117 + verify("foo(\"nasu\")", e => e.type == "Literal", "\"nasu\""); 1.118 + verify("foo(this)", e => e.type == "ThisExpression", "this"); 1.119 + 1.120 + // New/CallExpression + ObjectExpression + MemberExpression 1.121 + 1.122 + verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "nested", "this.parent.foo.bar.nested"); 1.123 + verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "bar", "this.parent.foo.bar"); 1.124 + verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "foo", "this.parent.foo"); 1.125 + verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "parent", "this.parent"); 1.126 + verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.type == "ThisExpression", "this"); 1.127 + verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "fun", "fun"); 1.128 + 1.129 + finish(); 1.130 +}