browser_dbg_parser-02.js 908 B

123456789101112131415161718192021222324252627282930
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. /**
  5. * Check that syntax errors are reported correctly.
  6. */
  7. function test() {
  8. let { Parser } = Cu.import("resource://devtools/shared/Parser.jsm", {});
  9. let source = "let x + 42;";
  10. let parser = new Parser();
  11. // Don't pollute the logs with exceptions that we are going to check anyhow.
  12. parser.logExceptions = false;
  13. let parsed = parser.get(source);
  14. ok(parsed,
  15. "An object should be returned even though the source had a syntax error.");
  16. is(parser.errors.length, 1,
  17. "There should be one error logged when parsing.");
  18. is(parser.errors[0].name, "SyntaxError",
  19. "The correct exception was caught.");
  20. is(parser.errors[0].message, "missing ; before statement",
  21. "The correct exception was caught.");
  22. finish();
  23. }