summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-07-04 10:35:22 +0000
committerMoonchild <moonchild@palemoon.org>2020-07-04 10:35:22 +0000
commit046534432d2914c80bcab36797fe0a43ff332a98 (patch)
treecf63937edf28a18db3a8d88418f2bf5f1823cec2
parent121935caed68654adc14a85482a53bc9ac196da8 (diff)
downloadUXP-046534432d2914c80bcab36797fe0a43ff332a98.tar
UXP-046534432d2914c80bcab36797fe0a43ff332a98.tar.gz
UXP-046534432d2914c80bcab36797fe0a43ff332a98.tar.lz
UXP-046534432d2914c80bcab36797fe0a43ff332a98.tar.xz
UXP-046534432d2914c80bcab36797fe0a43ff332a98.zip
Issue #618 - Remove eager instantiation
This backs out the stuff added in Bug 1295978. Ref: BZ 1295978, 1388728
-rw-r--r--dom/base/nsJSUtils.cpp1
-rw-r--r--dom/script/ModuleLoadRequest.cpp5
-rw-r--r--dom/script/ModuleScript.cpp22
-rw-r--r--dom/script/ModuleScript.h20
-rw-r--r--dom/script/ScriptLoader.cpp90
-rw-r--r--dom/script/ScriptLoader.h1
6 files changed, 10 insertions, 129 deletions
diff --git a/dom/base/nsJSUtils.cpp b/dom/base/nsJSUtils.cpp
index c294cfdba..65965d74b 100644
--- a/dom/base/nsJSUtils.cpp
+++ b/dom/base/nsJSUtils.cpp
@@ -315,6 +315,7 @@ nsJSUtils::ModuleInstantiate(JSContext* aCx, JS::Handle<JSObject*> aModule)
MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext());
MOZ_ASSERT(NS_IsMainThread());
+ MOZ_ASSERT(nsContentUtils::IsInMicroTask());
NS_ENSURE_TRUE(xpc::Scriptability::Get(aModule).Allowed(), NS_OK);
diff --git a/dom/script/ModuleLoadRequest.cpp b/dom/script/ModuleLoadRequest.cpp
index 98106df1b..8871dcdab 100644
--- a/dom/script/ModuleLoadRequest.cpp
+++ b/dom/script/ModuleLoadRequest.cpp
@@ -86,11 +86,6 @@ ModuleLoadRequest::DependenciesLoaded()
// The module and all of its dependencies have been successfully fetched and
// compiled.
- if (!mLoader->InstantiateModuleTree(this)) {
- LoadFailed();
- return;
- }
-
SetReady();
mLoader->ProcessLoadedModuleTree(this);
mLoader = nullptr;
diff --git a/dom/script/ModuleScript.cpp b/dom/script/ModuleScript.cpp
index 34ef4dec4..bf02f522d 100644
--- a/dom/script/ModuleScript.cpp
+++ b/dom/script/ModuleScript.cpp
@@ -34,7 +34,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ModuleScript)
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mModuleRecord)
- NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mException)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(ModuleScript)
@@ -44,13 +43,11 @@ ModuleScript::ModuleScript(ScriptLoader *aLoader, nsIURI* aBaseURL,
JS::Handle<JSObject*> aModuleRecord)
: mLoader(aLoader),
mBaseURL(aBaseURL),
- mModuleRecord(aModuleRecord),
- mInstantiationState(Uninstantiated)
+ mModuleRecord(aModuleRecord)
{
MOZ_ASSERT(mLoader);
MOZ_ASSERT(mBaseURL);
MOZ_ASSERT(mModuleRecord);
- MOZ_ASSERT(mException.isUndefined());
// Make module's host defined field point to this module script object.
// This is cleared in the UnlinkModuleRecord().
@@ -68,7 +65,6 @@ ModuleScript::UnlinkModuleRecord()
JS::SetModuleHostDefinedField(mModuleRecord, JS::UndefinedValue());
}
mModuleRecord = nullptr;
- mException.setUndefined();
}
ModuleScript::~ModuleScript()
@@ -80,21 +76,5 @@ ModuleScript::~ModuleScript()
DropJSObjects(this);
}
-void
-ModuleScript::SetInstantiationResult(JS::Handle<JS::Value> aMaybeException)
-{
- MOZ_ASSERT(mInstantiationState == Uninstantiated);
- MOZ_ASSERT(mModuleRecord);
- MOZ_ASSERT(mException.isUndefined());
-
- if (aMaybeException.isUndefined()) {
- mInstantiationState = Instantiated;
- } else {
- mModuleRecord = nullptr;
- mException = aMaybeException;
- mInstantiationState = Errored;
- }
-}
-
} // dom namespace
} // mozilla namespace
diff --git a/dom/script/ModuleScript.h b/dom/script/ModuleScript.h
index dd0d07e84..97fdb8ed1 100644
--- a/dom/script/ModuleScript.h
+++ b/dom/script/ModuleScript.h
@@ -20,17 +20,9 @@ class ScriptLoader;
class ModuleScript final : public nsISupports
{
- enum InstantiationState {
- Uninstantiated,
- Instantiated,
- Errored
- };
-
RefPtr<ScriptLoader> mLoader;
nsCOMPtr<nsIURI> mBaseURL;
JS::Heap<JSObject*> mModuleRecord;
- JS::Heap<JS::Value> mException;
- InstantiationState mInstantiationState;
~ModuleScript();
@@ -44,20 +36,8 @@ public:
ScriptLoader* Loader() const { return mLoader; }
JSObject* ModuleRecord() const { return mModuleRecord; }
- JS::Value Exception() const { return mException; }
nsIURI* BaseURL() const { return mBaseURL; }
- void SetInstantiationResult(JS::Handle<JS::Value> aMaybeException);
- bool IsUninstantiated() const {
- return mInstantiationState == Uninstantiated;
- }
- bool IsInstantiated() const {
- return mInstantiationState == Instantiated;
- }
- bool InstantiationFailed() const {
- return mInstantiationState == Errored;
- }
-
void UnlinkModuleRecord();
};
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
index 736bb4349..cf7f06e71 100644
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -726,11 +726,6 @@ ScriptLoader::StartFetchingModuleDependencies(ModuleLoadRequest* aRequest)
MOZ_ASSERT(aRequest->mModuleScript);
MOZ_ASSERT(!aRequest->IsReadyToRun());
- if (aRequest->mModuleScript->InstantiationFailed()) {
- aRequest->LoadFailed();
- return;
- }
-
aRequest->mProgress = ModuleLoadRequest::Progress::FetchingImports;
nsCOMArray<nsIURI> urls;
@@ -825,12 +820,6 @@ HostResolveImportedModule(JSContext* aCx, unsigned argc, JS::Value* vp)
return HandleModuleNotFound(aCx, script, string);
}
- if (ms->InstantiationFailed()) {
- JS::Rooted<JS::Value> exception(aCx, ms->Exception());
- JS_SetPendingException(aCx, exception);
- return false;
- }
-
*vp = JS::ObjectValue(*ms->ModuleRecord());
return true;
}
@@ -866,68 +855,6 @@ ScriptLoader::ProcessLoadedModuleTree(ModuleLoadRequest* aRequest)
}
}
-bool
-ScriptLoader::InstantiateModuleTree(ModuleLoadRequest* aRequest)
-{
- // Perform eager instantiation of the loaded module tree.
-
- MOZ_ASSERT(aRequest);
-
- ModuleScript* ms = aRequest->mModuleScript;
- MOZ_ASSERT(ms);
- if (!ms || !ms->ModuleRecord()) {
- return false;
- }
-
- AutoJSAPI jsapi;
- if (NS_WARN_IF(!jsapi.Init(ms->ModuleRecord()))) {
- return false;
- }
-
- nsresult rv = EnsureModuleResolveHook(jsapi.cx());
- NS_ENSURE_SUCCESS(rv, false);
-
- JS::Rooted<JSObject*> module(jsapi.cx(), ms->ModuleRecord());
- bool ok = NS_SUCCEEDED(nsJSUtils::ModuleInstantiate(jsapi.cx(), module));
-
- JS::RootedValue exception(jsapi.cx());
- if (!ok) {
- MOZ_ASSERT(jsapi.HasException());
- if (!jsapi.StealException(&exception)) {
- return false;
- }
- MOZ_ASSERT(!exception.isUndefined());
- }
-
- // Mark this module and any uninstantiated dependencies found via depth-first
- // search as instantiated and record any error.
-
- mozilla::Vector<ModuleLoadRequest*, 1> requests;
- if (!requests.append(aRequest)) {
- return false;
- }
-
- while (!requests.empty()) {
- ModuleLoadRequest* request = requests.popCopy();
- ModuleScript* ms = request->mModuleScript;
- if (!ms->IsUninstantiated()) {
- continue;
- }
-
- ms->SetInstantiationResult(exception);
-
- for (auto import : request->mImports) {
- if (import->mModuleScript->IsUninstantiated() &&
- !requests.append(import))
- {
- return false;
- }
- }
- }
-
- return true;
-}
-
nsresult
ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType,
bool aScriptFromHead)
@@ -1941,18 +1868,17 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
}
if (aRequest->IsModuleRequest()) {
+ rv = EnsureModuleResolveHook(aes.cx());
+ NS_ENSURE_SUCCESS(rv, rv);
+
ModuleLoadRequest* request = aRequest->AsModuleRequest();
MOZ_ASSERT(request->mModuleScript);
MOZ_ASSERT(!request->mOffThreadToken);
- ModuleScript* ms = request->mModuleScript;
- MOZ_ASSERT(!ms->IsUninstantiated());
- if (ms->InstantiationFailed()) {
- JS::Rooted<JS::Value> exception(aes.cx(), ms->Exception());
- JS_SetPendingException(aes.cx(), exception);
- rv = NS_ERROR_FAILURE;
- } else {
- JS::Rooted<JSObject*> module(aes.cx(), ms->ModuleRecord());
- MOZ_ASSERT(module);
+ JS::Rooted<JSObject*> module(aes.cx(),
+ request->mModuleScript->ModuleRecord());
+ MOZ_ASSERT(module);
+ rv = nsJSUtils::ModuleInstantiate(aes.cx(), module);
+ if (NS_SUCCEEDED(rv)) {
rv = nsJSUtils::ModuleEvaluate(aes.cx(), module);
}
} else {
diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h
index 3c428deea..32401d1b6 100644
--- a/dom/script/ScriptLoader.h
+++ b/dom/script/ScriptLoader.h
@@ -581,7 +581,6 @@ private:
nsresult CreateModuleScript(ModuleLoadRequest* aRequest);
nsresult ProcessFetchedModuleSource(ModuleLoadRequest* aRequest);
void ProcessLoadedModuleTree(ModuleLoadRequest* aRequest);
- bool InstantiateModuleTree(ModuleLoadRequest* aRequest);
void StartFetchingModuleDependencies(ModuleLoadRequest* aRequest);
RefPtr<mozilla::GenericPromise>