browser/devtools/debugger/test/browser_dbg_parser-10.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Test that creating an evaluation string for certain nodes works properly.
michael@0 6 */
michael@0 7
michael@0 8 function test() {
michael@0 9 let { Parser, ParserHelpers, SyntaxTreeVisitor } =
michael@0 10 Cu.import("resource:///modules/devtools/Parser.jsm", {});
michael@0 11
michael@0 12 function verify(source, predicate, string) {
michael@0 13 let ast = Parser.reflectionAPI.parse(source);
michael@0 14 let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
michael@0 15 let info = ParserHelpers.getIdentifierEvalString(node);
michael@0 16 is(info, string, "The identifier evaluation string is correct.");
michael@0 17 }
michael@0 18
michael@0 19 // Indentifier or Literal
michael@0 20
michael@0 21 verify("foo", e => e.type == "Identifier", "foo");
michael@0 22 verify("undefined", e => e.type == "Identifier", "undefined");
michael@0 23 verify("null", e => e.type == "Literal", "null");
michael@0 24 verify("42", e => e.type == "Literal", "42");
michael@0 25 verify("true", e => e.type == "Literal", "true");
michael@0 26 verify("\"nasu\"", e => e.type == "Literal", "\"nasu\"");
michael@0 27
michael@0 28 // MemberExpression or ThisExpression
michael@0 29
michael@0 30 verify("this", e => e.type == "ThisExpression", "this");
michael@0 31 verify("foo.bar", e => e.name == "foo", "foo");
michael@0 32 verify("foo.bar", e => e.name == "bar", "foo.bar");
michael@0 33
michael@0 34 // MemberExpression + ThisExpression
michael@0 35
michael@0 36 verify("this.foo.bar", e => e.type == "ThisExpression", "this");
michael@0 37 verify("this.foo.bar", e => e.name == "foo", "this.foo");
michael@0 38 verify("this.foo.bar", e => e.name == "bar", "this.foo.bar");
michael@0 39
michael@0 40 verify("foo.this.bar", e => e.name == "foo", "foo");
michael@0 41 verify("foo.this.bar", e => e.name == "this", "foo.this");
michael@0 42 verify("foo.this.bar", e => e.name == "bar", "foo.this.bar");
michael@0 43
michael@0 44 // ObjectExpression + VariableDeclarator
michael@0 45
michael@0 46 verify("let foo={bar:baz}", e => e.name == "baz", "baz");
michael@0 47 verify("let foo={bar:undefined}", e => e.name == "undefined", "undefined");
michael@0 48 verify("let foo={bar:null}", e => e.type == "Literal", "null");
michael@0 49 verify("let foo={bar:42}", e => e.type == "Literal", "42");
michael@0 50 verify("let foo={bar:true}", e => e.type == "Literal", "true");
michael@0 51 verify("let foo={bar:\"nasu\"}", e => e.type == "Literal", "\"nasu\"");
michael@0 52 verify("let foo={bar:this}", e => e.type == "ThisExpression", "this");
michael@0 53
michael@0 54 verify("let foo={bar:{nested:baz}}", e => e.name == "baz", "baz");
michael@0 55 verify("let foo={bar:{nested:undefined}}", e => e.name == "undefined", "undefined");
michael@0 56 verify("let foo={bar:{nested:null}}", e => e.type == "Literal", "null");
michael@0 57 verify("let foo={bar:{nested:42}}", e => e.type == "Literal", "42");
michael@0 58 verify("let foo={bar:{nested:true}}", e => e.type == "Literal", "true");
michael@0 59 verify("let foo={bar:{nested:\"nasu\"}}", e => e.type == "Literal", "\"nasu\"");
michael@0 60 verify("let foo={bar:{nested:this}}", e => e.type == "ThisExpression", "this");
michael@0 61
michael@0 62 verify("let foo={bar:baz}", e => e.name == "bar", "foo.bar");
michael@0 63 verify("let foo={bar:baz}", e => e.name == "foo", "foo");
michael@0 64
michael@0 65 verify("let foo={bar:{nested:baz}}", e => e.name == "nested", "foo.bar.nested");
michael@0 66 verify("let foo={bar:{nested:baz}}", e => e.name == "bar", "foo.bar");
michael@0 67 verify("let foo={bar:{nested:baz}}", e => e.name == "foo", "foo");
michael@0 68
michael@0 69 // ObjectExpression + MemberExpression
michael@0 70
michael@0 71 verify("parent.foo={bar:baz}", e => e.name == "bar", "parent.foo.bar");
michael@0 72 verify("parent.foo={bar:baz}", e => e.name == "foo", "parent.foo");
michael@0 73 verify("parent.foo={bar:baz}", e => e.name == "parent", "parent");
michael@0 74
michael@0 75 verify("parent.foo={bar:{nested:baz}}", e => e.name == "nested", "parent.foo.bar.nested");
michael@0 76 verify("parent.foo={bar:{nested:baz}}", e => e.name == "bar", "parent.foo.bar");
michael@0 77 verify("parent.foo={bar:{nested:baz}}", e => e.name == "foo", "parent.foo");
michael@0 78 verify("parent.foo={bar:{nested:baz}}", e => e.name == "parent", "parent");
michael@0 79
michael@0 80 verify("this.foo={bar:{nested:baz}}", e => e.name == "nested", "this.foo.bar.nested");
michael@0 81 verify("this.foo={bar:{nested:baz}}", e => e.name == "bar", "this.foo.bar");
michael@0 82 verify("this.foo={bar:{nested:baz}}", e => e.name == "foo", "this.foo");
michael@0 83 verify("this.foo={bar:{nested:baz}}", e => e.type == "ThisExpression", "this");
michael@0 84
michael@0 85 verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "nested", "this.parent.foo.bar.nested");
michael@0 86 verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "bar", "this.parent.foo.bar");
michael@0 87 verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "foo", "this.parent.foo");
michael@0 88 verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "parent", "this.parent");
michael@0 89 verify("this.parent.foo={bar:{nested:baz}}", e => e.type == "ThisExpression", "this");
michael@0 90
michael@0 91 verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "nested", "parent.this.foo.bar.nested");
michael@0 92 verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "bar", "parent.this.foo.bar");
michael@0 93 verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "foo", "parent.this.foo");
michael@0 94 verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "this", "parent.this");
michael@0 95 verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "parent", "parent");
michael@0 96
michael@0 97 // FunctionExpression
michael@0 98
michael@0 99 verify("function foo(){}", e => e.name == "foo", "foo");
michael@0 100 verify("var foo=function(){}", e => e.name == "foo", "foo");
michael@0 101 verify("var foo=function bar(){}", e => e.name == "bar", "bar");
michael@0 102
michael@0 103 // New/CallExpression
michael@0 104
michael@0 105 verify("foo()", e => e.name == "foo", "foo");
michael@0 106 verify("new foo()", e => e.name == "foo", "foo");
michael@0 107
michael@0 108 verify("foo(bar)", e => e.name == "bar", "bar");
michael@0 109 verify("foo(bar, baz)", e => e.name == "baz", "baz");
michael@0 110 verify("foo(undefined)", e => e.name == "undefined", "undefined");
michael@0 111 verify("foo(null)", e => e.type == "Literal", "null");
michael@0 112 verify("foo(42)", e => e.type == "Literal", "42");
michael@0 113 verify("foo(true)", e => e.type == "Literal", "true");
michael@0 114 verify("foo(\"nasu\")", e => e.type == "Literal", "\"nasu\"");
michael@0 115 verify("foo(this)", e => e.type == "ThisExpression", "this");
michael@0 116
michael@0 117 // New/CallExpression + ObjectExpression + MemberExpression
michael@0 118
michael@0 119 verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "nested", "this.parent.foo.bar.nested");
michael@0 120 verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "bar", "this.parent.foo.bar");
michael@0 121 verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "foo", "this.parent.foo");
michael@0 122 verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "parent", "this.parent");
michael@0 123 verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.type == "ThisExpression", "this");
michael@0 124 verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "fun", "fun");
michael@0 125
michael@0 126 finish();
michael@0 127 }

mercurial