Bug 1436110 - Fix rendering of thrown string in evaluation results; r=bgrins.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Wed, 07 Feb 2018 09:42:13 +0100
changeset 403559 5d3f2a7dfdc9ee36c43fcdf04e25b49e426c908a
parent 403558 f26d2eac74fba21b4b1c9f5475035148962ed18d
child 403560 719f138bc9d8ccd986f5a28ccb55d11e2366bbb2
push id33438
push userrgurzau@mozilla.com
push dateWed, 14 Feb 2018 10:46:56 +0000
treeherdermozilla-central@c48e46d5edbf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1436110
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
devtools/client/webconsole/new-console-output/components/message-types/EvaluationResult.js
devtools/client/webconsole/new-console-output/utils/messages.js
--- 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,
   });
 }