browser/devtools/debugger/test/browser_dbg_parser-05.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.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Check that JS code containing strings that might look like <script> tags
     6  * inside an HTML source is parsed correctly.
     7  */
     9 function test() {
    10   let { Parser } = Cu.import("resource:///modules/devtools/Parser.jsm", {});
    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);
    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.");
    32   is(parsed.scriptCount, 1,
    33     "There should be 1 script parsed in the parent source.");
    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).");
    42   finish();
    43 }

mercurial