michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Check that faulty JS inside HTML can be separated and identified correctly. michael@0: */ michael@0: michael@0: function test() { michael@0: let { Parser } = Cu.import("resource:///modules/devtools/Parser.jsm", {}); michael@0: michael@0: let source = [ michael@0: "", michael@0: "
", michael@0: "", michael@0: "", michael@0: "", michael@0: "" michael@0: ].join("\n"); michael@0: let parser = new Parser(); michael@0: let parsed = parser.get(source); michael@0: michael@0: ok(parsed, michael@0: "HTML code should be parsed correctly."); michael@0: is(parser.errors.length, 2, michael@0: "There should be two errors logged when parsing."); michael@0: michael@0: is(parser.errors[0].name, "SyntaxError", michael@0: "The correct first exception was caught."); michael@0: is(parser.errors[0].message, "missing ; before statement", michael@0: "The correct first exception was caught."); michael@0: michael@0: is(parser.errors[1].name, "SyntaxError", michael@0: "The correct second exception was caught."); michael@0: is(parser.errors[1].message, "missing ; before statement", michael@0: "The correct second exception was caught."); michael@0: michael@0: is(parsed.scriptCount, 1, michael@0: "There should be 1 script parsed in the parent HTML source."); michael@0: michael@0: is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:-1, length:-1, index:-1})", michael@0: "The first script shouldn't be considered valid."); michael@0: is(parsed.getScriptInfo(source.indexOf("let b")).toSource(), "({start:85, length:13, index:0})", michael@0: "The second script was located correctly."); michael@0: is(parsed.getScriptInfo(source.indexOf("let c")).toSource(), "({start:-1, length:-1, index:-1})", michael@0: "The third script shouldn't be considered valid."); michael@0: michael@0: finish(); michael@0: }