Bug 1710694 - [devtools] Fix custom error with message getter. r=ladybenko.

In the case a custom error object was defining the `name` and/or `message` property
in getters, we weren't displaying those information in the console.
That's because when retrieving those information, we were avoiding calling getters,
as they're deemed unsafe.
In those specific case, even if unsafe, we always want to show it to the user
so they're not missing any information when debugging.

A test case is added to ensure this works as expected and we don't regress.

Differential Revision: https://phabricator.services.mozilla.com/D115678
This commit is contained in:
Nicolas Chevobbe 2021-05-26 12:06:05 +00:00
Родитель 2314b37da7
Коммит 96a25e628e
2 изменённых файлов: 46 добавлений и 4 удалений

Просмотреть файл

@ -37,6 +37,34 @@ add_task(async function() {
`Uncaught Object { fav: "eggplant" }`
);
info("Check custom error with name and message getters");
// register the class
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
const script = content.document.createElement("script");
script.append(
content.document.createTextNode(
`
class CustomError extends Error {
get name() {
return "CustomErrorName";
}
get message() {
return "custom-error-message";
}
}`.trim()
)
);
content.document.body.append(script);
});
await checkThrowingWithStack(
hud,
`new CustomError()`,
"Uncaught CustomErrorName: custom-error-message",
// Additional frames: the stacktrace contains the CustomError call
[1]
);
info("Check that object in errors can be expanded");
const rejectedObjectMessage = findMessage(hud, "eggplant", ".error");
const oi = rejectedObjectMessage.querySelector(".tree");
@ -67,7 +95,12 @@ add_task(async function() {
ok(oiNodes[2].textContent.includes(`<prototype>: Object { \u2026 }`));
});
async function checkThrowingWithStack(hud, expression, expectedMessage) {
async function checkThrowingWithStack(
hud,
expression,
expectedMessage,
additionalFrameLines = []
) {
await SpecialPowers.spawn(gBrowser.selectedBrowser, [expression], function(
expr
) {
@ -84,5 +117,12 @@ async function checkThrowingWithStack(hud, expression, expectedMessage) {
content.document.body.append(script);
script.remove();
});
return checkMessageStack(hud, expectedMessage, [2, 3, 4, 5, 6]);
return checkMessageStack(hud, expectedMessage, [
...additionalFrameLines,
2,
3,
4,
5,
6,
]);
}

Просмотреть файл

@ -599,8 +599,10 @@ previewers.Object = [
case "DebuggeeWouldRun":
case "LinkError":
case "RuntimeError":
const name = DevToolsUtils.getProperty(obj, "name");
const msg = DevToolsUtils.getProperty(obj, "message");
// The name and/or message could be getters, and even if it's unsafe, we do want
// to show it to the user (See Bug 1710694).
const name = DevToolsUtils.getProperty(obj, "name", true);
const msg = DevToolsUtils.getProperty(obj, "message", true);
const stack = DevToolsUtils.getProperty(obj, "stack");
const fileName = DevToolsUtils.getProperty(obj, "fileName");
const lineNumber = DevToolsUtils.getProperty(obj, "lineNumber");