Bug 1822488 - [devtools] Display stacktraces for DOMException's. r=devtools-reviewers,nchevobbe

We are currently showing stacks for Error-like objects but not for DOMExceptions.
console.log("foo", new Error("bar")) would print bar's stacktraces, while we wouldn't for: console.log("foo", new DOMException("bar")).

Should we merge DOMException and Error previewers?
DOMException is only having code and result attributes which Error objects don't have.

Differential Revision: https://phabricator.services.mozilla.com/D172707
This commit is contained in:
Alexandre Poirot 2023-03-20 08:55:28 +00:00
parent 0f406fef0f
commit 9828f2bd31
3 changed files with 40 additions and 0 deletions

View File

@ -304,6 +304,7 @@ fail-if = a11y_checks # bug 1687728 frame-link-filename is not accessible
[browser_webconsole_location_styleeditor_link.js]
fail-if = a11y_checks # bug 1687728 frame-link-filename is not accessible
[browser_webconsole_logErrorInPage.js]
[browser_webconsole_logging_exceptions.js]
[browser_webconsole_loglimit.js]
[browser_webconsole_logs_exceptions_order.js]
[browser_webconsole_logWarningInPage.js]

View File

@ -0,0 +1,38 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Check that logging exceptions works as expected
"use strict";
const TEST_URI =
`data:text/html;charset=utf8,` +
encodeURI(`<!DOCTYPE html><script>
const domExceptionOnLine2 = new DOMException("Bar");
/* console.error will be on line 4 */
console.error("Foo", domExceptionOnLine2);
</script>`);
add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
info("Wait for the error to be logged");
const msgNode = await waitFor(() => findConsoleAPIMessage(hud, "Foo"));
ok(!msgNode.classList.contains("open"), `Error logged not expanded`);
const framesNode = await waitFor(() => msgNode.querySelector(".pane.frames"));
ok(framesNode, "The DOMException stack is displayed right away");
const frameNodes = framesNode.querySelectorAll(".frame");
is(frameNodes.length, 1, "Expected frames are displayed");
is(
frameNodes[0].querySelector(".line").textContent,
"2",
"The stack displayed by default refers to second argument passed to console.error and refers to DOMException callsite"
);
info(
"Check that the console.error stack is refering to console.error() callsite"
);
await checkMessageStack(hud, "Foo", [4]);
});

View File

@ -1085,6 +1085,7 @@ previewers.Object = [
filename: hooks.createValueGrip(rawObj.filename),
lineNumber: hooks.createValueGrip(rawObj.lineNumber),
columnNumber: hooks.createValueGrip(rawObj.columnNumber),
stack: hooks.createValueGrip(rawObj.stack),
};
return true;