diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
commit | da4c7e7ed675c3bf405668739c3012d140856109 (patch) | |
tree | cdd868dba063fecba609a1d819de271f0d51b23e /js/xpconnect | |
parent | Adding upstream version 125.0.3. (diff) | |
download | firefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip |
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/xpconnect')
-rw-r--r-- | js/xpconnect/idl/xpccomponents.idl | 12 | ||||
-rw-r--r-- | js/xpconnect/loader/mozJSModuleLoader.cpp | 28 | ||||
-rw-r--r-- | js/xpconnect/loader/mozJSModuleLoader.h | 1 | ||||
-rw-r--r-- | js/xpconnect/src/Sandbox.cpp | 4 | ||||
-rw-r--r-- | js/xpconnect/src/XPCJSRuntime.cpp | 3 | ||||
-rw-r--r-- | js/xpconnect/tests/mochitest/mochitest.toml | 2 | ||||
-rw-r--r-- | js/xpconnect/tests/mochitest/test_bug871887.html | 43 | ||||
-rw-r--r-- | js/xpconnect/tests/unit/test_import_global_current.js | 2 | ||||
-rw-r--r-- | js/xpconnect/tests/unit/test_scriptable_nsIClassInfo.js | 41 | ||||
-rw-r--r-- | js/xpconnect/tests/unit/xpcshell.toml | 2 | ||||
-rw-r--r-- | js/xpconnect/wrappers/XrayWrapper.cpp | 24 |
11 files changed, 98 insertions, 64 deletions
diff --git a/js/xpconnect/idl/xpccomponents.idl b/js/xpconnect/idl/xpccomponents.idl index 1d4155ed74..47ed22e3a5 100644 --- a/js/xpconnect/idl/xpccomponents.idl +++ b/js/xpconnect/idl/xpccomponents.idl @@ -261,7 +261,7 @@ interface nsIXPCComponents_Utils : nsISupports [optional] in jsval version, [optional] in AUTF8String filename, [optional] in long lineNo, - [optional] in bool enforceFilenameRestrictions); + [optional] in boolean enforceFilenameRestrictions); /* * Get the sandbox for running JS-implemented UA widgets (video controls etc.), @@ -569,7 +569,7 @@ interface nsIXPCComponents_Utils : nsISupports * reference edges) and will throw if you touch them (e.g. by * reading/writing a property). */ - bool isDeadWrapper(in jsval obj); + boolean isDeadWrapper(in jsval obj); /** * Determines whether this value is a remote object proxy, such as @@ -584,7 +584,7 @@ interface nsIXPCComponents_Utils : nsISupports * frame.contentWindow.doCrossOriginThing(); * } */ - bool isRemoteProxy(in jsval val); + boolean isRemoteProxy(in jsval val); /* * To be called from JS only. This is for Gecko internal use only, and may @@ -653,12 +653,12 @@ interface nsIXPCComponents_Utils : nsISupports /** * Check whether the given object is an opaque wrapper (PermissiveXrayOpaque). */ - bool isOpaqueWrapper(in jsval obj); + boolean isOpaqueWrapper(in jsval obj); /** * Check whether the given object is an XrayWrapper. */ - bool isXrayWrapper(in jsval obj); + boolean isXrayWrapper(in jsval obj); /** * Waive Xray on a given value. Identity op for primitives. @@ -680,7 +680,7 @@ interface nsIXPCComponents_Utils : nsISupports * probably what you want. */ [implicit_jscontext] - string getClassName(in jsval aObj, in bool aUnwrap); + string getClassName(in jsval aObj, in boolean aUnwrap); /** * Get a DOM classinfo for the given classname. Only some class diff --git a/js/xpconnect/loader/mozJSModuleLoader.cpp b/js/xpconnect/loader/mozJSModuleLoader.cpp index 017ac32b3b..cdf4df1970 100644 --- a/js/xpconnect/loader/mozJSModuleLoader.cpp +++ b/js/xpconnect/loader/mozJSModuleLoader.cpp @@ -1279,7 +1279,10 @@ nsresult mozJSModuleLoader::GetScriptForLocation( } void mozJSModuleLoader::UnloadModules() { + MOZ_ASSERT(!mIsUnloaded); + mInitialized = false; + mIsUnloaded = true; if (mLoaderGlobal) { MOZ_ASSERT(JS_HasExtensibleLexicalEnvironment(mLoaderGlobal)); @@ -1387,6 +1390,11 @@ nsresult mozJSModuleLoader::IsModuleLoaded(const nsACString& aLocation, bool* retval) { MOZ_ASSERT(nsContentUtils::IsCallerChrome()); + if (mIsUnloaded) { + *retval = false; + return NS_OK; + } + mInitialized = true; ModuleLoaderInfo info(aLocation); if (mImports.Get(info.Key())) { @@ -1420,6 +1428,11 @@ nsresult mozJSModuleLoader::IsJSModuleLoaded(const nsACString& aLocation, bool* retval) { MOZ_ASSERT(nsContentUtils::IsCallerChrome()); + if (mIsUnloaded) { + *retval = false; + return NS_OK; + } + mInitialized = true; ModuleLoaderInfo info(aLocation); if (mImports.Get(info.Key())) { @@ -1435,6 +1448,11 @@ nsresult mozJSModuleLoader::IsESModuleLoaded(const nsACString& aLocation, bool* retval) { MOZ_ASSERT(nsContentUtils::IsCallerChrome()); + if (mIsUnloaded) { + *retval = false; + return NS_OK; + } + mInitialized = true; ModuleLoaderInfo info(aLocation); @@ -1728,6 +1746,11 @@ nsresult mozJSModuleLoader::Import(JSContext* aCx, const nsACString& aLocation, JS::MutableHandleObject aModuleGlobal, JS::MutableHandleObject aModuleExports, bool aIgnoreExports) { + if (mIsUnloaded) { + JS_ReportErrorASCII(aCx, "Module loaded is already unloaded"); + return NS_ERROR_FAILURE; + } + mInitialized = true; AUTO_PROFILER_MARKER_TEXT( @@ -2013,6 +2036,11 @@ nsresult mozJSModuleLoader::ImportESModule( aSkipCheck /* = SkipCheckForBrokenURLOrZeroSized::No */) { using namespace JS::loader; + if (mIsUnloaded) { + JS_ReportErrorASCII(aCx, "Module loaded is already unloaded"); + return NS_ERROR_FAILURE; + } + mInitialized = true; // Called from ChromeUtils::ImportESModule. diff --git a/js/xpconnect/loader/mozJSModuleLoader.h b/js/xpconnect/loader/mozJSModuleLoader.h index ac118c507d..b5e81a4b25 100644 --- a/js/xpconnect/loader/mozJSModuleLoader.h +++ b/js/xpconnect/loader/mozJSModuleLoader.h @@ -290,6 +290,7 @@ class mozJSModuleLoader final : public nsIMemoryReporter { nsClassHashtable<nsCStringHashKey, nsCString> mLocations; bool mInitialized; + bool mIsUnloaded = false; #ifdef DEBUG bool mIsInitializingLoaderGlobal = false; #endif diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index 3e931320a9..ed77605193 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -311,7 +311,7 @@ static bool SandboxFetch(JSContext* cx, JS::HandleObject scope, } BindingCallContext callCx(cx, "fetch"); - RequestOrUSVString request; + RequestOrUTF8String request; if (!request.Init(callCx, args[0], "Argument 1")) { return false; } @@ -1274,7 +1274,7 @@ nsresult ApplyAddonContentScriptCSP(nsISupports* prinOrSop) { csp = new nsCSPContext(); MOZ_TRY( - csp->SetRequestContextWithPrincipal(clonedPrincipal, selfURI, u""_ns, 0)); + csp->SetRequestContextWithPrincipal(clonedPrincipal, selfURI, ""_ns, 0)); MOZ_TRY(csp->AppendPolicy(baseCSP, false, false)); diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index fd495ec964..567cd860cf 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -2589,7 +2589,8 @@ static void AccumulateTelemetryCallback(JSMetric id, uint32_t sample) { glean::performance_clone_deserialize::size.Accumulate(sample); break; case JSMetric::DESERIALIZE_ITEMS: - glean::performance_clone_deserialize::items.AccumulateSamples({sample}); + glean::performance_clone_deserialize::items.AccumulateSingleSample( + sample); break; case JSMetric::DESERIALIZE_US: glean::performance_clone_deserialize::time.AccumulateRawDuration( diff --git a/js/xpconnect/tests/mochitest/mochitest.toml b/js/xpconnect/tests/mochitest/mochitest.toml index c57cb26890..bc0f1d97b7 100644 --- a/js/xpconnect/tests/mochitest/mochitest.toml +++ b/js/xpconnect/tests/mochitest/mochitest.toml @@ -200,8 +200,6 @@ skip-if = [ "http2", ] -["test_bug871887.html"] - ["test_bug912322.html"] ["test_bug916945.html"] diff --git a/js/xpconnect/tests/mochitest/test_bug871887.html b/js/xpconnect/tests/mochitest/test_bug871887.html deleted file mode 100644 index 082b2ae746..0000000000 --- a/js/xpconnect/tests/mochitest/test_bug871887.html +++ /dev/null @@ -1,43 +0,0 @@ -<!DOCTYPE HTML> -<html> -<!-- -https://bugzilla.mozilla.org/show_bug.cgi?id=871887 ---> -<head> - <meta charset="utf-8"> - <title>Test for Bug 871887</title> - <script src="/tests/SimpleTest/SimpleTest.js"></script> - <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> - <script type="application/javascript"> - - /** Test for Bug 871887 **/ - SimpleTest.waitForExplicitFinish(); - - // NB: onstart ends up getting invoked twice, for mysterious and potentially- - // IE6-related reasons. - function checkpoint(invocant) { - ok(true, "onstart called"); - is(invocant, $('llama'), "this-binding is correct"); - $('llama').loop = 1; - $('llama').scrollDelay = 1; - $('llama').scrollAmount = 500; - } - - function done(invocant) { - is(invocant, $('llama'), "this-binding is correct"); - ok(true, "onfinish called"); - SimpleTest.finish(); - } - - </script> -</head> -<body> -<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=871887">Mozilla Bug 871887</a> -<p id="display"></p> -<div id="content"> -<marquee id="llama" onstart="checkpoint(this);" onfinish="done(this);">Watch the Llama</marquee> -</div> -<pre id="test"> -</pre> -</body> -</html> diff --git a/js/xpconnect/tests/unit/test_import_global_current.js b/js/xpconnect/tests/unit/test_import_global_current.js index cf466a7391..59037512f3 100644 --- a/js/xpconnect/tests/unit/test_import_global_current.js +++ b/js/xpconnect/tests/unit/test_import_global_current.js @@ -204,7 +204,7 @@ ChromeUtils.importESModule("resource://test/es6module_import_error.js", { `, sb); } catch (e) { caught = true; - Assert.stringMatches(e.message, /import not found/); + Assert.stringMatches(e.message, /doesn't provide an export named/); } Assert.ok(caught); }); diff --git a/js/xpconnect/tests/unit/test_scriptable_nsIClassInfo.js b/js/xpconnect/tests/unit/test_scriptable_nsIClassInfo.js new file mode 100644 index 0000000000..161afcbb9b --- /dev/null +++ b/js/xpconnect/tests/unit/test_scriptable_nsIClassInfo.js @@ -0,0 +1,41 @@ +/* Any copyright is dedicated to the Public Domain. +https://creativecommons.org/publicdomain/zero/1.0/ */ + +add_task(function () { + class TestClass { + QueryInterface = ChromeUtils.generateQI([ + "nsIXPCTestInterfaceA", + "nsIClassInfo", + ]); + + interfaces = [Ci.nsIXPCTestInterfaceA, Ci.nsIClassInfo, Ci.nsISupports]; + contractID = "@mozilla.org/test/class;1"; + classDescription = "description"; + classID = Components.ID("{4da556d4-00fa-451a-a280-d2aec7c5f265}"); + flags = 0; + + name = "this is a test"; + } + + let instance = new TestClass(); + Assert.ok(instance, "can create an instance"); + Assert.ok(instance.QueryInterface(Ci.nsIClassInfo), "can QI to nsIClassInfo"); + + let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); + registrar.registerFactory( + instance.classID, + instance.classDescription, + instance.contractID, + { + createInstance(iid) { + return instance.QueryInterface(iid); + }, + } + ); + Assert.ok(true, "successfully registered the factory"); + + let otherInstance = Cc["@mozilla.org/test/class;1"].createInstance( + Ci.nsIXPCTestInterfaceA + ); + Assert.ok(otherInstance, "can create an instance via xpcom"); +}); diff --git a/js/xpconnect/tests/unit/xpcshell.toml b/js/xpconnect/tests/unit/xpcshell.toml index 37274eba96..b7bc15afdc 100644 --- a/js/xpconnect/tests/unit/xpcshell.toml +++ b/js/xpconnect/tests/unit/xpcshell.toml @@ -358,6 +358,8 @@ head = "head_ongc.js" ["test_sandbox_name.js"] +["test_scriptable_nsIClassInfo.js"] + ["test_storage.js"] ["test_structuredClone.js"] diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index cdedb02a5f..48696cd12d 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -1799,6 +1799,11 @@ bool DOMXrayTraits::call(JSContext* cx, HandleObject wrapper, // using "legacycaller". At this time for all the legacycaller users it makes // more sense to invoke on the xray compartment, so we just go ahead and do // that for everything. + if (IsDOMConstructor(obj)) { + const JSNativeHolder* holder = NativeHolderFromObject(obj); + return holder->mNative(cx, args.length(), args.base()); + } + if (js::IsProxy(obj)) { if (JS::IsCallable(obj)) { // Passing obj here, but it doesn't really matter because legacycaller @@ -1822,20 +1827,21 @@ bool DOMXrayTraits::construct(JSContext* cx, HandleObject wrapper, const JS::CallArgs& args, const js::Wrapper& baseInstance) { RootedObject obj(cx, getTargetObject(wrapper)); - MOZ_ASSERT(mozilla::dom::HasConstructor(obj)); - const JSClass* clasp = JS::GetClass(obj); // See comments in DOMXrayTraits::call() explaining what's going on here. - if (clasp->flags & JSCLASS_IS_DOMIFACEANDPROTOJSCLASS) { - if (JSNative construct = clasp->getConstruct()) { - if (!construct(cx, args.length(), args.base())) { - return false; - } - } else { + if (IsDOMConstructor(obj)) { + const JSNativeHolder* holder = NativeHolderFromObject(obj); + if (!holder->mNative(cx, args.length(), args.base())) { + return false; + } + } else { + const JSClass* clasp = JS::GetClass(obj); + if (clasp->flags & JSCLASS_IS_DOMIFACEANDPROTOJSCLASS) { + MOZ_ASSERT(!clasp->getConstruct()); + RootedValue v(cx, ObjectValue(*wrapper)); js::ReportIsNotFunction(cx, v); return false; } - } else { if (!baseInstance.construct(cx, wrapper, args)) { return false; } |