Bug 1099071 - Display error message in console for thrown empty string;r=bgrins

MozReview-Commit-ID: IhOFhDnyMpF
This commit is contained in:
AJ Kerrigan 2016-02-19 00:32:57 -05:00
Родитель 1db30ea608
Коммит 9a49ea4d03
4 изменённых файлов: 31 добавлений и 2 удалений

Просмотреть файл

@ -1349,7 +1349,7 @@ Messages.JavaScriptEvalOutput = function(evalResponse, errorMessage)
// be useful to extensions customizing the console output.
this.response = evalResponse;
if (errorMessage) {
if (typeof(errorMessage) !== "undefined") {
severity = "error";
msg = errorMessage;
quoteStrings = false;

Просмотреть файл

@ -308,6 +308,11 @@ JSTerm.prototype = {
return;
}
let errorMessage = response.exceptionMessage;
// Wrap thrown strings in Error objects, so `throw "foo"` outputs
// "Error: foo"
if (typeof(response.exception) === "string") {
errorMessage = new Error(errorMessage).toString();
}
let result = response.result;
let helperResult = response.helperResult;
let helperHasRawOutput = !!(helperResult || {}).rawOutput;

Просмотреть файл

@ -142,4 +142,28 @@ function* testJSTerm(hud) {
jsterm.clearOutput();
yield jsterm.execute("undefined");
yield checkResult("undefined", "undefined is printed");
// check that thrown strings produce error messages,
// and the message text matches that of a stringified error object
// bug 1099071
jsterm.clearOutput();
yield jsterm.execute("throw '';");
yield checkResult((node) => {
return node.parentNode.getAttribute("severity") === "error" &&
node.textContent === new Error("").toString();
}, "thrown empty string generates error message");
jsterm.clearOutput();
yield jsterm.execute("throw 'tomatoes';");
yield checkResult((node) => {
return node.parentNode.getAttribute("severity") === "error" &&
node.textContent === new Error("tomatoes").toString();
}, "thrown non-empty string generates error message");
jsterm.clearOutput();
yield jsterm.execute("throw { foo: 'bar' };");
yield checkResult((node) => {
return node.parentNode.getAttribute("severity") === "error" &&
node.textContent === Object.prototype.toString();
}, "thrown object generates error message");
}

Просмотреть файл

@ -1,5 +1,5 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft= javascript ts=2 et sw=2 tw=80: */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */