Bug 1847813 - Process loaded modules asynchronously in DOM module loader r=smaug
Based on the explanation on the bug, the solution would seem to be to call the ModuleLoaderBase::OnModuleLoadComplete hook from a microtask. This causes a ton of test failures. Instead this patch changes the DOM script loader to implement this hook with a runnable. This fixes the problem (verified manually) and all tests pass. (Replacing the runnable with a microtask just in the DOM script loader also does not work and results in many test failures. I'm still trying to understand why.) The changes to ContinueDynamicImport are removed because they are also on this path and we don't need a microtask as well. This takes us closer to the state before bug 1842798 landed when all the module loader used MozPromise internally and completions like this happened via runnables. I was not able to immediately come up with a test for this. Differential Revision: https://phabricator.services.mozilla.com/D185830
This commit is contained in:
@@ -1196,42 +1196,12 @@ nsresult ModuleLoaderBase::InitDebuggerDataForModuleGraph(
|
||||
}
|
||||
|
||||
void ModuleLoaderBase::ProcessDynamicImport(ModuleLoadRequest* aRequest) {
|
||||
// Instantiate and evaluate the imported module.
|
||||
// See: https://tc39.es/ecma262/#sec-ContinueDynamicImport
|
||||
//
|
||||
// Since this is specced as happening on promise resolution (step 8) this must
|
||||
// at least run as part of a microtask. We don't create the unobservable
|
||||
// promise.
|
||||
|
||||
class DynamicImportMicroTask : public mozilla::MicroTaskRunnable {
|
||||
public:
|
||||
explicit DynamicImportMicroTask(ModuleLoadRequest* aRequest)
|
||||
: MicroTaskRunnable(), mRequest(aRequest) {}
|
||||
|
||||
virtual void Run(mozilla::AutoSlowOperation& aAso) override {
|
||||
mRequest->mLoader->InstantiateAndEvaluateDynamicImport(mRequest);
|
||||
mRequest = nullptr;
|
||||
}
|
||||
|
||||
virtual bool Suppressed() override {
|
||||
return mRequest->mLoader->mGlobalObject->IsInSyncOperation();
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<ModuleLoadRequest> mRequest;
|
||||
};
|
||||
|
||||
MOZ_ASSERT(aRequest->mLoader == this);
|
||||
|
||||
if (!aRequest->mModuleScript) {
|
||||
FinishDynamicImportAndReject(aRequest, NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
|
||||
RefPtr<DynamicImportMicroTask> runnable =
|
||||
new DynamicImportMicroTask(aRequest);
|
||||
context->DispatchToMicroTask(do_AddRef(runnable));
|
||||
InstantiateAndEvaluateDynamicImport(aRequest);
|
||||
}
|
||||
|
||||
void ModuleLoaderBase::InstantiateAndEvaluateDynamicImport(
|
||||
|
||||
Reference in New Issue
Block a user