From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- js/xpconnect/loader/mozJSModuleLoader.cpp | 28 ++++++++++++++++++++++++++++ js/xpconnect/loader/mozJSModuleLoader.h | 1 + 2 files changed, 29 insertions(+) (limited to 'js/xpconnect/loader') 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 mLocations; bool mInitialized; + bool mIsUnloaded = false; #ifdef DEBUG bool mIsInitializingLoaderGlobal = false; #endif -- cgit v1.2.3