зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1099071 - Display error message in console for thrown empty string;r=bgrins
MozReview-Commit-ID: IhOFhDnyMpF
This commit is contained in:
Родитель
1db30ea608
Коммит
9a49ea4d03
|
@ -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/. */
|
||||
|
|
Загрузка…
Ссылка в новой задаче