зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1607569 - Fix leak in browser_console_devtools_loader_exception. r=ochameau.
In the Browser toolbox destroy function, we now wait for any pending connection initialization promise. In the test we close the browser toolbox at the end. We also need to guard a few method in the connection proxy to ensure the instances we use are still alive before using them. Differential Revision: https://phabricator.services.mozilla.com/D71171
This commit is contained in:
Родитель
c9c76fff5a
Коммит
90668a72e5
|
@ -113,6 +113,11 @@ class BrowserConsole extends WebConsole {
|
|||
// toolbox session id.
|
||||
this._telemetry.toolClosed("browserconsole", -1, this);
|
||||
|
||||
// Wait for any pending connection initialization.
|
||||
await Promise.all(
|
||||
this.ui.getAllProxies().map(proxy => proxy.getConnectionPromise())
|
||||
);
|
||||
|
||||
await this.targetList.stopListening();
|
||||
await super.destroy();
|
||||
await this.currentTarget.destroy();
|
||||
|
|
|
@ -10,6 +10,10 @@ const TEST_URI =
|
|||
"data:text/html;charset=utf8,<p>browser_console_devtools_loader_exception.js</p>";
|
||||
|
||||
add_task(async function() {
|
||||
// Disable the preloaded process as it creates processes intermittently
|
||||
// which forces the emission of RDP requests we aren't correctly waiting for.
|
||||
await pushPref("dom.ipc.processPrelaunch.enabled", false);
|
||||
|
||||
const wcHud = await openNewTabAndConsole(TEST_URI);
|
||||
ok(wcHud, "web console opened");
|
||||
|
||||
|
@ -60,4 +64,6 @@ add_task(async function() {
|
|||
ok(true, "The view source tab was opened in response to clicking the link");
|
||||
|
||||
await BrowserTestUtils.removeTab(newTab);
|
||||
info("Close browser console");
|
||||
await BrowserConsoleManager.closeBrowserConsole();
|
||||
});
|
||||
|
|
|
@ -59,6 +59,10 @@ class WebConsoleConnectionProxy {
|
|||
return this._connecter;
|
||||
}
|
||||
|
||||
if (!this.target.client) {
|
||||
return Promise.reject("target was destroyed");
|
||||
}
|
||||
|
||||
this.target.on("will-navigate", this._onTabWillNavigate);
|
||||
this.target.on("navigate", this._onTabNavigated);
|
||||
|
||||
|
@ -82,7 +86,7 @@ class WebConsoleConnectionProxy {
|
|||
|
||||
this._addWebConsoleFrontEventListeners();
|
||||
|
||||
if (!this.webConsoleFront.hasNativeConsoleAPI) {
|
||||
if (this.webConsoleFront && !this.webConsoleFront.hasNativeConsoleAPI) {
|
||||
await this.webConsoleUI.logWarningAboutReplacedAPI();
|
||||
}
|
||||
})();
|
||||
|
@ -108,12 +112,20 @@ class WebConsoleConnectionProxy {
|
|||
return this._connecter;
|
||||
}
|
||||
|
||||
getConnectionPromise() {
|
||||
return this._connecter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach to the Web Console actor.
|
||||
* @private
|
||||
* @returns Promise
|
||||
*/
|
||||
_attachConsole() {
|
||||
if (!this.webConsoleFront) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const listeners = ["NetworkActivity"];
|
||||
// Enable the forwarding of console messages to the parent process
|
||||
// when we open the Browser Console or Toolbox without fission support. If Fission
|
||||
|
@ -131,6 +143,10 @@ class WebConsoleConnectionProxy {
|
|||
* @private
|
||||
*/
|
||||
_addWebConsoleFrontEventListeners() {
|
||||
if (!this.webConsoleFront) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.webConsoleFront.on("networkEvent", this._onNetworkEvent);
|
||||
this.webConsoleFront.on("networkEventUpdate", this._onNetworkEventUpdate);
|
||||
this.webConsoleFront.on(
|
||||
|
@ -168,13 +184,20 @@ class WebConsoleConnectionProxy {
|
|||
* @returns An array of network messages.
|
||||
*/
|
||||
_getNetworkMessages() {
|
||||
if (!this.webConsoleFront) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.from(this.webConsoleFront.getNetworkEvents());
|
||||
}
|
||||
|
||||
_clearLogpointMessages(logpointId) {
|
||||
if (this.webConsoleUI) {
|
||||
this.webConsoleUI.wrapper.dispatchClearLogpointMessages(logpointId);
|
||||
// Some message might try to update while we are closing the toolbox.
|
||||
if (!this.webConsoleUI?.wrapper) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.webConsoleUI.wrapper.dispatchClearLogpointMessages(logpointId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,9 +209,6 @@ class WebConsoleConnectionProxy {
|
|||
* The network request information.
|
||||
*/
|
||||
_onNetworkEvent(networkInfo) {
|
||||
if (!this.webConsoleUI) {
|
||||
return;
|
||||
}
|
||||
this.dispatchMessageAdd(networkInfo);
|
||||
}
|
||||
|
||||
|
@ -201,9 +221,6 @@ class WebConsoleConnectionProxy {
|
|||
* The update response received from the server.
|
||||
*/
|
||||
_onNetworkEventUpdate(response) {
|
||||
if (!this.webConsoleUI) {
|
||||
return;
|
||||
}
|
||||
this.dispatchMessageUpdate(response.networkInfo, response);
|
||||
}
|
||||
|
||||
|
@ -231,6 +248,10 @@ class WebConsoleConnectionProxy {
|
|||
* The message received from the server.
|
||||
*/
|
||||
_onTabNavigated(packet) {
|
||||
// Some message might try to update while we are closing the toolbox.
|
||||
if (!this.webConsoleUI) {
|
||||
return;
|
||||
}
|
||||
this.webConsoleUI.handleTabNavigated(packet);
|
||||
}
|
||||
|
||||
|
@ -242,6 +263,10 @@ class WebConsoleConnectionProxy {
|
|||
* The message received from the server.
|
||||
*/
|
||||
_onTabWillNavigate(packet) {
|
||||
// Some message might try to update while we are closing the toolbox.
|
||||
if (!this.webConsoleUI) {
|
||||
return;
|
||||
}
|
||||
this.webConsoleUI.handleTabWillNavigate(packet);
|
||||
}
|
||||
|
||||
|
@ -249,6 +274,10 @@ class WebConsoleConnectionProxy {
|
|||
* Dispatch a message add on the new frontend and emit an event for tests.
|
||||
*/
|
||||
dispatchMessageAdd(packet) {
|
||||
// Some message might try to update while we are closing the toolbox.
|
||||
if (!this.webConsoleUI?.wrapper) {
|
||||
return;
|
||||
}
|
||||
this.webConsoleUI.wrapper.dispatchMessageAdd(packet);
|
||||
}
|
||||
|
||||
|
@ -256,6 +285,10 @@ class WebConsoleConnectionProxy {
|
|||
* Batched dispatch of messages.
|
||||
*/
|
||||
dispatchMessagesAdd(packets) {
|
||||
// Some message might try to update while we are closing the toolbox.
|
||||
if (!this.webConsoleUI?.wrapper) {
|
||||
return;
|
||||
}
|
||||
this.webConsoleUI.wrapper.dispatchMessagesAdd(packets);
|
||||
}
|
||||
|
||||
|
@ -264,7 +297,7 @@ class WebConsoleConnectionProxy {
|
|||
*/
|
||||
dispatchMessageUpdate(networkInfo, response) {
|
||||
// Some message might try to update while we are closing the toolbox.
|
||||
if (!this.webConsoleUI) {
|
||||
if (!this.webConsoleUI?.wrapper) {
|
||||
return;
|
||||
}
|
||||
this.webConsoleUI.wrapper.dispatchMessageUpdate(networkInfo, response);
|
||||
|
|
Загрузка…
Ссылка в новой задаче