mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 17:25:36 +00:00
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:
parent
85044e0002
commit
d9a179c704
@ -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 (
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user