summaryrefslogtreecommitdiffstats
path: root/js/xpconnect
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
commit086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch)
treea4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /js/xpconnect
parentAdding debian version 124.0.1-1. (diff)
downloadfirefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz
firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/xpconnect')
-rw-r--r--js/xpconnect/idl/xpccomponents.idl9
-rw-r--r--js/xpconnect/loader/ChromeScriptLoader.cpp9
-rw-r--r--js/xpconnect/loader/mozJSModuleLoader.cpp50
-rw-r--r--js/xpconnect/loader/mozJSModuleLoader.h9
-rw-r--r--js/xpconnect/loader/nsImportModule.cpp35
-rw-r--r--js/xpconnect/loader/nsImportModule.h112
-rw-r--r--js/xpconnect/src/Sandbox.cpp8
-rw-r--r--js/xpconnect/src/XPCComponents.cpp2
-rw-r--r--js/xpconnect/src/XPCConvert.cpp46
-rw-r--r--js/xpconnect/src/XPCJSContext.cpp5
-rw-r--r--js/xpconnect/src/XPCJSRuntime.cpp35
-rw-r--r--js/xpconnect/src/XPCShellImpl.cpp11
-rw-r--r--js/xpconnect/src/xpcprivate.h3
-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
38 files changed, 234 insertions, 538 deletions
diff --git a/js/xpconnect/idl/xpccomponents.idl b/js/xpconnect/idl/xpccomponents.idl
index 0235228663..1d4155ed74 100644
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -324,6 +324,9 @@ interface nsIXPCComponents_Utils : nsISupports
* pointing to the same file will not cause the module to be re-evaluated,
* but the symbols in EXPORTED_SYMBOLS will be exported into the
* specified target object and the global object returned as above.
+ *
+ * TODO: Remove this once m-c, c-c, and out-of-tree code migrations finish
+ * (bug 1776175, bug 1881888).
*/
[implicit_jscontext,optional_argc]
jsval import(in AUTF8String aResourceURI, [optional] in jsval targetObj);
@@ -344,6 +347,9 @@ interface nsIXPCComponents_Utils : nsISupports
/**
* Returns true if the JSM is loaded into the system global previously via
* the import method above. Returns false otherwise.
+ *
+ * TODO: Remove this once m-c, c-c, and out-of-tree code migrations finish
+ * (bug 1776175, bug 1881888).
*/
boolean isJSModuleLoaded(in AUTF8String aResourceURI);
@@ -360,6 +366,9 @@ interface nsIXPCComponents_Utils : nsISupports
* imported then this method will do nothing.
*
* @param resourceURI A resource:// URI string to unload the module from.
+ *
+ * TODO: Remove this once m-c, c-c, and out-of-tree code migrations finish
+ * (bug 1776175, bug 1881888).
*/
void unload(in AUTF8String registryLocation);
diff --git a/js/xpconnect/loader/ChromeScriptLoader.cpp b/js/xpconnect/loader/ChromeScriptLoader.cpp
index 5c7115c997..d67c41d014 100644
--- a/js/xpconnect/loader/ChromeScriptLoader.cpp
+++ b/js/xpconnect/loader/ChromeScriptLoader.cpp
@@ -17,8 +17,8 @@
#include "js/CompileOptions.h" // JS::CompileOptions, JS::OwningCompileOptions
#include "js/CompilationAndEvaluation.h"
#include "js/experimental/CompileScript.h" // JS::CompileGlobalScriptToStencil, JS::NewFrontendContext, JS::DestroyFrontendContext, JS::SetNativeStackQuota, JS::ThreadStackQuotaForSize, JS::HadFrontendErrors, JS::ConvertFrontendErrorsToRuntimeErrors
-#include "js/experimental/JSStencil.h" // JS::Stencil, JS::CompileGlobalScriptToStencil, JS::InstantiateGlobalStencil, JS::CompilationStorage
-#include "js/SourceText.h" // JS::SourceText
+#include "js/experimental/JSStencil.h" // JS::Stencil, JS::CompileGlobalScriptToStencil, JS::InstantiateGlobalStencil
+#include "js/SourceText.h" // JS::SourceText
#include "js/Utility.h"
#include "mozilla/AlreadyAddRefed.h" // already_AddRefed
@@ -119,9 +119,8 @@ class AsyncScriptCompileTask final : public Task {
JS::SetNativeStackQuota(mFrontendContext,
JS::ThreadStackQuotaForSize(stackSize));
- JS::CompilationStorage compileStorage;
- mStencil = JS::CompileGlobalScriptToStencil(mFrontendContext, mOptions,
- mSrcBuf, compileStorage);
+ mStencil =
+ JS::CompileGlobalScriptToStencil(mFrontendContext, mOptions, mSrcBuf);
}
// Cancel the task.
diff --git a/js/xpconnect/loader/mozJSModuleLoader.cpp b/js/xpconnect/loader/mozJSModuleLoader.cpp
index f20306f0a0..017ac32b3b 100644
--- a/js/xpconnect/loader/mozJSModuleLoader.cpp
+++ b/js/xpconnect/loader/mozJSModuleLoader.cpp
@@ -454,6 +454,12 @@ void mozJSModuleLoader::InitStatics() {
MOZ_ASSERT(!sSelf);
sSelf = new mozJSModuleLoader();
RegisterWeakMemoryReporter(sSelf);
+
+ dom::AutoJSAPI jsapi;
+ jsapi.Init();
+ JSContext* cx = jsapi.cx();
+ sSelf->InitSharedGlobal(cx);
+
NonSharedGlobalSyncModuleLoaderScope::InitStatics();
}
@@ -486,12 +492,16 @@ void mozJSModuleLoader::ShutdownLoaders() {
}
}
-mozJSModuleLoader* mozJSModuleLoader::GetOrCreateDevToolsLoader() {
+mozJSModuleLoader* mozJSModuleLoader::GetOrCreateDevToolsLoader(
+ JSContext* aCx) {
if (sDevToolsLoader) {
return sDevToolsLoader;
}
sDevToolsLoader = new mozJSModuleLoader();
RegisterWeakMemoryReporter(sDevToolsLoader);
+
+ sDevToolsLoader->InitSharedGlobal(aCx);
+
return sDevToolsLoader;
}
@@ -682,26 +692,22 @@ void mozJSModuleLoader::CreateLoaderGlobal(JSContext* aCx,
aGlobal.set(global);
}
-JSObject* mozJSModuleLoader::GetSharedGlobal(JSContext* aCx) {
- if (!mLoaderGlobal) {
- JS::RootedObject globalObj(aCx);
+void mozJSModuleLoader::InitSharedGlobal(JSContext* aCx) {
+ JS::RootedObject globalObj(aCx);
- CreateLoaderGlobal(
- aCx, IsDevToolsLoader() ? "DevTools global"_ns : "shared JSM global"_ns,
- &globalObj);
+ CreateLoaderGlobal(
+ aCx, IsDevToolsLoader() ? "DevTools global"_ns : "shared JSM global"_ns,
+ &globalObj);
- // If we fail to create a module global this early, we're not going to
- // get very far, so just bail out now.
- MOZ_RELEASE_ASSERT(globalObj);
- mLoaderGlobal = globalObj;
-
- // AutoEntryScript required to invoke debugger hook, which is a
- // Gecko-specific concept at present.
- dom::AutoEntryScript aes(globalObj, "module loader report global");
- JS_FireOnNewGlobalObject(aes.cx(), globalObj);
- }
+ // If we fail to create a module global this early, we're not going to
+ // get very far, so just bail out now.
+ MOZ_RELEASE_ASSERT(globalObj);
+ mLoaderGlobal = globalObj;
- return mLoaderGlobal;
+ // AutoEntryScript required to invoke debugger hook, which is a
+ // Gecko-specific concept at present.
+ dom::AutoEntryScript aes(globalObj, "module loader report global");
+ JS_FireOnNewGlobalObject(aes.cx(), globalObj);
}
// Read script file on the main thread and pass it back to worker.
@@ -970,8 +976,8 @@ JSObject* mozJSModuleLoader::PrepareObjectForLocation(JSContext* aCx,
nsIFile* aModuleFile,
nsIURI* aURI,
bool aRealFile) {
- RootedObject globalObj(aCx, GetSharedGlobal(aCx));
- NS_ENSURE_TRUE(globalObj, nullptr);
+ RootedObject globalObj(aCx, GetSharedGlobal());
+ MOZ_ASSERT(globalObj);
JSAutoRealm ar(aCx, globalObj);
// |thisObj| is the object we set properties on for a particular .jsm.
@@ -2018,8 +2024,8 @@ nsresult mozJSModuleLoader::ImportESModule(
MarkerInnerWindowIdFromJSContext(aCx)),
Substring(aLocation, 0, std::min(size_t(128), aLocation.Length())));
- RootedObject globalObj(aCx, GetSharedGlobal(aCx));
- NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE);
+ RootedObject globalObj(aCx, GetSharedGlobal());
+ MOZ_ASSERT(globalObj);
MOZ_ASSERT_IF(NS_IsMainThread(),
xpc::Scriptability::Get(globalObj).Allowed());
diff --git a/js/xpconnect/loader/mozJSModuleLoader.h b/js/xpconnect/loader/mozJSModuleLoader.h
index 0b8e5f85d9..ac118c507d 100644
--- a/js/xpconnect/loader/mozJSModuleLoader.h
+++ b/js/xpconnect/loader/mozJSModuleLoader.h
@@ -76,9 +76,14 @@ class mozJSModuleLoader final : public nsIMemoryReporter {
return sSelf;
}
- JSObject* GetSharedGlobal(JSContext* aCx);
+ JSObject* GetSharedGlobal() {
+ MOZ_ASSERT(mLoaderGlobal);
+ return mLoaderGlobal;
+ }
private:
+ void InitSharedGlobal(JSContext* aCx);
+
void InitSyncModuleLoaderForGlobal(nsIGlobalObject* aGlobal);
void DisconnectSyncModuleLoaderFromGlobal();
@@ -86,7 +91,7 @@ class mozJSModuleLoader final : public nsIMemoryReporter {
public:
static mozJSModuleLoader* GetDevToolsLoader() { return sDevToolsLoader; }
- static mozJSModuleLoader* GetOrCreateDevToolsLoader();
+ static mozJSModuleLoader* GetOrCreateDevToolsLoader(JSContext* aCx);
nsresult ImportInto(const nsACString& aResourceURI,
JS::HandleValue aTargetObj, JSContext* aCx, uint8_t aArgc,
diff --git a/js/xpconnect/loader/nsImportModule.cpp b/js/xpconnect/loader/nsImportModule.cpp
index a313c44388..3720a444a6 100644
--- a/js/xpconnect/loader/nsImportModule.cpp
+++ b/js/xpconnect/loader/nsImportModule.cpp
@@ -39,44 +39,11 @@ static void AnnotateCrashReportWithJSException(JSContext* aCx,
aURI, file.get(), line, column,
NS_ConvertUTF16toUTF8(msg).get());
- CrashReporter::AnnotateCrashReport(
+ CrashReporter::RecordAnnotationNSCString(
CrashReporter::Annotation::JSModuleLoadError, errorString);
}
}
-nsresult ImportModule(const char* aURI, const char* aExportName,
- const nsIID& aIID, void** aResult, bool aInfallible) {
- AutoJSAPI jsapi;
- MOZ_ALWAYS_TRUE(jsapi.Init(xpc::PrivilegedJunkScope()));
- JSContext* cx = jsapi.cx();
-
- JS::RootedObject global(cx);
- JS::RootedObject exports(cx);
- nsresult rv = mozJSModuleLoader::Get()->Import(cx, nsDependentCString(aURI),
- &global, &exports);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- if (aInfallible) {
- AnnotateCrashReportWithJSException(cx, aURI);
-
- MOZ_CRASH_UNSAFE_PRINTF("Failed to load critical module \"%s\"", aURI);
- }
- return rv;
- }
-
- if (aExportName) {
- JS::RootedValue namedExport(cx);
- if (!JS_GetProperty(cx, exports, aExportName, &namedExport)) {
- return NS_ERROR_FAILURE;
- }
- if (!namedExport.isObject()) {
- return NS_ERROR_XPC_BAD_CONVERT_JS;
- }
- exports.set(&namedExport.toObject());
- }
-
- return nsXPConnect::XPConnect()->WrapJS(cx, exports, aIID, aResult);
-}
-
nsresult ImportESModule(const char* aURI, const char* aExportName,
const nsIID& aIID, void** aResult, bool aInfallible) {
AutoJSAPI jsapi;
diff --git a/js/xpconnect/loader/nsImportModule.h b/js/xpconnect/loader/nsImportModule.h
index 31f6f8c7c1..16a5c40a88 100644
--- a/js/xpconnect/loader/nsImportModule.h
+++ b/js/xpconnect/loader/nsImportModule.h
@@ -16,124 +16,12 @@
namespace mozilla {
namespace loader {
-nsresult ImportModule(const char* aURI, const char* aExportName,
- const nsIID& aIID, void** aResult, bool aInfallible);
-
nsresult ImportESModule(const char* aURI, const char* aExportName,
const nsIID& aIID, void** aResult, bool aInfallible);
} // namespace loader
} // namespace mozilla
-class MOZ_STACK_CLASS nsImportModule final : public nsCOMPtr_helper {
- public:
- nsImportModule(const char* aURI, const char* aExportName, nsresult* aErrorPtr,
- bool aInfallible)
- : mURI(aURI),
- mExportName(aExportName),
- mErrorPtr(aErrorPtr),
- mInfallible(aInfallible) {
- MOZ_ASSERT_IF(mErrorPtr, !mInfallible);
- }
-
- virtual nsresult NS_FASTCALL operator()(const nsIID& aIID,
- void** aResult) const override {
- nsresult rv = ::mozilla::loader::ImportModule(mURI, mExportName, aIID,
- aResult, mInfallible);
- if (mErrorPtr) {
- *mErrorPtr = rv;
- }
- return rv;
- }
-
- private:
- const char* mURI;
- const char* mExportName;
- nsresult* mErrorPtr;
- bool mInfallible;
-};
-
-/**
- * These helpers make it considerably easier for C++ code to import a JS module
- * and wrap it in an appropriately-defined XPIDL interface for its exports.
- * Typical usage is something like:
- *
- * Foo.jsm:
- *
- * var EXPORTED_SYMBOLS = ["foo"];
- *
- * function foo(bar) {
- * return bar.toString();
- * }
- *
- * mozIFoo.idl:
- *
- * interface mozIFoo : nsISupports {
- * AString foo(double meh);
- * }
- *
- * Thing.cpp:
- *
- * nsCOMPtr<mozIFoo> foo = do_ImportModule(
- * "resource://meh/Foo.jsm");
- *
- * MOZ_TRY(foo->Foo(42));
- *
- * For JS modules which export all fields within a single named object, a second
- * argument can be passed naming that object.
- *
- * Foo.jsm:
- *
- * var EXPORTED_SYMBOLS = ["Foo"];
- *
- * var Foo = {
- * function foo(bar) {
- * return bar.toString();
- * }
- * };
- *
- * Thing.cpp:
- *
- * nsCOMPtr<mozIFoo> foo = do_ImportModule(
- * "resource:://meh/Foo.jsm", "Foo");
- */
-
-template <size_t N>
-inline nsImportModule do_ImportModule(const char (&aURI)[N]) {
- return {aURI, nullptr, nullptr, /* infallible */ true};
-}
-
-template <size_t N>
-inline nsImportModule do_ImportModule(const char (&aURI)[N],
- const mozilla::fallible_t&) {
- return {aURI, nullptr, nullptr, /* infallible */ false};
-}
-
-template <size_t N>
-inline nsImportModule do_ImportModule(const char (&aURI)[N], nsresult* aRv) {
- return {aURI, nullptr, aRv, /* infallible */ false};
-}
-
-template <size_t N, size_t N2>
-inline nsImportModule do_ImportModule(const char (&aURI)[N],
- const char (&aExportName)[N2]) {
- return {aURI, aExportName, nullptr, /* infallible */ true};
-}
-
-template <size_t N, size_t N2>
-inline nsImportModule do_ImportModule(const char (&aURI)[N],
- const char (&aExportName)[N2],
- const mozilla::fallible_t&) {
- return {aURI, aExportName, nullptr, /* infallible */ false};
-}
-
-template <size_t N, size_t N2>
-inline nsImportModule do_ImportModule(const char (&aURI)[N],
- const char (&aExportName)[N2],
- nsresult* aRv) {
- return {aURI, aExportName, aRv, /* infallible */ false};
-}
-
class MOZ_STACK_CLASS nsImportESModule final : public nsCOMPtr_helper {
public:
nsImportESModule(const char* aURI, const char* aExportName,
diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp
index 77dbf2d02e..3e931320a9 100644
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -50,6 +50,7 @@
#include "mozilla/dom/DOMParserBinding.h"
#include "mozilla/dom/DOMTokenListBinding.h"
#include "mozilla/dom/ElementBinding.h"
+#include "mozilla/dom/ElementInternalsBinding.h"
#include "mozilla/dom/EventBinding.h"
#include "mozilla/dom/Exceptions.h"
#include "mozilla/dom/IndexedDatabaseManager.h"
@@ -901,6 +902,8 @@ bool xpc::GlobalProperties::Parse(JSContext* cx, JS::HandleObject obj) {
CSS = true;
} else if (JS_LinearStringEqualsLiteral(nameStr, "CSSRule")) {
CSSRule = true;
+ } else if (JS_LinearStringEqualsLiteral(nameStr, "CustomStateSet")) {
+ CustomStateSet = true;
} else if (JS_LinearStringEqualsLiteral(nameStr, "Document")) {
Document = true;
} else if (JS_LinearStringEqualsLiteral(nameStr, "Directory")) {
@@ -1027,6 +1030,11 @@ bool xpc::GlobalProperties::Define(JSContext* cx, JS::HandleObject obj) {
return false;
}
+ if (CustomStateSet &&
+ !dom::CustomStateSet_Binding::GetConstructorObject(cx)) {
+ return false;
+ }
+
if (Directory && !dom::Directory_Binding::GetConstructorObject(cx))
return false;
diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp
index 9fa4e629aa..25feaf851c 100644
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -1777,7 +1777,7 @@ nsXPCComponents_Utils::GetFunctionSourceLocation(HandleValue funcValue,
NS_ENSURE_TRUE(func, NS_ERROR_INVALID_ARG);
RootedScript script(cx, JS_GetFunctionScript(cx, func));
- NS_ENSURE_TRUE(func, NS_ERROR_FAILURE);
+ NS_ENSURE_TRUE(script, NS_ERROR_FAILURE);
AppendUTF8toUTF16(nsDependentCString(JS_GetScriptFilename(script)),
filename);
diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp
index 560ac375d7..c11e4ccdfb 100644
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -250,27 +250,18 @@ bool XPCConvert::NativeData2JS(JSContext* cx, MutableHandleValue d,
// almost always ASCII, so the inexact allocations below
// should be fine.
- if (IsUtf8Latin1(*utf8String)) {
- using UniqueLatin1Chars =
- js::UniquePtr<JS::Latin1Char[], JS::FreePolicy>;
-
- UniqueLatin1Chars buffer(static_cast<JS::Latin1Char*>(
- JS_string_malloc(cx, allocLen.value())));
- if (!buffer) {
+ // Is the string buffer is already valid latin1 (i.e. it is ASCII).
+ //
+ // NOTE: XPCStringConvert::UTF8ToJSVal cannot be used here because
+ // it requires valid UTF-8 sequence.
+ if (mozilla::IsAscii(*utf8String)) {
+ nsStringBuffer* buf;
+ if (!XPCStringConvert::Latin1ToJSVal(cx, *utf8String, &buf, d)) {
return false;
}
-
- size_t written = LossyConvertUtf8toLatin1(
- *utf8String, Span(reinterpret_cast<char*>(buffer.get()), len));
- buffer[written] = 0;
-
- // written can never exceed len, so the truncation is OK.
- JSString* str = JS_NewLatin1String(cx, std::move(buffer), written);
- if (!str) {
- return false;
+ if (buf) {
+ buf->AddRef();
}
-
- d.setString(str);
return true;
}
@@ -670,24 +661,7 @@ bool XPCConvert::JSData2Native(JSContext* cx, void* d, HandleValue s,
return true;
}
- JSLinearString* linear = JS_EnsureLinearString(cx, str);
- if (!linear) {
- return false;
- }
-
- size_t utf8Length = JS::GetDeflatedUTF8StringLength(linear);
- if (!rs->SetLength(utf8Length, fallible)) {
- if (pErr) {
- *pErr = NS_ERROR_OUT_OF_MEMORY;
- }
- return false;
- }
-
- mozilla::DebugOnly<size_t> written = JS::DeflateStringToUTF8Buffer(
- linear, mozilla::Span(rs->BeginWriting(), utf8Length));
- MOZ_ASSERT(written == utf8Length);
-
- return true;
+ return AssignJSString(cx, *rs, str);
}
case nsXPTType::T_CSTRING: {
diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp
index 7bf574f675..8f3621f9c5 100644
--- a/js/xpconnect/src/XPCJSContext.cpp
+++ b/js/xpconnect/src/XPCJSContext.cpp
@@ -812,11 +812,6 @@ void xpc::SetPrefableContextOptions(JS::ContextOptions& options) {
.setWasmIon(Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_optimizingjit"))
.setWasmBaseline(
Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_baselinejit"))
-#define WASM_FEATURE(NAME, LOWER_NAME, STAGE, COMPILE_PRED, COMPILER_PRED, \
- FLAG_PRED, FLAG_FORCE_ON, FLAG_FUZZ_ON, SHELL, PREF) \
- .setWasm##NAME(Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_" PREF))
- JS_FOR_WASM_FEATURES(WASM_FEATURE)
-#undef WASM_FEATURE
.setWasmVerbose(Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_verbose"))
.setAsyncStack(Preferences::GetBool(JS_OPTIONS_DOT_STR "asyncstack"))
.setAsyncStackCaptureDebuggeeOnly(Preferences::GetBool(
diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp
index c4d272b950..fd495ec964 100644
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -8,13 +8,13 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/AutoRestore.h"
+#include "mozilla/AppShutdown.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/UniquePtr.h"
#include "xpcprivate.h"
#include "xpcpublic.h"
#include "XPCMaps.h"
-#include "XPCWrapper.h"
#include "XPCJSMemoryReporter.h"
#include "XrayWrapper.h"
#include "WrapperFactory.h"
@@ -28,11 +28,9 @@
#include "nsIObserverService.h"
#include "mozilla/dom/Document.h"
#include "nsIRunnable.h"
-#include "nsIPlatformInfo.h"
#include "nsPIDOMWindow.h"
#include "nsPrintfCString.h"
#include "nsScriptSecurityManager.h"
-#include "nsThreadPool.h"
#include "nsWindowSizes.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/Preferences.h"
@@ -40,6 +38,7 @@
#include "mozilla/Services.h"
#include "mozilla/dom/ScriptLoader.h"
#include "mozilla/dom/ScriptSettings.h"
+#include "mozilla/glean/GleanMetrics.h"
#include "nsContentUtils.h"
#include "nsCCUncollectableMarker.h"
@@ -613,9 +612,13 @@ JSObject* NACScope(JSObject* global) {
return scope;
}
-JSObject* PrivilegedJunkScope() { return XPCJSRuntime::Get()->LoaderGlobal(); }
+JSObject* PrivilegedJunkScope() {
+ return mozJSModuleLoader::Get()->GetSharedGlobal();
+}
-JSObject* CompilationScope() { return XPCJSRuntime::Get()->LoaderGlobal(); }
+JSObject* CompilationScope() {
+ return mozJSModuleLoader::Get()->GetSharedGlobal();
+}
nsGlobalWindowInner* WindowOrNull(JSObject* aObj) {
MOZ_ASSERT(aObj);
@@ -1454,6 +1457,9 @@ static void ReportZoneStats(const JS::ZoneStats& zStats,
zStats.regExpSharedsMallocHeap,
"Shared compiled regexp data.");
+ ZRREPORT_BYTES(pathPrefix + "zone-object"_ns, zStats.zoneObject,
+ "The JS::Zone object itself.");
+
ZRREPORT_BYTES(pathPrefix + "regexp-zone"_ns, zStats.regexpZone,
"The regexp zone and regexp data.");
@@ -2638,9 +2644,6 @@ static void SetUseCounterCallback(JSObject* obj, JSUseCounter counter) {
case JSUseCounter::WASM_LEGACY_EXCEPTIONS:
SetUseCounter(obj, eUseCounter_custom_JS_wasm_legacy_exceptions);
break;
- case JSUseCounter::LATE_WEEKDAY:
- SetUseCounter(obj, eUseCounter_custom_JS_late_weekday);
- break;
default:
MOZ_ASSERT_UNREACHABLE("Unexpected JSUseCounter id");
}
@@ -2905,8 +2908,6 @@ void ConstructUbiNode(void* storage, JSObject* ptr) {
}
void XPCJSRuntime::Initialize(JSContext* cx) {
- mLoaderGlobal.init(cx, nullptr);
-
// these jsids filled in later when we have a JSContext to work with.
mStrIDs[0] = JS::PropertyKey::Void();
@@ -3191,20 +3192,6 @@ void XPCJSRuntime::DeleteSingletonScopes() {
sandbox->ReleaseWrapper(sandbox);
mUnprivilegedJunkScope = nullptr;
}
- mLoaderGlobal = nullptr;
-}
-
-JSObject* XPCJSRuntime::LoaderGlobal() {
- if (!mLoaderGlobal) {
- RefPtr loader = mozJSModuleLoader::Get();
-
- dom::AutoJSAPI jsapi;
- jsapi.Init();
-
- mLoaderGlobal = loader->GetSharedGlobal(jsapi.cx());
- MOZ_RELEASE_ASSERT(!JS_IsExceptionPending(jsapi.cx()));
- }
- return mLoaderGlobal;
}
uint32_t GetAndClampCPUCount() {
diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp
index 38a02e9b2f..b36ba56aed 100644
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -1084,6 +1084,10 @@ int XRE_XPCShellMain(int argc, char** argv, char** envp,
// stability, we should instantiate COM ASAP so that we can ensure that these
// global settings are configured before anything can interfere.
mscom::ProcessRuntime mscom;
+
+# ifdef MOZ_SANDBOX
+ nsAutoString binDirPath;
+# endif
#endif
// The provider needs to outlive the call to shutting down XPCOM.
@@ -1103,6 +1107,11 @@ int XRE_XPCShellMain(int argc, char** argv, char** envp,
return 1;
}
+#if defined(XP_WIN) && defined(MOZ_SANDBOX)
+ // We need the binary directory to initialize the windows sandbox.
+ MOZ_ALWAYS_SUCCEEDS(appDir->GetPath(binDirPath));
+#endif
+
dirprovider.SetAppFile(appFile);
nsCOMPtr<nsIFile> greDir;
@@ -1301,7 +1310,7 @@ int XRE_XPCShellMain(int argc, char** argv, char** envp,
# if defined(MOZ_SANDBOX)
// Required for sandboxed child processes.
if (aShellData->sandboxBrokerServices) {
- SandboxBroker::Initialize(aShellData->sandboxBrokerServices);
+ SandboxBroker::Initialize(aShellData->sandboxBrokerServices, binDirPath);
SandboxBroker::GeckoDependentInitialize();
} else {
NS_WARNING(
diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h
index 57a4b1e02e..1e873d9c05 100644
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -560,7 +560,6 @@ class XPCJSRuntime final : public mozilla::CycleCollectedJSRuntime {
JSObject* UnprivilegedJunkScope(const mozilla::fallible_t&);
bool IsUnprivilegedJunkScope(JSObject*);
- JSObject* LoaderGlobal();
void DeleteSingletonScopes();
@@ -610,7 +609,6 @@ class XPCJSRuntime final : public mozilla::CycleCollectedJSRuntime {
JS::GCSliceCallback mPrevGCSliceCallback;
JS::DoCycleCollectionCallback mPrevDoCycleCollectionCallback;
mozilla::WeakPtr<SandboxPrivate> mUnprivilegedJunkScope;
- JS::PersistentRootedObject mLoaderGlobal;
RefPtr<AsyncFreeSnowWhite> mAsyncSnowWhiteFreer;
friend class XPCJSContext;
@@ -2193,6 +2191,7 @@ struct GlobalProperties {
bool ChromeUtils : 1;
bool CSS : 1;
bool CSSRule : 1;
+ bool CustomStateSet : 1;
bool Directory : 1;
bool Document : 1;
bool DOMException : 1;
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",