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
--- a/devtools/client/webconsole/new-console-output/components/message-types/EvaluationResult.js
+++ b/devtools/client/webconsole/new-console-output/components/message-types/EvaluationResult.js
@@ -39,17 +39,17 @@ function EvaluationResult(props) {
exceptionDocURL,
frame,
timeStamp,
parameters,
notes,
} = message;
let messageBody;
- if (message.messageText) {
+ if (typeof message.messageText !== "undefined" && message.messageText !== null) {
if (typeof message.messageText === "string") {
messageBody = message.messageText;
} else if (
typeof message.messageText === "object"
&& message.messageText.type === "longString"
) {
messageBody = `${message.messageText.initial}…`;
}
--- a/devtools/client/webconsole/new-console-output/utils/messages.js
+++ b/devtools/client/webconsole/new-console-output/utils/messages.js
@@ -238,44 +238,51 @@ function transformNetworkEventPacket(pac
method: networkEvent.request.method,
updates: networkEvent.updates,
cause: networkEvent.cause,
});
}
function transformEvaluationResultPacket(packet) {
let {
- exceptionMessage: messageText,
+ exceptionMessage,
exceptionDocURL,
+ exception,
frame,
result,
helperResult,
timestamp: timeStamp,
notes,
} = packet;
const parameter = helperResult && helperResult.object
? helperResult.object
: result;
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,
timeStamp,
notes,
});
}