Skip to content

Commit aa0e96e

Browse files
committed
Bug 1820594 - Part 24: Add ModuleErroredRunnable to dispatch ModuleErrored. r=jonco
When there's a ParseError, the error should be dispatched asynchronously. However, workers can't handle the micro task, therefore we still call ModuleErrored synchronously. WPT test: /html/semantics/scripting-1/the-script-element/module/inline-async-inserted-execorder.html Differential Revision: https://phabricator.services.mozilla.com/D255128
1 parent 8054f6d commit aa0e96e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

js/loader/ModuleLoaderBase.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
#include "nsNetUtil.h" // NS_NewURI
3535
#include "xpcpublic.h"
3636

37+
using mozilla::AutoSlowOperation;
3738
using mozilla::CycleCollectedJSContext;
3839
using mozilla::Err;
40+
using mozilla::MicroTaskRunnable;
3941
using mozilla::Preferences;
4042
using mozilla::UniquePtr;
4143
using mozilla::WrapNotNull;
@@ -885,6 +887,30 @@ void ModuleLoaderBase::OnFetchFailed(ModuleLoadRequest* aRequest) {
885887
}
886888
}
887889

890+
class ModuleErroredRunnable : public MicroTaskRunnable {
891+
public:
892+
explicit ModuleErroredRunnable(ModuleLoadRequest* aRequest)
893+
: mRequest(aRequest) {}
894+
895+
virtual void Run(AutoSlowOperation& aAso) override {
896+
mRequest->ModuleErrored();
897+
}
898+
899+
private:
900+
RefPtr<ModuleLoadRequest> mRequest;
901+
};
902+
903+
void ModuleLoaderBase::DispatchModuleErrored(ModuleLoadRequest* aRequest) {
904+
if (aRequest->HasScriptLoadContext()) {
905+
CycleCollectedJSContext* context = CycleCollectedJSContext::Get();
906+
RefPtr<ModuleErroredRunnable> runnable =
907+
new ModuleErroredRunnable(aRequest);
908+
context->DispatchToMicroTask(runnable.forget());
909+
} else {
910+
aRequest->ModuleErrored();
911+
}
912+
}
913+
888914
nsresult ModuleLoaderBase::CreateModuleScript(ModuleLoadRequest* aRequest) {
889915
MOZ_ASSERT(!aRequest->mModuleScript);
890916
MOZ_ASSERT(aRequest->mBaseURL);
@@ -975,7 +1001,7 @@ nsresult ModuleLoaderBase::CreateModuleScript(ModuleLoadRequest* aRequest) {
9751001
}
9761002

9771003
moduleScript->SetParseError(error);
978-
aRequest->ModuleErrored();
1004+
DispatchModuleErrored(aRequest);
9791005
return NS_OK;
9801006
}
9811007

@@ -991,7 +1017,7 @@ nsresult ModuleLoaderBase::CreateModuleScript(ModuleLoadRequest* aRequest) {
9911017
aRequest->mModuleScript = nullptr;
9921018
return rv;
9931019
}
994-
aRequest->ModuleErrored();
1020+
DispatchModuleErrored(aRequest);
9951021
return NS_OK;
9961022
}
9971023
}

js/loader/ModuleLoaderBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ class ModuleLoaderBase : public nsISupports {
563563
void RemoveDynamicImport(ModuleLoadRequest* aRequest);
564564

565565
nsresult CreateModuleScript(ModuleLoadRequest* aRequest);
566+
void DispatchModuleErrored(ModuleLoadRequest* aRequest);
566567

567568
bool IsFetchingAndHasWaitingRequest(ModuleLoadRequest* aRequest);
568569

0 commit comments

Comments
 (0)