зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1768922 - Support ESM loaded by shim in Cu.isModuleLoaded. r=yulia
Differential Revision: https://phabricator.services.mozilla.com/D146166
This commit is contained in:
Родитель
ccbca0889a
Коммит
11c8544fb4
|
@ -344,15 +344,17 @@ nsresult ModuleLoaderBase::StartOrRestartModuleLoad(ModuleLoadRequest* aRequest,
|
|||
}
|
||||
|
||||
bool ModuleLoaderBase::ModuleMapContainsURL(nsIURI* aURL) const {
|
||||
// Returns whether we have fetched, or are currently fetching, a module script
|
||||
// for a URL.
|
||||
return mFetchingModules.Contains(aURL) || mFetchedModules.Contains(aURL);
|
||||
return IsModuleFetching(aURL) || IsModuleFetched(aURL);
|
||||
}
|
||||
|
||||
bool ModuleLoaderBase::IsModuleFetching(nsIURI* aURL) const {
|
||||
return mFetchingModules.Contains(aURL);
|
||||
}
|
||||
|
||||
bool ModuleLoaderBase::IsModuleFetched(nsIURI* aURL) const {
|
||||
return mFetchedModules.Contains(aURL);
|
||||
}
|
||||
|
||||
void ModuleLoaderBase::SetModuleFetchStarted(ModuleLoadRequest* aRequest) {
|
||||
// Update the module map to indicate that a module is currently being fetched.
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#include "nsRefPtrHashtable.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsILoadInfo.h" // nsSecurityFlags
|
||||
#include "nsINode.h" // nsIURI
|
||||
#include "nsILoadInfo.h" // nsSecurityFlags
|
||||
#include "nsINode.h" // nsIURI
|
||||
#include "nsThreadUtils.h" // GetMainThreadSerialEventTarget
|
||||
#include "nsURIHashKey.h"
|
||||
#include "mozilla/CORSMode.h"
|
||||
|
@ -274,6 +274,9 @@ class ModuleLoaderBase : public nsISupports {
|
|||
mAcquiringImportMaps = acquiring;
|
||||
}
|
||||
|
||||
// Returns true if the module for given URL is already fetched.
|
||||
bool IsModuleFetched(nsIURI* aURL) const;
|
||||
|
||||
// Internal methods.
|
||||
|
||||
private:
|
||||
|
|
|
@ -1100,14 +1100,27 @@ nsresult mozJSComponentLoader::IsModuleLoaded(const nsACString& aLocation,
|
|||
|
||||
mInitialized = true;
|
||||
ComponentLoaderInfo info(aLocation);
|
||||
*retval = !!mImports.Get(info.Key());
|
||||
|
||||
if (!*retval && IsJSM(aLocation)) {
|
||||
nsAutoCString mjsLocation;
|
||||
ToMJS(aLocation, mjsLocation);
|
||||
return IsModuleLoaded(mjsLocation, retval);
|
||||
if (mImports.Get(info.Key())) {
|
||||
*retval = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (IsJSM(aLocation) && mModuleLoader) {
|
||||
nsAutoCString mjsLocation;
|
||||
ToMJS(aLocation, mjsLocation);
|
||||
|
||||
ComponentLoaderInfo mjsInfo(mjsLocation);
|
||||
|
||||
nsresult rv = mjsInfo.EnsureURI();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mModuleLoader->IsModuleFetched(mjsInfo.URI())) {
|
||||
*retval = true;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
*retval = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
export let loadCount = 0;
|
||||
loadCount++;
|
||||
|
||||
export const obj = { value: 10 };
|
|
@ -0,0 +1,4 @@
|
|||
export let loadCount = 0;
|
||||
loadCount++;
|
||||
|
||||
export const obj = { value: 10 };
|
|
@ -300,3 +300,32 @@ add_task(function test_Cu_import_not_exported_shim() {
|
|||
Assert.equal(global["*namespace*"], undefined,
|
||||
`*namespace* special binding should not be exposed`);
|
||||
});
|
||||
|
||||
add_task(function test_Cu_isModuleLoaded_shim() {
|
||||
Assert.equal(Cu.isModuleLoaded("resource://test/esmified-5.jsm"), false);
|
||||
Assert.equal(Cu.isModuleLoaded("resource://test/esmified-5.mjs"), false);
|
||||
|
||||
Cu.import("resource://test/esmified-5.jsm", {});
|
||||
|
||||
Assert.equal(Cu.isModuleLoaded("resource://test/esmified-5.jsm"), true);
|
||||
|
||||
// This is false because Cu.isModuleLoaded does not support ESM directly
|
||||
// (bug 1768819)
|
||||
Assert.equal(Cu.isModuleLoaded("resource://test/esmified-5.mjs"), false);
|
||||
});
|
||||
|
||||
add_task(function test_Cu_isModuleLoaded_no_shim() {
|
||||
Assert.equal(Cu.isModuleLoaded("resource://test/esmified-6.jsm"), false);
|
||||
Assert.equal(Cu.isModuleLoaded("resource://test/esmified-6.mjs"), false);
|
||||
|
||||
ChromeUtils.importModule("resource://test/esmified-6.mjs");
|
||||
|
||||
// Regardless of whether the ESM is loaded by shim or not,
|
||||
// query that accesses the ESM-ified module returns the existence of
|
||||
// ESM.
|
||||
Assert.equal(Cu.isModuleLoaded("resource://test/esmified-6.jsm"), true);
|
||||
|
||||
// This is false because Cu.isModuleLoaded does not support ESM directly
|
||||
// (bug 1768819)
|
||||
Assert.equal(Cu.isModuleLoaded("resource://test/esmified-6.mjs"), false);
|
||||
});
|
||||
|
|
|
@ -32,6 +32,8 @@ support-files =
|
|||
esmified-2.mjs
|
||||
esmified-3.mjs
|
||||
esmified-4.mjs
|
||||
esmified-5.mjs
|
||||
esmified-6.mjs
|
||||
esmified-not-exported.mjs
|
||||
not-esmified-not-exported.jsm
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче