зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1770492 - [messagehandler] Support emitting protocol errors from MessageHandler modules r=webdriver-reviewers,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D151034
This commit is contained in:
Родитель
3dd6f50995
Коммит
75eac83967
|
@ -19,6 +19,7 @@ remote.jar:
|
|||
content/shared/Navigate.jsm (shared/Navigate.jsm)
|
||||
content/shared/PDF.jsm (shared/PDF.jsm)
|
||||
content/shared/RecommendedPreferences.jsm (shared/RecommendedPreferences.jsm)
|
||||
content/shared/RemoteError.jsm (shared/RemoteError.jsm)
|
||||
content/shared/Stack.jsm (shared/Stack.jsm)
|
||||
content/shared/Sync.jsm (shared/Sync.jsm)
|
||||
content/shared/TabManager.jsm (shared/TabManager.jsm)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const EXPORTED_SYMBOLS = ["RemoteError"];
|
||||
|
||||
/**
|
||||
* Base class for all remote protocol errors.
|
||||
*/
|
||||
class RemoteError extends Error {
|
||||
get isRemoteError() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to a serializable object. Should be implemented by subclasses.
|
||||
*/
|
||||
toJSON() {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
}
|
|
@ -6,7 +6,11 @@
|
|||
|
||||
const EXPORTED_SYMBOLS = ["error"];
|
||||
|
||||
class MessageHandlerError extends Error {
|
||||
const { RemoteError } = ChromeUtils.import(
|
||||
"chrome://remote/content/shared/RemoteError.jsm"
|
||||
);
|
||||
|
||||
class MessageHandlerError extends RemoteError {
|
||||
/**
|
||||
* @param {(string|Error)=} x
|
||||
* Optional string describing error situation or Error instance
|
||||
|
@ -23,6 +27,10 @@ class MessageHandlerError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
get isMessageHandlerError() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Object.<string, string>}
|
||||
* JSON serialisation of error prototype.
|
||||
|
|
|
@ -13,7 +13,6 @@ const { XPCOMUtils } = ChromeUtils.importESModule(
|
|||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
error: "chrome://remote/content/shared/messagehandler/Errors.jsm",
|
||||
isBrowsingContextCompatible:
|
||||
"chrome://remote/content/shared/messagehandler/transports/FrameContextUtils.jsm",
|
||||
MessageHandlerRegistry:
|
||||
|
@ -59,9 +58,10 @@ class MessageHandlerFrameChild extends JSWindowActorChild {
|
|||
try {
|
||||
return await messageHandler.handleCommand(command);
|
||||
} catch (e) {
|
||||
if (e instanceof lazy.error.MessageHandlerError) {
|
||||
if (e?.isRemoteError) {
|
||||
return {
|
||||
error: e.toJSON(),
|
||||
isMessageHandlerError: e.isMessageHandlerError,
|
||||
};
|
||||
}
|
||||
throw e;
|
||||
|
|
|
@ -20,6 +20,12 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
|
|||
"chrome://remote/content/shared/messagehandler/WindowGlobalMessageHandler.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "WebDriverError", () => {
|
||||
return ChromeUtils.import(
|
||||
"chrome://remote/content/shared/webdriver/Errors.jsm"
|
||||
).error.WebDriverError;
|
||||
});
|
||||
|
||||
/**
|
||||
* Parent actor for the MessageHandlerFrame JSWindowActor. The
|
||||
* MessageHandlerFrame actor is used by FrameTransport to communicate between
|
||||
|
@ -86,7 +92,12 @@ class MessageHandlerFrameParent extends JSWindowActorParent {
|
|||
);
|
||||
|
||||
if (result?.error) {
|
||||
throw lazy.error.MessageHandlerError.fromJSON(result.error);
|
||||
if (result.isMessageHandlerError) {
|
||||
throw lazy.error.MessageHandlerError.fromJSON(result.error);
|
||||
}
|
||||
|
||||
// TODO: Do not assume WebDriver is the session protocol, see Bug 1779026.
|
||||
throw lazy.WebDriverError.fromJSON(result.error);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -10,6 +10,10 @@ const { XPCOMUtils } = ChromeUtils.importESModule(
|
|||
"resource://gre/modules/XPCOMUtils.sys.mjs"
|
||||
);
|
||||
|
||||
const { RemoteError } = ChromeUtils.import(
|
||||
"chrome://remote/content/shared/RemoteError.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
|
@ -178,7 +182,7 @@ const error = {
|
|||
* It should not be used directly, as it does not correspond to a real
|
||||
* error in the specification.
|
||||
*/
|
||||
class WebDriverError extends Error {
|
||||
class WebDriverError extends RemoteError {
|
||||
/**
|
||||
* @param {(string|Error)=} x
|
||||
* Optional string describing error situation or Error instance
|
||||
|
|
Загрузка…
Ссылка в новой задаче