Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 /**
5 * Check that some potentially problematic identifier nodes have the
6 * right location information attached.
7 */
9 function test() {
10 let { Parser, ParserHelpers, SyntaxTreeVisitor } =
11 Cu.import("resource:///modules/devtools/Parser.jsm", {});
13 function verify(source, predicate, [sline, scol], [eline, ecol]) {
14 let ast = Parser.reflectionAPI.parse(source);
15 let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
16 let loc = ParserHelpers.getNodeLocation(node);
18 is(loc.start.toSource(), { line: sline, column: scol }.toSource(),
19 "The start location was correct for the identifier in: '" + source + "'.");
20 is(loc.end.toSource(), { line: eline, column: ecol }.toSource(),
21 "The end location was correct for the identifier in: '" + source + "'.");
22 }
24 // FunctionDeclarations and FunctionExpressions.
26 // The location is unavailable for the identifier node "foo".
27 verify("function foo(){}", e => e.name == "foo", [1, 9], [1, 12]);
28 verify("\nfunction\nfoo\n(\n)\n{\n}\n", e => e.name == "foo", [3, 0], [3, 3]);
30 verify("({bar:function foo(){}})", e => e.name == "foo", [1, 15], [1, 18]);
31 verify("(\n{\nbar\n:\nfunction\nfoo\n(\n)\n{\n}\n}\n)", e => e.name == "foo", [6, 0], [6, 3]);
33 // Just to be sure, check the identifier node "bar" as well.
34 verify("({bar:function foo(){}})", e => e.name == "bar", [1, 2], [1, 5]);
35 verify("(\n{\nbar\n:\nfunction\nfoo\n(\n)\n{\n}\n}\n)", e => e.name == "bar", [3, 0], [3, 3]);
37 // MemberExpressions.
39 // The location is unavailable for the identifier node "bar".
40 verify("foo.bar", e => e.name == "bar", [1, 4], [1, 7]);
41 verify("\nfoo\n.\nbar\n", e => e.name == "bar", [4, 0], [4, 3]);
43 // Just to be sure, check the identifier node "foo" as well.
44 verify("foo.bar", e => e.name == "foo", [1, 0], [1, 3]);
45 verify("\nfoo\n.\nbar\n", e => e.name == "foo", [2, 0], [2, 3]);
47 // VariableDeclarator
49 // The location is incorrect for the identifier node "foo".
50 verify("let foo = bar", e => e.name == "foo", [1, 4], [1, 7]);
51 verify("\nlet\nfoo\n=\nbar\n", e => e.name == "foo", [3, 0], [3, 3]);
53 // Just to be sure, check the identifier node "bar" as well.
54 verify("let foo = bar", e => e.name == "bar", [1, 10], [1, 13]);
55 verify("\nlet\nfoo\n=\nbar\n", e => e.name == "bar", [5, 0], [5, 3]);
57 // Just to be sure, check AssignmentExpreesions as well.
58 verify("foo = bar", e => e.name == "foo", [1, 0], [1, 3]);
59 verify("\nfoo\n=\nbar\n", e => e.name == "foo", [2, 0], [2, 3]);
60 verify("foo = bar", e => e.name == "bar", [1, 6], [1, 9]);
61 verify("\nfoo\n=\nbar\n", e => e.name == "bar", [4, 0], [4, 3]);
63 // LabeledStatement and ContinueStatement, because it's 1968 again
65 verify("foo: bar", e => e.name == "foo", [1, 0], [1, 3]);
66 verify("\nfoo\n:\nbar\n", e => e.name == "foo", [2, 0], [2, 3]);
68 verify("foo: for(;;) continue foo", e => e.name == "foo", [1, 22], [1, 25]);
69 verify("\nfoo\n:\nfor(\n;\n;\n)\ncontinue\nfoo\n", e => e.name == "foo", [9, 0], [9, 3]);
71 finish();
72 }