Bug 1436110 - Fix rendering of thrown string in evaluation results; r=bgrins.

If the user tried to evaluate `throw ""`, an "undefined" message was displayed
in the console output, which is wrong. Some changes needed to be made to the
messages util to better handle those cases.

MozReview-Commit-ID: Is5pJYB2N48

--HG--
extra : rebase_source : 90a95af6bf7f5046e652b02263ae118fc4156693
This commit is contained in:
Nicolas Chevobbe 2018-02-07 09:42:13 +01:00
parent 85044e0002
commit d9a179c704
2 changed files with 13 additions and 6 deletions

View File

@ -44,7 +44,7 @@ function EvaluationResult(props) {
} = message;
let messageBody;
if (message.messageText) {
if (typeof message.messageText !== "undefined" && message.messageText !== null) {
if (typeof message.messageText === "string") {
messageBody = message.messageText;
} else if (

View File

@ -243,8 +243,9 @@ function transformNetworkEventPacket(packet) {
function transformEvaluationResultPacket(packet) {
let {
exceptionMessage: messageText,
exceptionMessage,
exceptionDocURL,
exception,
frame,
result,
helperResult,
@ -258,19 +259,25 @@ function transformEvaluationResultPacket(packet) {
if (helperResult && helperResult.type === "error") {
try {
messageText = l10n.getStr(helperResult.message);
exceptionMessage = l10n.getStr(helperResult.message);
} catch (ex) {
messageText = helperResult.message;
exceptionMessage = helperResult.message;
}
} else if (typeof exception === "string") {
// Wrap thrown strings in Error objects, so `throw "foo"` outputs "Error: foo"
exceptionMessage = new Error(exceptionMessage).toString();
}
const level = messageText ? MESSAGE_LEVEL.ERROR : MESSAGE_LEVEL.LOG;
const level = typeof exceptionMessage !== "undefined" && exceptionMessage !== null
? MESSAGE_LEVEL.ERROR
: MESSAGE_LEVEL.LOG;
return new ConsoleMessage({
source: MESSAGE_SOURCE.JAVASCRIPT,
type: MESSAGE_TYPE.RESULT,
helperType: helperResult ? helperResult.type : null,
level,
messageText,
messageText: exceptionMessage,
parameters: [parameter],
exceptionDocURL,
frame,