mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
Issue #618 - Remove eager instantiation
This backs out the stuff added in Bug 1295978. Ref: BZ 1295978, 1388728
This commit is contained in:
parent
b590ecea12
commit
a754a7be26
6 changed files with 10 additions and 129 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue