Bug 1877703 - Part 2: Track request for currently fetching module in the module map r=smaug

Currently we record the URI of each fetching modules and any addtional requests
that are blocked waiting on that fetch. This adds the fetching module request
itself.

This is needed by the next patch.

Differential Revision: https://phabricator.services.mozilla.com/D204201
This commit is contained in:
Jon Coppeard
2024-03-13 13:25:29 +00:00
parent cb76d1f909
commit c3449718cd
2 changed files with 36 additions and 30 deletions

View File

@@ -165,20 +165,30 @@ class ScriptLoaderInterface : public nsISupports {
*/
class ModuleLoaderBase : public nsISupports {
/*
* The set of requests that are waiting for an ongoing fetch to complete.
* Represents an ongoing load operation for a URI initiated for one request
* and which may have other requests waiting for it to complete.
*
* These are tracked in the mFetchingModules map.
*/
class WaitingRequests final : public nsISupports {
virtual ~WaitingRequests() = default;
class LoadingRequest final : public nsISupports {
virtual ~LoadingRequest() = default;
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(WaitingRequests)
NS_DECL_CYCLE_COLLECTION_CLASS(LoadingRequest)
// The request that initiated the load and which is currently fetching or
// being compiled.
RefPtr<ModuleLoadRequest> mRequest;
// A list of any other requests for the same URI that are waiting for the
// initial load to complete. These will be resumed by ResumeWaitingRequests
// when that happens.
nsTArray<RefPtr<ModuleLoadRequest>> mWaiting;
};
// Module map
nsRefPtrHashtable<nsURIHashKey, WaitingRequests> mFetchingModules;
nsRefPtrHashtable<nsURIHashKey, LoadingRequest> mFetchingModules;
nsRefPtrHashtable<nsURIHashKey, ModuleScript> mFetchedModules;
// List of dynamic imports that are currently being loaded.
@@ -421,7 +431,7 @@ class ModuleLoaderBase : public nsISupports {
void SetModuleFetchFinishedAndResumeWaitingRequests(
ModuleLoadRequest* aRequest, nsresult aResult);
void ResumeWaitingRequests(WaitingRequests* aWaitingRequests, bool aSuccess);
void ResumeWaitingRequests(LoadingRequest* aLoadingRequest, bool aSuccess);
void ResumeWaitingRequest(ModuleLoadRequest* aRequest, bool aSuccess);
void StartFetchingModuleDependencies(ModuleLoadRequest* aRequest);