Bug 1726237 - [devtools] Fix intermittent failures with error type getGrids failed r=jdescottes

This also removes `ignoreGetGridsPromiseRejections` which was used to ignore
the rejections from the promise failure.

Differential Revision: https://phabricator.services.mozilla.com/D123054
This commit is contained in:
Hubert Boma Manilla 2021-08-26 18:32:12 +00:00
Родитель 8b804a5de3
Коммит a1ca9092e3
9 изменённых файлов: 21 добавлений и 25 удалений

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

@ -4,6 +4,7 @@
"use strict";
const { safeAsyncMethod } = require("devtools/shared/async-utils");
const {
FrontClassWithSpec,
registerFront,
@ -147,6 +148,15 @@ class GridFront extends FrontClassWithSpec(gridSpec) {
}
class LayoutFront extends FrontClassWithSpec(layoutSpec) {
constructor(client, targetFront, parentFront) {
super(client, targetFront, parentFront);
this.getAllGrids = safeAsyncMethod(
this.getAllGrids.bind(this),
() => this.isDestroyed(),
[]
);
}
/**
* Get the WalkerFront instance that owns this LayoutFront.
*/
@ -155,6 +165,9 @@ class LayoutFront extends FrontClassWithSpec(layoutSpec) {
}
getAllGrids() {
if (!this.walkerFront.rootNode) {
return [];
}
return this.getGrids(this.walkerFront.rootNode);
}
}

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

@ -27,8 +27,6 @@ const TEST_URI = `
</div>
`;
ignoreGetGridsPromiseRejections();
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));

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

@ -18,8 +18,6 @@ const TEST_URI = `
</div>
`;
ignoreGetGridsPromiseRejections();
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));

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

@ -31,8 +31,6 @@ const OTHER_URI = `
</div>
`;
ignoreGetGridsPromiseRejections();
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { gridInspector, inspector } = await openLayoutView();

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

@ -30,8 +30,6 @@ const TEST_URI = `
</div>
`;
ignoreGetGridsPromiseRejections();
add_task(async function() {
await pushPref("devtools.gridinspector.maxHighlighters", 3);
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));

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

@ -19,8 +19,6 @@ const TEST_URI = `
const TEST_URI_2 = "data:text/html,<html><body>test</body></html>";
ignoreGetGridsPromiseRejections();
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, view } = await openRuleView();

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

@ -22,8 +22,6 @@ const TEST_URI = `
<div></div>
`;
ignoreGetGridsPromiseRejections();
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const { inspector, view: ruleView, toolbox } = await openRuleView();

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

@ -929,14 +929,3 @@ async function removeContentPageElementAttribute(selector, attribute) {
}
);
}
function ignoreGetGridsPromiseRejections() {
const { PromiseTestUtils } = ChromeUtils.import(
"resource://testing-common/PromiseTestUtils.jsm"
);
// Once Bug 1655422 is done we should cleanup the functions
// added globally. See Bug 1725565
PromiseTestUtils.allowMatchingRejectionsGlobally(
/Connection closed.*getGrids failed/
);
}

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

@ -47,9 +47,15 @@ const SWALLOWED_RET = Symbol("swallowed");
* @param {Function} shouldSwallow
* Function that will run when an error is caught. If it returns true,
* the error will be swallowed. Otherwise, it will bubble up.
* @param {Mixed} retValue
* Optional value to return when an error is caught and is swallowed.
* @return {Function} The wrapped method.
*/
exports.safeAsyncMethod = function(asyncFn, shouldSwallow) {
exports.safeAsyncMethod = function(
asyncFn,
shouldSwallow,
retValue = SWALLOWED_RET
) {
return async function(...args) {
try {
const ret = await asyncFn(...args);
@ -57,7 +63,7 @@ exports.safeAsyncMethod = function(asyncFn, shouldSwallow) {
} catch (e) {
if (shouldSwallow()) {
console.warn("Async method failed in safeAsyncMethod", e);
return SWALLOWED_RET;
return retValue;
}
throw e;
}