зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1767829 - Part 3: Add the option for derived module loaders to specifiy their own event target r=yulia
Module loaders require an event target to use with mozPromise. The default uses the event loop so doesn't permit implementing a synchronous module loader. Differential Revision: https://phabricator.services.mozilla.com/D145490
This commit is contained in:
Родитель
1e506ccabd
Коммит
ce9567cdac
|
@ -27,11 +27,9 @@
|
|||
#include "nsContentUtils.h"
|
||||
#include "nsICacheInfoChannel.h" // nsICacheInfoChannel
|
||||
#include "nsNetUtil.h" // NS_NewURI
|
||||
#include "nsThreadUtils.h" // GetMainThreadSerialEventTarget
|
||||
#include "xpcpublic.h"
|
||||
|
||||
using mozilla::Err;
|
||||
using mozilla::GetMainThreadSerialEventTarget;
|
||||
using mozilla::Preferences;
|
||||
using mozilla::UniquePtr;
|
||||
using mozilla::WrapNotNull;
|
||||
|
@ -57,7 +55,8 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ModuleLoaderBase)
|
|||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(ModuleLoaderBase, mFetchedModules,
|
||||
mDynamicImportRequests, mGlobalObject, mLoader)
|
||||
mDynamicImportRequests, mGlobalObject, mEventTarget,
|
||||
mLoader)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(ModuleLoaderBase)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(ModuleLoaderBase)
|
||||
|
@ -321,7 +320,7 @@ nsresult ModuleLoaderBase::StartOrRestartModuleLoad(ModuleLoadRequest* aRequest,
|
|||
if (aRestart == RestartRequest::No && ModuleMapContainsURL(request->mURI)) {
|
||||
LOG(("ScriptLoadRequest (%p): Waiting for module fetch", aRequest));
|
||||
WaitForModuleFetch(request->mURI)
|
||||
->Then(GetMainThreadSerialEventTarget(), __func__, request,
|
||||
->Then(mEventTarget, __func__, request,
|
||||
&ModuleLoadRequest::ModuleLoaded,
|
||||
&ModuleLoadRequest::LoadFailed);
|
||||
return NS_OK;
|
||||
|
@ -747,9 +746,8 @@ void ModuleLoaderBase::StartFetchingModuleDependencies(
|
|||
|
||||
// Wait for all imports to become ready.
|
||||
RefPtr<mozilla::GenericPromise::AllPromiseType> allReady =
|
||||
mozilla::GenericPromise::All(mozilla::GetMainThreadSerialEventTarget(),
|
||||
importsReady);
|
||||
allReady->Then(mozilla::GetMainThreadSerialEventTarget(), __func__, aRequest,
|
||||
mozilla::GenericPromise::All(mEventTarget, importsReady);
|
||||
allReady->Then(mEventTarget, __func__, aRequest,
|
||||
&ModuleLoadRequest::DependenciesLoaded,
|
||||
&ModuleLoadRequest::ModuleErrored);
|
||||
}
|
||||
|
@ -852,9 +850,13 @@ void ModuleLoaderBase::FinishDynamicImport(
|
|||
}
|
||||
|
||||
ModuleLoaderBase::ModuleLoaderBase(ScriptLoaderInterface* aLoader,
|
||||
nsIGlobalObject* aGlobalObject)
|
||||
: mGlobalObject(aGlobalObject), mLoader(aLoader) {
|
||||
nsIGlobalObject* aGlobalObject,
|
||||
nsISerialEventTarget* aEventTarget)
|
||||
: mGlobalObject(aGlobalObject),
|
||||
mEventTarget(aEventTarget),
|
||||
mLoader(aLoader) {
|
||||
MOZ_ASSERT(mGlobalObject);
|
||||
MOZ_ASSERT(mEventTarget);
|
||||
MOZ_ASSERT(mLoader);
|
||||
|
||||
EnsureModuleHooksInitialized();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsILoadInfo.h" // nsSecurityFlags
|
||||
#include "nsINode.h" // nsIURI
|
||||
#include "nsThreadUtils.h" // GetMainThreadSerialEventTarget
|
||||
#include "nsURIHashKey.h"
|
||||
#include "mozilla/CORSMode.h"
|
||||
#include "mozilla/dom/JSExecutionContext.h"
|
||||
|
@ -155,6 +156,10 @@ class ModuleLoaderBase : public nsISupports {
|
|||
|
||||
nsCOMPtr<nsIGlobalObject> mGlobalObject;
|
||||
|
||||
// Event handler used to process MozPromise actions, used internally to wait
|
||||
// for fetches to finish and for imports to become avilable.
|
||||
nsCOMPtr<nsISerialEventTarget> mEventTarget;
|
||||
|
||||
// https://wicg.github.io/import-maps/#document-acquiring-import-maps
|
||||
//
|
||||
// Each Document has an acquiring import maps boolean. It is initially true.
|
||||
|
@ -171,7 +176,9 @@ class ModuleLoaderBase : public nsISupports {
|
|||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(ModuleLoaderBase)
|
||||
explicit ModuleLoaderBase(ScriptLoaderInterface* aLoader,
|
||||
nsIGlobalObject* aGlobalObject);
|
||||
nsIGlobalObject* aGlobalObject,
|
||||
nsISerialEventTarget* aEventTarget =
|
||||
mozilla::GetMainThreadSerialEventTarget());
|
||||
|
||||
using LoadedScript = JS::loader::LoadedScript;
|
||||
using ScriptFetchOptions = JS::loader::ScriptFetchOptions;
|
||||
|
|
Загрузка…
Ссылка в новой задаче