browser/devtools/debugger/test/browser_dbg_parser-06.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 * Check that some potentially problematic identifier nodes have the
michael@0 6 * right location information attached.
michael@0 7 */
michael@0 8
michael@0 9 function test() {
michael@0 10 let { Parser, ParserHelpers, SyntaxTreeVisitor } =
michael@0 11 Cu.import("resource:///modules/devtools/Parser.jsm", {});
michael@0 12
michael@0 13 function verify(source, predicate, [sline, scol], [eline, ecol]) {
michael@0 14 let ast = Parser.reflectionAPI.parse(source);
michael@0 15 let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
michael@0 16 let loc = ParserHelpers.getNodeLocation(node);
michael@0 17
michael@0 18 is(loc.start.toSource(), { line: sline, column: scol }.toSource(),
michael@0 19 "The start location was correct for the identifier in: '" + source + "'.");
michael@0 20 is(loc.end.toSource(), { line: eline, column: ecol }.toSource(),
michael@0 21 "The end location was correct for the identifier in: '" + source + "'.");
michael@0 22 }
michael@0 23
michael@0 24 // FunctionDeclarations and FunctionExpressions.
michael@0 25
michael@0 26 // The location is unavailable for the identifier node "foo".
michael@0 27 verify("function foo(){}", e => e.name == "foo", [1, 9], [1, 12]);
michael@0 28 verify("\nfunction\nfoo\n(\n)\n{\n}\n", e => e.name == "foo", [3, 0], [3, 3]);
michael@0 29
michael@0 30 verify("({bar:function foo(){}})", e => e.name == "foo", [1, 15], [1, 18]);
michael@0 31 verify("(\n{\nbar\n:\nfunction\nfoo\n(\n)\n{\n}\n}\n)", e => e.name == "foo", [6, 0], [6, 3]);
michael@0 32
michael@0 33 // Just to be sure, check the identifier node "bar" as well.
michael@0 34 verify("({bar:function foo(){}})", e => e.name == "bar", [1, 2], [1, 5]);
michael@0 35 verify("(\n{\nbar\n:\nfunction\nfoo\n(\n)\n{\n}\n}\n)", e => e.name == "bar", [3, 0], [3, 3]);
michael@0 36
michael@0 37 // MemberExpressions.
michael@0 38
michael@0 39 // The location is unavailable for the identifier node "bar".
michael@0 40 verify("foo.bar", e => e.name == "bar", [1, 4], [1, 7]);
michael@0 41 verify("\nfoo\n.\nbar\n", e => e.name == "bar", [4, 0], [4, 3]);
michael@0 42
michael@0 43 // Just to be sure, check the identifier node "foo" as well.
michael@0 44 verify("foo.bar", e => e.name == "foo", [1, 0], [1, 3]);
michael@0 45 verify("\nfoo\n.\nbar\n", e => e.name == "foo", [2, 0], [2, 3]);
michael@0 46
michael@0 47 // VariableDeclarator
michael@0 48
michael@0 49 // The location is incorrect for the identifier node "foo".
michael@0 50 verify("let foo = bar", e => e.name == "foo", [1, 4], [1, 7]);
michael@0 51 verify("\nlet\nfoo\n=\nbar\n", e => e.name == "foo", [3, 0], [3, 3]);
michael@0 52
michael@0 53 // Just to be sure, check the identifier node "bar" as well.
michael@0 54 verify("let foo = bar", e => e.name == "bar", [1, 10], [1, 13]);
michael@0 55 verify("\nlet\nfoo\n=\nbar\n", e => e.name == "bar", [5, 0], [5, 3]);
michael@0 56
michael@0 57 // Just to be sure, check AssignmentExpreesions as well.
michael@0 58 verify("foo = bar", e => e.name == "foo", [1, 0], [1, 3]);
michael@0 59 verify("\nfoo\n=\nbar\n", e => e.name == "foo", [2, 0], [2, 3]);
michael@0 60 verify("foo = bar", e => e.name == "bar", [1, 6], [1, 9]);
michael@0 61 verify("\nfoo\n=\nbar\n", e => e.name == "bar", [4, 0], [4, 3]);
michael@0 62
michael@0 63 // LabeledStatement and ContinueStatement, because it's 1968 again
michael@0 64
michael@0 65 verify("foo: bar", e => e.name == "foo", [1, 0], [1, 3]);
michael@0 66 verify("\nfoo\n:\nbar\n", e => e.name == "foo", [2, 0], [2, 3]);
michael@0 67
michael@0 68 verify("foo: for(;;) continue foo", e => e.name == "foo", [1, 22], [1, 25]);
michael@0 69 verify("\nfoo\n:\nfor(\n;\n;\n)\ncontinue\nfoo\n", e => e.name == "foo", [9, 0], [9, 3]);
michael@0 70
michael@0 71 finish();
michael@0 72 }

mercurial