bug 1543115: remote: make RemoteAgent.listen() accept strings; r=remote-protocol-reviewers,maja_zf

Crafting nsIURIs in Rust is complicated.  Allow RemoteAgent.listen()
to accept both strings and nsIURIs when called in JavaScript.

Differential Revision: https://phabricator.services.mozilla.com/D50286

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andreas Tolfsen 2019-11-19 12:32:46 +00:00
parent e29e510bb0
commit e02175a9ab

View File

@ -36,7 +36,7 @@ class RemoteAgentClass {
return !!this.server && !this.server.isStopped();
}
async listen(address) {
async listen(url) {
if (!Preferences.get(ENABLED, false)) {
throw new Error("Remote agent is disabled by preference");
}
@ -46,11 +46,11 @@ class RemoteAgentClass {
);
}
if (!(address instanceof Ci.nsIURI)) {
throw new TypeError(`Expected nsIURI: ${address}`);
if (!(url instanceof Ci.nsIURI)) {
url = Services.io.newURI(url);
}
let { host, port } = address;
let { host, port } = url;
if (Preferences.get(FORCE_LOCAL) && !LOOPBACKS.includes(host)) {
throw new Error("Restricted to loopback devices");
}