Skip to content

Commit 986f958

Browse files
committedNov 25, 2022
Bug 1541508 - Use Services.env in remote/ r=whimboo,webdriver-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D160144
1 parent 4e91678 commit 986f958

File tree

3 files changed

+6
-35
lines changed

3 files changed

+6
-35
lines changed
 

‎remote/components/Marionette.sys.mjs

+2-9
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ XPCOMUtils.defineLazyGetter(lazy, "logger", () =>
2424

2525
XPCOMUtils.defineLazyGetter(lazy, "textEncoder", () => new TextEncoder());
2626

27-
XPCOMUtils.defineLazyServiceGetter(
28-
lazy,
29-
"env",
30-
"@mozilla.org/process/environment;1",
31-
"nsIEnvironment"
32-
);
33-
3427
const NOTIFY_LISTENING = "marionette-listening";
3528

3629
// Complements -marionette flag for starting the Marionette server.
@@ -72,7 +65,7 @@ class MarionetteParentProcess {
7265
this.helpInfo = " --marionette Enable remote control server.\n";
7366

7467
// Initially set the enabled state based on the environment variable.
75-
this.enabled = lazy.env.exists(ENV_ENABLED);
68+
this.enabled = Services.env.exists(ENV_ENABLED);
7669

7770
Services.ppmm.addMessageListener("Marionette:IsRunning", this);
7871

@@ -238,7 +231,7 @@ class MarionetteParentProcess {
238231
return;
239232
}
240233

241-
lazy.env.set(ENV_ENABLED, "1");
234+
Services.env.set(ENV_ENABLED, "1");
242235
Services.obs.notifyObservers(this, NOTIFY_LISTENING, true);
243236
lazy.logger.debug("Marionette is listening");
244237

‎remote/marionette/prefs.sys.mjs

+2-13
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
6-
7-
const lazy = {};
8-
9-
XPCOMUtils.defineLazyServiceGetter(
10-
lazy,
11-
"env",
12-
"@mozilla.org/process/environment;1",
13-
"nsIEnvironment"
14-
);
15-
165
const { PREF_BOOL, PREF_INT, PREF_INVALID, PREF_STRING } = Ci.nsIPrefBranch;
176

187
export class Branch {
@@ -169,13 +158,13 @@ export class EnvironmentPrefs {
169158
* @return {Iterable.<string, (string|boolean|number)>
170159
*/
171160
static *from(key) {
172-
if (!lazy.env.exists(key)) {
161+
if (!Services.env.exists(key)) {
173162
return;
174163
}
175164

176165
let prefs;
177166
try {
178-
prefs = JSON.parse(lazy.env.get(key));
167+
prefs = JSON.parse(Services.env.get(key));
179168
} catch (e) {
180169
throw new TypeError(`Unable to parse prefs from ${key}`, e);
181170
}

‎remote/marionette/test/xpcshell/test_prefs.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44

55
"use strict";
66

7-
const { XPCOMUtils } = ChromeUtils.importESModule(
8-
"resource://gre/modules/XPCOMUtils.sys.mjs"
9-
);
10-
11-
XPCOMUtils.defineLazyServiceGetter(
12-
this,
13-
"env",
14-
"@mozilla.org/process/environment;1",
15-
"nsIEnvironment"
16-
);
17-
187
const {
198
Branch,
209
EnvironmentPrefs,
@@ -94,14 +83,14 @@ add_test(function test_EnvironmentPrefs_from() {
9483
"test.int": 888,
9584
"test.string": "bar",
9685
};
97-
env.set("FOO", JSON.stringify(prefsTable));
86+
Services.env.set("FOO", JSON.stringify(prefsTable));
9887

9988
try {
10089
for (let [key, value] of EnvironmentPrefs.from("FOO")) {
10190
equal(prefsTable[key], value);
10291
}
10392
} finally {
104-
env.set("FOO", null);
93+
Services.env.set("FOO", null);
10594
}
10695

10796
run_next_test();

0 commit comments

Comments
 (0)
Failed to load comments.