|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Check that JS code containing strings that might look like <script> tags |
|
6 * inside an HTML source is parsed correctly. |
|
7 */ |
|
8 |
|
9 function test() { |
|
10 let { Parser } = Cu.import("resource:///modules/devtools/Parser.jsm", {}); |
|
11 |
|
12 let source = [ |
|
13 "let a = [];", |
|
14 "a.push('<script>');", |
|
15 "a.push('var a = 42;');", |
|
16 "a.push('</script>');", |
|
17 "a.push('<script type=\"text/javascript\">');", |
|
18 "a.push('var b = 42;');", |
|
19 "a.push('</script>');", |
|
20 "a.push('<script type=\"text/javascript;version=1.8\">');", |
|
21 "a.push('var c = 42;');", |
|
22 "a.push('</script>');" |
|
23 ].join("\n"); |
|
24 let parser = new Parser(); |
|
25 let parsed = parser.get(source); |
|
26 |
|
27 ok(parsed, |
|
28 "The javascript code should be parsed correctly."); |
|
29 is(parser.errors.length, 0, |
|
30 "There should be no errors logged when parsing."); |
|
31 |
|
32 is(parsed.scriptCount, 1, |
|
33 "There should be 1 script parsed in the parent source."); |
|
34 |
|
35 is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:0, length:261, index:0})", |
|
36 "The script location is correct (1)."); |
|
37 is(parsed.getScriptInfo(source.indexOf("<script>")).toSource(), "({start:0, length:261, index:0})", |
|
38 "The script location is correct (2)."); |
|
39 is(parsed.getScriptInfo(source.indexOf("</script>")).toSource(), "({start:0, length:261, index:0})", |
|
40 "The script location is correct (3)."); |
|
41 |
|
42 finish(); |
|
43 } |