fune/remote/shared/messagehandler/Module.jsm
Julian Descottes 69fa6f5492 Bug 1726800 - [remote] Verify commands as early as possible in MessageHandler r=webdriver-reviewers,whimboo
Depends on D123655
With this patch, the MessageHandler can immediately check if a command is implemented by the modules, and therefore reject as early as possible.
This is implemented via a checkCommand method on MessageHandler.

Other required changes:
- ModuleRegistry now owns the logic to import BiDi modules.
- ModuleCache exposes a `getAllModuleClasses` to get all the relevant modules for a moduleName+destination pair.

Error messages have been improved and are verified with a dedicated test

Differential Revision: https://phabricator.services.mozilla.com/D123655
2021-10-12 16:48:43 +00:00

44 lines
1.1 KiB
JavaScript

/* 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 = ["Module"];
class Module {
/**
* Create a new module instance.
*
* @param {MessageHandler} messageHandler
* The MessageHandler instance which owns this Module instance.
*/
constructor(messageHandler) {
this._messageHandler = messageHandler;
}
/**
* Clean-up the module instance.
*
* It's required to be implemented in the sub class.
*/
destroy() {
throw new Error("Not implemented");
}
/**
* Instance shortcut for supportsMethod to avoid reaching the constructor for
* consumers which directly deal with an instance.
*/
supportsMethod(methodName) {
return this.constructor.supportsMethod(methodName);
}
get messageHandler() {
return this._messageHandler;
}
static supportsMethod(methodName) {
return typeof this.prototype[methodName] === "function";
}
}