1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/* 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/. */
add_task(async function testShared() {
const ns1 = ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs");
const ns2 = ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
global: "shared",
});
Assert.equal(ns1, ns2);
Assert.equal(ns1.obj, ns2.obj);
});
add_task(async function testDevTools() {
const ns1 = ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
loadInDevToolsLoader: true,
});
const ns2 = ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
global: "devtools",
});
Assert.equal(ns1, ns2);
Assert.equal(ns1.obj, ns2.obj);
});
add_task(async function testInvalidOptions() {
// Unknown value is rejected.
Assert.throws(() => {
ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
global: "invalid",
});
}, Error);
Assert.throws(() => {
ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
global: globalThis,
});
}, Error);
// Unknown name is ignored.
ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
global2: "shared",
});
});
|