summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests
diff options
context:
space:
mode:
Diffstat (limited to 'js/xpconnect/tests')
-rw-r--r--js/xpconnect/tests/browser/browser.toml3
-rw-r--r--js/xpconnect/tests/browser/browser_date_telemetry.js70
-rw-r--r--js/xpconnect/tests/browser/browser_dead_object.js11
-rw-r--r--js/xpconnect/tests/browser/browser_exception_leak.js11
-rw-r--r--js/xpconnect/tests/chrome/test_bug799348.xhtml4
-rw-r--r--js/xpconnect/tests/chrome/test_cows.xhtml2
-rw-r--r--js/xpconnect/tests/chrome/test_windowProxyDeadWrapper.html2
-rw-r--r--js/xpconnect/tests/chrome/test_xrayToJS.xhtml6
-rw-r--r--js/xpconnect/tests/components/native/moz.build1
-rw-r--r--js/xpconnect/tests/components/native/xpctest_module.cpp2
-rw-r--r--js/xpconnect/tests/components/native/xpctest_private.h11
-rw-r--r--js/xpconnect/tests/components/native/xpctest_returncode.cpp20
-rw-r--r--js/xpconnect/tests/idl/xpctest_esmreturncode.idl45
-rw-r--r--js/xpconnect/tests/idl/xpctest_utils.idl23
-rw-r--r--js/xpconnect/tests/unit/ReturnCodeChild.jsm51
-rw-r--r--js/xpconnect/tests/unit/es6module_devtoolsLoader.sys.mjs91
-rw-r--r--js/xpconnect/tests/unit/import_shared_in_worker.js10
-rw-r--r--js/xpconnect/tests/unit/lazy_shared_in_worker.js14
-rw-r--r--js/xpconnect/tests/unit/test_defineESModuleGetters_options.js18
-rw-r--r--js/xpconnect/tests/unit/test_defineESModuleGetters_options_worker.js1
-rw-r--r--js/xpconnect/tests/unit/test_import_devtools_loader.js28
-rw-r--r--js/xpconnect/tests/unit/test_import_global.js8
-rw-r--r--js/xpconnect/tests/unit/test_import_global_worker.js1
-rw-r--r--js/xpconnect/tests/unit/test_returncode.js4
-rw-r--r--js/xpconnect/tests/unit/xpcshell.toml1
25 files changed, 144 insertions, 294 deletions
diff --git a/js/xpconnect/tests/browser/browser.toml b/js/xpconnect/tests/browser/browser.toml
index c7c72c71e7..59b8e08657 100644
--- a/js/xpconnect/tests/browser/browser.toml
+++ b/js/xpconnect/tests/browser/browser.toml
@@ -9,8 +9,6 @@ support-files = [
"browser_promise_userInteractionHandling.html"
]
-["browser_date_telemetry.js"]
-
["browser_dead_object.js"]
["browser_exception_leak.js"]
@@ -28,4 +26,3 @@ support-files = [
["browser_weak_xpcwjs.js"]
["browser_weak_xpcwn.js"]
-
diff --git a/js/xpconnect/tests/browser/browser_date_telemetry.js b/js/xpconnect/tests/browser/browser_date_telemetry.js
deleted file mode 100644
index b9c653db53..0000000000
--- a/js/xpconnect/tests/browser/browser_date_telemetry.js
+++ /dev/null
@@ -1,70 +0,0 @@
-/* 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/.
- */
-
-const triggers = [
- "Sep 26 Tues 1995",
- "Sep 26 1995 Tues",
- "Sep 26 1995 Tues 09:30",
- "Sep 26 1995 09:Tues:30",
- "Sep 26 1995 09:30 Tues GMT",
- "Sep 26 1995 09:30 GMT Tues",
-
- "26 Tues Sep 1995",
- "26 Sep Tues 1995",
- "26 Sep 1995 Tues",
-
- "1995-09-26 Tues",
-
- // Multiple occurences should only trigger 1 counter
- "Sep 26 Tues 1995 Tues",
-];
-const nonTriggers = [
- "Sep 26 1995",
- "Tues Sep 26 1995",
- "Sep Tues 26 1995",
-
- // Invalid format shouldn't trigger the counter
- "Sep 26 Tues 1995 foo",
-];
-
-function getCount() {
- return Glean.useCounterPage.jsLateWeekday.testGetValue() ?? 0;
-}
-
-/**
- * Opens and closes a browser tab with minimal JS code which parses
- * the given Date format.
- */
-async function parseFormat(format, call = "new Date") {
- let newTab = await BrowserTestUtils.openNewForegroundTab(
- gBrowser,
- `data:text/html;charset=utf-8,<script>${call}("${format}")</script>`
- );
- BrowserTestUtils.removeTab(newTab);
-}
-
-add_task(async function test_date_telemetry() {
- let sum = getCount();
-
- // waitForCondition cannot be used to test if nothing has changed,
- // so these tests aren't as reliable as the ones in the next loop.
- // If you encounter an inexplicable failure in any of these tests,
- // debug by adding a delay to the end of the parseFormat function.
- for (const format of nonTriggers) {
- await parseFormat(format);
- const count = getCount();
- is(count, sum, `${format} should not trigger telemetry`);
- sum = count;
- }
-
- for (const [i, format] of triggers.entries()) {
- // Alternate between Date constructor and Date.parse
- await parseFormat(format, ["new Date", "Date.parse"][i % 2]);
- await BrowserTestUtils.waitForCondition(() => getCount() > sum);
- const count = getCount();
- is(count, sum + 1, `${format} should trigger telemetry`);
- sum = count;
- }
-});
diff --git a/js/xpconnect/tests/browser/browser_dead_object.js b/js/xpconnect/tests/browser/browser_dead_object.js
index b8b2dd0688..a79b46bc36 100644
--- a/js/xpconnect/tests/browser/browser_dead_object.js
+++ b/js/xpconnect/tests/browser/browser_dead_object.js
@@ -19,13 +19,10 @@ add_task(async function test() {
let { TestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
- let promise = TestUtils.topicObserved(
- "inner-window-nuked",
- (subject, data) => {
- let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
- return id == args.innerWindowId;
- }
- );
+ let promise = TestUtils.topicObserved("inner-window-nuked", subject => {
+ let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
+ return id == args.innerWindowId;
+ });
content.location = "http://mochi.test:8888/";
await promise;
return Cu.isDeadWrapper(doc);
diff --git a/js/xpconnect/tests/browser/browser_exception_leak.js b/js/xpconnect/tests/browser/browser_exception_leak.js
index be860355bc..80358758ec 100644
--- a/js/xpconnect/tests/browser/browser_exception_leak.js
+++ b/js/xpconnect/tests/browser/browser_exception_leak.js
@@ -40,13 +40,10 @@ add_task(async function test() {
// eslint-disable-next-line no-unused-vars
let doc = content.document;
- let promise = TestUtils.topicObserved(
- "inner-window-nuked",
- (subject, data) => {
- let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
- return id == args.innerWindowId;
- }
- );
+ let promise = TestUtils.topicObserved("inner-window-nuked", subject => {
+ let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
+ return id == args.innerWindowId;
+ });
content.location = "http://mochi.test:8888/";
await promise;
diff --git a/js/xpconnect/tests/chrome/test_bug799348.xhtml b/js/xpconnect/tests/chrome/test_bug799348.xhtml
index 91de48164f..99e36eaae9 100644
--- a/js/xpconnect/tests/chrome/test_bug799348.xhtml
+++ b/js/xpconnect/tests/chrome/test_bug799348.xhtml
@@ -22,10 +22,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=799348
var gCalledOnload = false;
var myObserver = {
QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
- observe(win, topic, data) {
+ observe(win, topic) {
if (topic == "domwindowopened") {
ok(!gCalledOnload, "domwindowopened notification fired before onload");
- win.addEventListener("load", function(evt) {
+ win.addEventListener("load", function() {
gCalledOnload = true;
win.close();
});
diff --git a/js/xpconnect/tests/chrome/test_cows.xhtml b/js/xpconnect/tests/chrome/test_cows.xhtml
index 69d7d3e9e6..c6e27a2c47 100644
--- a/js/xpconnect/tests/chrome/test_cows.xhtml
+++ b/js/xpconnect/tests/chrome/test_cows.xhtml
@@ -91,7 +91,7 @@ function COWTests() {
});
// Test function objects.
- var func = function(x) { return 42; };
+ var func = function() { return 42; };
func.foo = "foo property";
var funcCOW = getCOW(func);
try {
diff --git a/js/xpconnect/tests/chrome/test_windowProxyDeadWrapper.html b/js/xpconnect/tests/chrome/test_windowProxyDeadWrapper.html
index a6f0ac95be..234a38ebeb 100644
--- a/js/xpconnect/tests/chrome/test_windowProxyDeadWrapper.html
+++ b/js/xpconnect/tests/chrome/test_windowProxyDeadWrapper.html
@@ -51,7 +51,7 @@ async function go() {
// once the window is destroyed.
frame.remove();
- TestUtils.topicObserved("outer-window-nuked", (subject, data) => {
+ TestUtils.topicObserved("outer-window-nuked", (subject) => {
let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
return id == winID;
}).then(() => {
diff --git a/js/xpconnect/tests/chrome/test_xrayToJS.xhtml b/js/xpconnect/tests/chrome/test_xrayToJS.xhtml
index cc009a2d55..9943055aea 100644
--- a/js/xpconnect/tests/chrome/test_xrayToJS.xhtml
+++ b/js/xpconnect/tests/chrome/test_xrayToJS.xhtml
@@ -360,7 +360,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
return typedArrayClasses.includes(classname);
}
- function propertyIsGetter(obj, name, classname) {
+ function propertyIsGetter(obj, name) {
return !!Object.getOwnPropertyDescriptor(obj, name).get;
}
@@ -800,7 +800,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
checkThrows(function() { trickyObject.hasOwnProperty = 33; }, /shadow/,
"Should reject shadowing of pre-existing inherited properties over Xrays");
- checkThrows(function() { Object.defineProperty(trickyObject, 'rejectedProp', { get() {}}); },
+ checkThrows(function() { Object.defineProperty(trickyObject, 'rejectedProp', { get() { return undefined; }}); },
/accessor property/, "Should reject accessor property definition");
}
@@ -1058,7 +1058,7 @@ for (var prop of props) {
is(t.delete(null), true, "Key null can be deleted");
let values = [];
- t.forEach((value, key) => values.push(value));
+ t.forEach((value) => values.push(value));
is(values.toString(), "a,5", "forEach enumerates values correctly");
t.clear();
diff --git a/js/xpconnect/tests/components/native/moz.build b/js/xpconnect/tests/components/native/moz.build
index ba3d227c5b..662cfbcc85 100644
--- a/js/xpconnect/tests/components/native/moz.build
+++ b/js/xpconnect/tests/components/native/moz.build
@@ -14,7 +14,6 @@ UNIFIED_SOURCES += [
"xpctest_esmreturncode.cpp",
"xpctest_module.cpp",
"xpctest_params.cpp",
- "xpctest_returncode.cpp",
]
LOCAL_INCLUDES += [
diff --git a/js/xpconnect/tests/components/native/xpctest_module.cpp b/js/xpconnect/tests/components/native/xpctest_module.cpp
index 42b4259d5b..11200240b1 100644
--- a/js/xpconnect/tests/components/native/xpctest_module.cpp
+++ b/js/xpconnect/tests/components/native/xpctest_module.cpp
@@ -35,8 +35,6 @@ nsresult xpcTestRegisterComponents() {
"@mozilla.org/js/xpc/test/native/ObjectReadWrite;1"));
MOZ_TRY(RegisterFactory<nsXPCTestParams>(
"@mozilla.org/js/xpc/test/native/Params;1"));
- MOZ_TRY(RegisterFactory<nsXPCTestReturnCodeParent>(
- "@mozilla.org/js/xpc/test/native/ReturnCodeParent;1"));
MOZ_TRY(RegisterFactory<nsXPCTestESMReturnCodeParent>(
"@mozilla.org/js/xpc/test/native/ESMReturnCodeParent;1"));
MOZ_TRY(RegisterFactory<xpcTestCEnums>(
diff --git a/js/xpconnect/tests/components/native/xpctest_private.h b/js/xpconnect/tests/components/native/xpctest_private.h
index c5d7bc86cf..d2d12d4ef8 100644
--- a/js/xpconnect/tests/components/native/xpctest_private.h
+++ b/js/xpconnect/tests/components/native/xpctest_private.h
@@ -67,17 +67,6 @@ class nsXPCTestParams final : public nsIXPCTestParams {
~nsXPCTestParams() = default;
};
-class nsXPCTestReturnCodeParent final : public nsIXPCTestReturnCodeParent {
- public:
- NS_DECL_ISUPPORTS
- NS_DECL_NSIXPCTESTRETURNCODEPARENT
-
- nsXPCTestReturnCodeParent() = default;
-
- private:
- ~nsXPCTestReturnCodeParent() = default;
-};
-
class nsXPCTestESMReturnCodeParent final : public nsIXPCTestReturnCodeParent {
public:
NS_DECL_ISUPPORTS
diff --git a/js/xpconnect/tests/components/native/xpctest_returncode.cpp b/js/xpconnect/tests/components/native/xpctest_returncode.cpp
deleted file mode 100644
index 3a52f616d9..0000000000
--- a/js/xpconnect/tests/components/native/xpctest_returncode.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-/* 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/. */
-
-#include "xpctest_private.h"
-#include "nsComponentManagerUtils.h"
-#include "nsImportModule.h"
-
-NS_IMPL_ISUPPORTS(nsXPCTestReturnCodeParent, nsIXPCTestReturnCodeParent)
-
-NS_IMETHODIMP nsXPCTestReturnCodeParent::CallChild(int32_t childBehavior,
- nsresult* _retval) {
- nsresult rv;
- nsCOMPtr<nsIXPCTestReturnCodeChild> child(do_ImportModule(
- "resource://test/ReturnCodeChild.jsm", "ReturnCodeChild", &rv));
- NS_ENSURE_SUCCESS(rv, rv);
- rv = child->DoIt(childBehavior);
- *_retval = rv;
- return NS_OK;
-}
diff --git a/js/xpconnect/tests/idl/xpctest_esmreturncode.idl b/js/xpconnect/tests/idl/xpctest_esmreturncode.idl
deleted file mode 100644
index ac17feda3f..0000000000
--- a/js/xpconnect/tests/idl/xpctest_esmreturncode.idl
+++ /dev/null
@@ -1,45 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * 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/. */
-
-/**
- * Test the use of Components.returnCode with system ESM
- *
- * This ("parent") interface defines a method that in-turn calls another
- * ("child") interface implemented in JS, and returns the nsresult from that
- * child interface. The child interface manages the return code by way of
- * Components.returnCode.
- */
-
-#include "nsISupports.idl"
-
-
-[scriptable, uuid(494f9336-ad06-46ad-bbb4-b0010e27e12d)]
-interface nsIXPCTestESMReturnCodeParent : nsISupports {
- // Calls the "child" interface with the specified behavior flag. Returns
- // the NSRESULT from the child interface.
- nsresult callChild(in long childBehavior);
-};
-
-[scriptable, uuid(dee07408-75d8-4968-a37c-fe0d48ccd1ac)]
-interface nsIXPCTestESMReturnCodeChild : nsISupports {
- void doIt(in long behavior);
-
- // Flags to control that the child does.
- // child will throw a JS exception
- const long CHILD_SHOULD_THROW = 0;
-
- // child will just return normally
- const long CHILD_SHOULD_RETURN_SUCCESS = 1;
-
- // child will return after setting Components.returnCode to NS_ERROR_FAILURE
- const long CHILD_SHOULD_RETURN_RESULTCODE = 2;
-
- // child will set Components.returnCode to NS_ERROR_UNEXPECTED, then create
- // a new component that sets Components.returnCode to NS_ERROR_FAILURE.
- // Our caller should see the NS_ERROR_UNEXPECTED we set rather than the
- // value set later by the "inner" child.
- const long CHILD_SHOULD_NEST_RESULTCODES = 3;
-};
diff --git a/js/xpconnect/tests/idl/xpctest_utils.idl b/js/xpconnect/tests/idl/xpctest_utils.idl
index e59814272b..db135fcbe1 100644
--- a/js/xpconnect/tests/idl/xpctest_utils.idl
+++ b/js/xpconnect/tests/idl/xpctest_utils.idl
@@ -17,3 +17,26 @@ interface nsIXPCTestFunctionInterface : nsISupports {
interface nsIXPCTestUtils : nsISupports {
nsIXPCTestFunctionInterface doubleWrapFunction(in nsIXPCTestFunctionInterface f);
};
+
+/*
+ * Test that non-[scriptable] interfaces and [noscript] members are not
+ * generated for TypeScript bindings.
+ */
+
+[uuid(ddf64cfb-668a-4571-a900-0fe2babb6249)]
+interface nsIXPCTestNotScriptable : nsISupports {
+ // Empty.
+};
+
+[scriptable, uuid(1bbfe703-c67d-4995-b061-564c8a1c39d7)]
+interface nsIXPCTestNoScriptMembers : nsISupports {
+ [noscript]
+ attribute long noscriptProp;
+
+ attribute long exposedProp;
+
+ [noscript]
+ void noscriptMethod(in long arg);
+
+ void exposedMethod(in long arg);
+};
diff --git a/js/xpconnect/tests/unit/ReturnCodeChild.jsm b/js/xpconnect/tests/unit/ReturnCodeChild.jsm
deleted file mode 100644
index bf74453969..0000000000
--- a/js/xpconnect/tests/unit/ReturnCodeChild.jsm
+++ /dev/null
@@ -1,51 +0,0 @@
-/* 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/. */
-
-var EXPORTED_SYMBOLS = ["ReturnCodeChild"];
-
-function xpcWrap(obj, iface) {
- let ifacePointer = Cc[
- "@mozilla.org/supports-interface-pointer;1"
- ].createInstance(Ci.nsISupportsInterfacePointer);
-
- ifacePointer.data = obj;
- return ifacePointer.data.QueryInterface(iface);
-}
-
-var ReturnCodeChild = {
- QueryInterface: ChromeUtils.generateQI(["nsIXPCTestReturnCodeChild"]),
-
- doIt(behaviour) {
- switch (behaviour) {
- case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_THROW:
- throw(new Error("a requested error"));
- case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_SUCCESS:
- return;
- case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_RESULTCODE:
- Components.returnCode = Cr.NS_ERROR_FAILURE;
- return;
- case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_NEST_RESULTCODES:
- // Use xpconnect to create another instance of *this* component and
- // call that. This way we have crossed the xpconnect bridge twice.
-
- // We set *our* return code early - this should be what is returned
- // to our caller, even though our "inner" component will set it to
- // a different value that we will see (but our caller should not)
- Components.returnCode = Cr.NS_ERROR_UNEXPECTED;
- // call the child asking it to do the .returnCode set.
- let sub = xpcWrap(ReturnCodeChild, Ci.nsIXPCTestReturnCodeChild);
- let childResult = Cr.NS_OK;
- try {
- sub.doIt(Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_RESULTCODE);
- } catch (ex) {
- childResult = ex.result;
- }
- // write it to the console so the test can check it.
- let consoleService = Cc["@mozilla.org/consoleservice;1"]
- .getService(Ci.nsIConsoleService);
- consoleService.logStringMessage("nested child returned " + childResult);
- return;
- }
- }
-};
diff --git a/js/xpconnect/tests/unit/es6module_devtoolsLoader.sys.mjs b/js/xpconnect/tests/unit/es6module_devtoolsLoader.sys.mjs
index c7de54c82f..c8262f5f5c 100644
--- a/js/xpconnect/tests/unit/es6module_devtoolsLoader.sys.mjs
+++ b/js/xpconnect/tests/unit/es6module_devtoolsLoader.sys.mjs
@@ -7,23 +7,88 @@ export function increment() {
import { object } from "resource://test/es6module_devtoolsLoader.js";
export const importedObject = object;
-const importTrue = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { loadInDevToolsLoader : true });
-export const importESModuleTrue = importTrue.object;
+const importDevTools = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { global: "devtools" });
+export const importESModuleDevTools = importDevTools.object;
-const importFalse = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { loadInDevToolsLoader : false });
-export const importESModuleFalse = importFalse.object;
+const importShared = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { global: "shared" });
+export const importESModuleShared = importShared.object;
-const importNull = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", {});
-export const importESModuleNull = importNull.object;
+const importCurrent = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { global: "current" });
+export const importESModuleCurrent = importCurrent.object;
-const importNull2 = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js");
-export const importESModuleNull2 = importNull2.object;
+const importContextual = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", { global: "contextual" });
+export const importESModuleContextual = importContextual.object;
-const lazy = {};
-ChromeUtils.defineESModuleGetters(lazy, {
+let caught = false;
+try {
+ ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js");
+} catch (e) {
+ caught = true;
+}
+export const importESModuleNoOptionFailed1 = caught;
+
+caught = false;
+try {
+ ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader.js", {});
+} catch (e) {
+ caught = true;
+}
+export const importESModuleNoOptionFailed2 = caught;
+
+const lazyDevTools = {};
+ChromeUtils.defineESModuleGetters(lazyDevTools, {
+ object: "resource://test/es6module_devtoolsLoader.js",
+}, { global: "devtools" });
+
+export function importLazyDevTools() {
+ return lazyDevTools.object;
+}
+
+const lazyShared = {};
+ChromeUtils.defineESModuleGetters(lazyShared, {
+ object: "resource://test/es6module_devtoolsLoader.js",
+}, { global: "shared" });
+
+export function importLazyShared() {
+ return lazyShared.object;
+}
+
+const lazyCurrent = {};
+ChromeUtils.defineESModuleGetters(lazyCurrent, {
+ object: "resource://test/es6module_devtoolsLoader.js",
+}, { global: "current" });
+
+export function importLazyCurrent() {
+ return lazyCurrent.object;
+}
+
+const lazyContextual = {};
+ChromeUtils.defineESModuleGetters(lazyContextual, {
object: "resource://test/es6module_devtoolsLoader.js",
-});
+}, { global: "contextual" });
+
+export function importLazyContextual() {
+ return lazyContextual.object;
+}
+
+caught = false;
+try {
+ let lazy = {};
+ ChromeUtils.defineESModuleGetters({}, {
+ object: "resource://test/es6module_devtoolsLoader.js",
+ });
+} catch (e) {
+ caught = true;
+}
+export const importLazyNoOptionFailed1 = caught;
-export function importLazy() {
- return lazy.object;
+caught = false;
+try {
+ let lazy = {};
+ ChromeUtils.defineESModuleGetters({}, {
+ object: "resource://test/es6module_devtoolsLoader.js",
+ }, {});
+} catch (e) {
+ caught = true;
}
+export const importLazyNoOptionFailed2 = caught;
diff --git a/js/xpconnect/tests/unit/import_shared_in_worker.js b/js/xpconnect/tests/unit/import_shared_in_worker.js
index bc92fe26a6..170254fb21 100644
--- a/js/xpconnect/tests/unit/import_shared_in_worker.js
+++ b/js/xpconnect/tests/unit/import_shared_in_worker.js
@@ -24,13 +24,5 @@ onmessage = event => {
caught3 = true;
}
- let caught4 = false;
- try {
- ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
- loadInDevToolsLoader: true,
- });
- } catch (e) {
- caught4 = true;
- }
- postMessage({ caught1, caught2, caught3, caught4 });
+ postMessage({ caught1, caught2, caught3 });
};
diff --git a/js/xpconnect/tests/unit/lazy_shared_in_worker.js b/js/xpconnect/tests/unit/lazy_shared_in_worker.js
index 148cdefb3e..91114e61c4 100644
--- a/js/xpconnect/tests/unit/lazy_shared_in_worker.js
+++ b/js/xpconnect/tests/unit/lazy_shared_in_worker.js
@@ -36,17 +36,5 @@ onmessage = event => {
caught3 = true;
}
- let caught4 = false;
- try {
- const lazy = {};
- ChromeUtils.defineESModuleGetters(lazy, {
- obj: "resource://test/esmified-1.sys.mjs"
- }, {
- loadInDevToolsLoader: true,
- });
- lazy.obj;
- } catch (e) {
- caught4 = true;
- }
- postMessage({ caught1, caught2, caught3, caught4 });
+ postMessage({ caught1, caught2, caught3 });
};
diff --git a/js/xpconnect/tests/unit/test_defineESModuleGetters_options.js b/js/xpconnect/tests/unit/test_defineESModuleGetters_options.js
index 11d282e511..b01580dfa1 100644
--- a/js/xpconnect/tests/unit/test_defineESModuleGetters_options.js
+++ b/js/xpconnect/tests/unit/test_defineESModuleGetters_options.js
@@ -25,29 +25,21 @@ add_task(async function testShared() {
});
add_task(async function testDevTools() {
- const lazy1 = {};
- const lazy2 = {};
-
- ChromeUtils.defineESModuleGetters(lazy1, {
- GetX: "resource://test/esm_lazy-1.sys.mjs",
- }, {
- loadInDevToolsLoader: true,
- });
+ const lazy = {};
- ChromeUtils.defineESModuleGetters(lazy2, {
+ ChromeUtils.defineESModuleGetters(lazy, {
GetX: "resource://test/esm_lazy-1.sys.mjs",
}, {
global: "devtools",
});
- Assert.equal(lazy1.GetX, lazy2.GetX);
+ lazy.GetX; // delazify before import.
const ns = ChromeUtils.importESModule("resource://test/esm_lazy-1.sys.mjs", {
- loadInDevToolsLoader: true,
+ global: "devtools",
});
- Assert.equal(ns.GetX, lazy1.GetX);
- Assert.equal(ns.GetX, lazy2.GetX);
+ Assert.equal(ns.GetX, lazy.GetX);
});
add_task(async function testSandbox() {
diff --git a/js/xpconnect/tests/unit/test_defineESModuleGetters_options_worker.js b/js/xpconnect/tests/unit/test_defineESModuleGetters_options_worker.js
index f1eab22d2b..a21030ac6a 100644
--- a/js/xpconnect/tests/unit/test_defineESModuleGetters_options_worker.js
+++ b/js/xpconnect/tests/unit/test_defineESModuleGetters_options_worker.js
@@ -29,5 +29,4 @@ add_task(async function testSharedInWorker() {
Assert.equal(result.caught1, true);
Assert.equal(result.caught2, true);
Assert.equal(result.caught3, true);
- Assert.equal(result.caught4, true);
});
diff --git a/js/xpconnect/tests/unit/test_import_devtools_loader.js b/js/xpconnect/tests/unit/test_import_devtools_loader.js
index d7e6fe42f6..f3518ca301 100644
--- a/js/xpconnect/tests/unit/test_import_devtools_loader.js
+++ b/js/xpconnect/tests/unit/test_import_devtools_loader.js
@@ -39,19 +39,27 @@ add_task(async function testDevToolsModuleLoader() {
dbg.addDebuggee(nsGlobal);
Assert.ok(true, "The global is accepted by the Debugger API");
- const ns1 = ChromeUtils.importESModule(ESM_URL, { loadInDevToolsLoader : false });
- Assert.equal(ns1, ns, "Passing loadInDevToolsLoader=false from the shared JSM global is equivalent to regular importESModule");
+ const ns1 = ChromeUtils.importESModule(ESM_URL, { global: "shared" });
+ Assert.equal(ns1, ns, "Passing global: 'shared' from the shared JSM global is equivalent to regular importESModule");
info("Test importing in the devtools loader");
- const ns2 = ChromeUtils.importESModule(ESM_URL, { loadInDevToolsLoader: true });
+ const ns2 = ChromeUtils.importESModule(ESM_URL, { global: "devtools" });
Assert.equal(ns2.x, 0, "We get a new module instance with a new incremented number");
Assert.notEqual(ns2, ns, "We imported a new instance of the module");
Assert.notEqual(ns2.importedObject, ns.importedObject, "The two module instances expose distinct objects");
- Assert.equal(ns2.importESModuleTrue, ns2.importedObject, "When using loadInDevToolsLoader:true from a devtools global, we keep loading in the same loader");
- Assert.equal(ns2.importESModuleNull, ns2.importedObject, "When having an undefined loadInDevToolsLoader from a devtools global, we keep loading in the same loader");
- Assert.equal(ns2.importESModuleNull2, ns2.importedObject, "When having no optional argument at all, we keep loading in the same loader");
- Assert.equal(ns2.importESModuleFalse, ns.importedObject, "When passing an explicit loadInDevToolsLoader:false, we load in the shared global, even from a devtools global");
- Assert.equal(ns2.importLazy(), ns2.importedObject, "ChromeUtils.defineESModuleGetters imports will follow the contextual loader");
+ Assert.equal(ns2.importESModuleDevTools, ns2.importedObject, "When using global: 'devtools' from a devtools global, we keep loading in the same loader");
+ Assert.equal(ns2.importESModuleCurrent, ns2.importedObject, "When using global: 'current' from a devtools global, we keep loading in the same loader");
+ Assert.equal(ns2.importESModuleContextual, ns2.importedObject, "When using global: 'contextual' from a devtools global, we keep loading in the same loader");
+ Assert.ok(ns2.importESModuleNoOptionFailed1, "global option is required in DevTools global");
+ Assert.ok(ns2.importESModuleNoOptionFailed2, "global option is required in DevTools global");
+ Assert.equal(ns2.importESModuleShared, ns.importedObject, "When passing global: 'shared', we load in the shared global, even from a devtools global");
+
+ Assert.equal(ns2.importLazyDevTools(), ns2.importedObject, "When using global: 'devtools' from a devtools global, we keep loading in the same loader");
+ Assert.equal(ns2.importLazyCurrent(), ns2.importedObject, "When using global: 'current' from a devtools global, we keep loading in the same loader");
+ Assert.equal(ns2.importLazyContextual(), ns2.importedObject, "When using global: 'contextual' from a devtools global, we keep loading in the same loader");
+ Assert.ok(ns2.importLazyNoOptionFailed1, "global option is required in DevTools global");
+ Assert.ok(ns2.importLazyNoOptionFailed2, "global option is required in DevTools global");
+ Assert.equal(ns2.importLazyShared(), ns.importedObject, "When passing global: 'shared', we load in the shared global, even from a devtools global");
info("When using the devtools loader, we load in a distinct global, but the same compartment");
const ns2Global = Cu.getGlobalForObject(ns2);
@@ -63,12 +71,12 @@ add_task(async function testDevToolsModuleLoader() {
"Global os ESM loaded in the devtools loader can't be inspected by the Debugee");
info("Re-import the same module in the devtools loader");
- const ns3 = ChromeUtils.importESModule(ESM_URL, { loadInDevToolsLoader: true });
+ const ns3 = ChromeUtils.importESModule(ESM_URL, { global: "devtools" });
Assert.equal(ns3, ns2, "We import the exact same module");
Assert.equal(ns3.importedObject, ns2.importedObject, "The two module expose the same objects");
info("Import a module only from the devtools loader");
- const ns4 = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader_only.js", { loadInDevToolsLoader: true });
+ const ns4 = ChromeUtils.importESModule("resource://test/es6module_devtoolsLoader_only.js", { global: "devtools" });
const ns4Global = Cu.getGlobalForObject(ns4);
Assert.equal(ns4Global, ns2Global, "The module is loaded in the same devtools global");
diff --git a/js/xpconnect/tests/unit/test_import_global.js b/js/xpconnect/tests/unit/test_import_global.js
index 9ad4522854..97dbaac90d 100644
--- a/js/xpconnect/tests/unit/test_import_global.js
+++ b/js/xpconnect/tests/unit/test_import_global.js
@@ -14,16 +14,14 @@ add_task(async function testShared() {
});
add_task(async function testDevTools() {
- const ns1 = ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
- loadInDevToolsLoader: true,
- });
+ const ns1 = ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs");
const ns2 = ChromeUtils.importESModule("resource://test/esmified-1.sys.mjs", {
global: "devtools",
});
- Assert.equal(ns1, ns2);
- Assert.equal(ns1.obj, ns2.obj);
+ Assert.notEqual(ns1, ns2);
+ Assert.notEqual(ns1.obj, ns2.obj);
});
add_task(async function testInvalidOptions() {
diff --git a/js/xpconnect/tests/unit/test_import_global_worker.js b/js/xpconnect/tests/unit/test_import_global_worker.js
index 16359a4da4..9000358b67 100644
--- a/js/xpconnect/tests/unit/test_import_global_worker.js
+++ b/js/xpconnect/tests/unit/test_import_global_worker.js
@@ -17,5 +17,4 @@ add_task(async function testSharedInWorker() {
Assert.equal(result.caught1, true);
Assert.equal(result.caught2, true);
Assert.equal(result.caught3, true);
- Assert.equal(result.caught4, true);
});
diff --git a/js/xpconnect/tests/unit/test_returncode.js b/js/xpconnect/tests/unit/test_returncode.js
index de4289c013..31997eb4ad 100644
--- a/js/xpconnect/tests/unit/test_returncode.js
+++ b/js/xpconnect/tests/unit/test_returncode.js
@@ -14,10 +14,6 @@ function run_test() {
// Load the component manifests.
registerXPCTestComponents();
- // and the tests.
- test_simple("@mozilla.org/js/xpc/test/native/ReturnCodeParent;1");
- test_nested("@mozilla.org/js/xpc/test/native/ReturnCodeParent;1");
-
test_simple("@mozilla.org/js/xpc/test/native/ESMReturnCodeParent;1");
test_nested("@mozilla.org/js/xpc/test/native/ESMReturnCodeParent;1");
}
diff --git a/js/xpconnect/tests/unit/xpcshell.toml b/js/xpconnect/tests/unit/xpcshell.toml
index 97b2dbe559..37274eba96 100644
--- a/js/xpconnect/tests/unit/xpcshell.toml
+++ b/js/xpconnect/tests/unit/xpcshell.toml
@@ -15,7 +15,6 @@ support-files = [
"importer.jsm",
"recursive_importA.jsm",
"recursive_importB.jsm",
- "ReturnCodeChild.jsm",
"ReturnCodeChild.sys.mjs",
"syntax_error.jsm",
"uninitialized_lexical.jsm",