Skip to content

Commit 5eb2171

Browse files
committed
Bug 1863204 - Correct ESLint scope for some privileged globals and remove importGlobalProperties from more places. r=Gijs,sessionstore-reviewers,dom-storage-reviewers,sclements,asuth
Differential Revision: https://phabricator.services.mozilla.com/D192806
1 parent 179d2c8 commit 5eb2171

File tree

31 files changed

+9
-56
lines changed

31 files changed

+9
-56
lines changed

browser/components/newtab/test/xpcshell/head.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
1212
JsonSchema: "resource://gre/modules/JsonSchema.sys.mjs",
1313
});
1414

15-
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
16-
1715
function assertValidates(validator, obj, msg) {
1816
const result = validator.validate(obj);
1917
Assert.ok(

browser/components/sessionstore/test/unit/test_final_write_cleanup.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ const {
2222
const MAX_ENTRIES = 9;
2323
const URL = "http://example.com/#";
2424

25-
Cu.importGlobalProperties(["structuredClone"]);
26-
2725
async function prepareWithLimit(back, fwd) {
2826
SessionWriter.init("empty", false, Paths, {
2927
maxSerializeBack: back,

dom/cache/test/xpcshell/head.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ add_setup(function () {
4747

4848
enableTesting();
4949

50-
// Expose Cache and Fetch symbols on the global
51-
Cu.importGlobalProperties(["caches", "fetch"]);
50+
Cu.importGlobalProperties(["caches"]);
5251

5352
registerCleanupFunction(resetTesting);
5453
});

dom/indexedDB/test/test_message_manager_ipc.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
const blobText = blobData.join("");
2727
const blobType = "text/plain";
2828

29-
Cu.importGlobalProperties(["indexedDB"]);
30-
3129
function info(msg) {
3230
sendAsyncMessage(mmName, { op: "info", msg });
3331
}

dom/indexedDB/test/unit/GlobalObjectsChild.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ function finishTest() {
1919
function run_test() {
2020
const name = "Splendid Test";
2121

22-
Cu.importGlobalProperties(["indexedDB"]);
23-
2422
do_test_pending();
2523

2624
let keyRange = IDBKeyRange.only(42);

dom/indexedDB/test/unit/test_sandbox.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ function run_test() {
7777
sb
7878
);
7979

80-
Cu.importGlobalProperties(["indexedDB"]);
8180
do_test_pending();
8281
Promise.all([innerPromise, exerciseInterface()]).then(do_test_finished);
8382
}

dom/indexedDB/test/unit/xpcshell-head-parent-process.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ if (!this.runTest) {
4646
enableExperimental();
4747
}
4848

49-
Cu.importGlobalProperties(["indexedDB"]);
50-
5149
// In order to support converting tests to using async functions from using
5250
// generator functions, we detect async functions by checking the name of
5351
// function's constructor.

dom/localstorage/test/unit/head.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ add_setup(function () {
2121

2222
enableTesting();
2323

24-
Cu.importGlobalProperties(["crypto"]);
25-
2624
registerCleanupFunction(resetTesting);
2725
});
2826

dom/push/test/xpcshell/test_crypto_encrypt.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Test PushCrypto.encrypt()
22
"use strict";
33

4-
Cu.importGlobalProperties(["crypto"]);
5-
64
const { PushCrypto } = ChromeUtils.importESModule(
75
"resource://gre/modules/PushCrypto.sys.mjs"
86
);

dom/push/test/xpcshell/test_service_child.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
"use strict";
55

6-
Cu.importGlobalProperties(["crypto"]);
7-
86
var db;
97

108
function done() {

dom/streams/test/xpcshell/fetch.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ AddonTestUtils.createAppInfo(
1212
"42"
1313
);
1414

15-
Cu.importGlobalProperties(["fetch"]);
1615
add_task(async function helper() {
1716
do_get_profile();
1817

dom/tests/unit/test_Fetch.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* Any copyright is dedicated to the Public Domain.
22
http://creativecommons.org/publicdomain/zero/1.0/ */
33

4-
Cu.importGlobalProperties(["fetch"]);
54
const { HttpServer } = ChromeUtils.importESModule(
65
"resource://testing-common/httpd.sys.mjs"
76
);

js/xpconnect/tests/unit/test_structuredClone.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ function run_test() {
2727
sb
2828
);
2929

30-
Cu.importGlobalProperties(["structuredClone"]);
3130
const clone = structuredClone({ b: 2 });
3231
Assert.equal(clone.b, 2);
3332
}

netwerk/test/unit/test_dooh.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
/* import-globals-from trr_common.js */
77

8-
Cu.importGlobalProperties(["fetch"]);
9-
108
const { setTimeout } = ChromeUtils.importESModule(
119
"resource://gre/modules/Timer.sys.mjs"
1210
);

services/crypto/tests/unit/test_jwcrypto.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ ChromeUtils.defineESModuleGetters(this, {
77
jwcrypto: "resource://services-crypto/jwcrypto.sys.mjs",
88
});
99

10-
Cu.importGlobalProperties(["crypto"]);
11-
1210
// Enable logging from jwcrypto.jsm.
1311
Services.prefs.setCharPref("services.crypto.jwcrypto.log.level", "Debug");
1412

services/fxaccounts/tests/xpcshell/test_pairing.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const { EventEmitter } = ChromeUtils.importESModule(
1212
ChromeUtils.defineESModuleGetters(this, {
1313
jwcrypto: "resource://services-crypto/jwcrypto.sys.mjs",
1414
});
15-
XPCOMUtils.defineLazyGlobalGetters(this, ["crypto"]);
1615

1716
const CHANNEL_ID = "sW-UA97Q6Dljqen7XRlYPw";
1817
const CHANNEL_KEY = crypto.getRandomValues(new Uint8Array(32));

services/settings/test/unit/test_remote_settings_dump_lastmodified.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const { Utils } = ChromeUtils.importESModule(
44
"resource://services-settings/Utils.sys.mjs"
55
);
66

7-
Cu.importGlobalProperties(["fetch"]);
8-
97
async function getLocalDumpLastModified(bucket, collection) {
108
let res;
119
try {

services/settings/test/unit/test_remote_settings_worker.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ const { Database } = ChromeUtils.importESModule(
1717
"resource://services-settings/Database.sys.mjs"
1818
);
1919

20-
XPCOMUtils.defineLazyGlobalGetters(this, ["indexedDB"]);
21-
2220
const IS_ANDROID = AppConstants.platform == "android";
2321

2422
add_task(async function test_canonicaljson() {

toolkit/components/nimbus/test/unit/test_ExperimentAPI_NimbusFeatures.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const { JsonSchema } = ChromeUtils.importESModule(
77
"resource://gre/modules/JsonSchema.sys.mjs"
88
);
99

10-
Cu.importGlobalProperties(["fetch"]);
11-
1210
ChromeUtils.defineLazyGetter(this, "fetchSchema", () => {
1311
return fetch("resource://nimbus/schemas/NimbusEnrollment.schema.json", {
1412
credentials: "omit",

toolkit/components/normandy/test/unit/test_NormandyApi.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ load("utils.js");
1111
NormandyTestUtils.init({ add_task });
1212
const { decorate_task } = NormandyTestUtils;
1313

14-
Cu.importGlobalProperties(["fetch"]);
15-
1614
decorate_task(withMockApiServer(), async function test_get({ serverUrl }) {
1715
// Test that NormandyApi can fetch from the test server.
1816
const response = await NormandyApi.get(`${serverUrl}/api/v1/`);

toolkit/components/search/tests/xpcshell/searchconfigs/head_searchconfig.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ ChromeUtils.defineESModuleGetters(this, {
2121
updateAppInfo: "resource://testing-common/AppInfo.sys.mjs",
2222
});
2323

24-
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
25-
2624
const GLOBAL_SCOPE = this;
2725
const TEST_DEBUG = Services.env.get("TEST_DEBUG");
2826

toolkit/components/search/tests/xpcshell/test_remove_engine_notification_box.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
"use strict";
55

6-
Cu.importGlobalProperties(["structuredClone"]);
7-
86
const CONFIG = [
97
{
108
// Engine initially default, but the defaults will be changed to engine-pref.

toolkit/components/search/tests/xpcshell/test_validate_manifests.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
"use strict";
55

6-
Cu.importGlobalProperties(["fetch"]);
7-
86
const { ExtensionData } = ChromeUtils.importESModule(
97
"resource://gre/modules/Extension.sys.mjs"
108
);

toolkit/components/shopping/test/xpcshell/head.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ http://creativecommons.org/publicdomain/zero/1.0/ */
44
"use strict";
55
/* exported createHttpServer, loadJSONfromFile, readFile */
66

7-
Cu.importGlobalProperties(["fetch"]);
8-
97
const { AddonTestUtils } = ChromeUtils.importESModule(
108
"resource://testing-common/AddonTestUtils.sys.mjs"
119
);

toolkit/components/telemetry/tests/unit/test_TelemetryController.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,6 @@ add_task(async function test_encryptedPing() {
804804
// The underlying jwcrypto module being used here is not currently available on Android.
805805
return;
806806
}
807-
Cu.importGlobalProperties(["crypto"]);
808807

809808
const ECDH_PARAMS = {
810809
name: "ECDH",
@@ -1050,7 +1049,6 @@ add_task(async function test_encryptedPing_overrideId() {
10501049
// The underlying jwcrypto module being used here is not currently available on Android.
10511050
return;
10521051
}
1053-
Cu.importGlobalProperties(["crypto"]);
10541052

10551053
const publicKey = {
10561054
crv: "P-256",

toolkit/mozapps/extensions/test/xpcshell/head_addons.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,6 @@ function copyBlocklistToProfile(blocklistFile) {
11471147
}
11481148

11491149
async function mockGfxBlocklistItemsFromDisk(path) {
1150-
Cu.importGlobalProperties(["fetch"]);
11511150
let response = await fetch(Services.io.newFileURI(do_get_file(path)).spec);
11521151
let json = await response.json();
11531152
return mockGfxBlocklistItems(json);

toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/head.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ async function load_mlbf_record_as_blob() {
3838
const url = Services.io.newFileURI(
3939
do_get_file("../data/mlbf-blocked1-unblocked2.bin")
4040
).spec;
41-
Cu.importGlobalProperties(["fetch"]);
4241
return (await fetch(url)).blob();
4342
}
4443

toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_mlbf_dump.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const nonBlockedAddon = {
3232
};
3333

3434
async function sha256(arrayBuffer) {
35-
Cu.importGlobalProperties(["crypto"]);
3635
let hash = await crypto.subtle.digest("SHA-256", arrayBuffer);
3736
const toHex = b => b.toString(16).padStart(2, "0");
3837
return Array.from(new Uint8Array(hash), toHex).join("");

tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,5 @@ module.exports = {
2121
// JS can run. It's definitely available in JSMs. So even if this is not
2222
// the perfect place to add it, it's not wrong, and we can move it later.
2323
WebAssembly: false,
24-
// These are hard-coded and available in .jsm scopes.
25-
// See BackstagePass::Resolve.
26-
fetch: false,
27-
crypto: false,
28-
indexedDB: false,
29-
structuredClone: false,
3024
},
3125
};

tools/lint/eslint/eslint-plugin-mozilla/lib/environments/privileged.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,5 +810,11 @@ module.exports = {
810810
XULScrollElement: false,
811811
XULTextElement: false,
812812
console: false,
813+
// These are hard-coded and available in privileged scopes.
814+
// See BackstagePass::Resolve.
815+
fetch: false,
816+
crypto: false,
817+
indexedDB: false,
818+
structuredClone: false,
813819
},
814820
};

tools/lint/eslint/eslint-plugin-mozilla/tests/reject-importGlobalProperties.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ ruleTester.run("reject-importGlobalProperties", rule, {
2323
},
2424
{
2525
options: ["allownonwebidl"],
26-
code: "Cu.importGlobalProperties(['fetch'])",
26+
code: "Cu.importGlobalProperties(['caches'])",
2727
},
2828
{
2929
options: ["allownonwebidl"],
30-
code: "XPCOMUtils.defineLazyGlobalGetters(this, ['fetch'])",
30+
code: "XPCOMUtils.defineLazyGlobalGetters(this, ['caches'])",
3131
},
3232
],
3333
invalid: [

0 commit comments

Comments
 (0)