mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-29 16:58:28 +00:00
Issue #618 - Remove eager instantiation
This backs out the stuff added in Bug 1295978. Ref: BZ 1295978, 1388728
This commit is contained in:
@@ -315,6 +315,7 @@ nsJSUtils::ModuleInstantiate(JSContext* aCx, JS::Handle<JSObject*> aModule)
|
|||||||
|
|
||||||
MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext());
|
MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext());
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
MOZ_ASSERT(nsContentUtils::IsInMicroTask());
|
||||||
|
|
||||||
NS_ENSURE_TRUE(xpc::Scriptability::Get(aModule).Allowed(), NS_OK);
|
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
|
// The module and all of its dependencies have been successfully fetched and
|
||||||
// compiled.
|
// compiled.
|
||||||
|
|
||||||
if (!mLoader->InstantiateModuleTree(this)) {
|
|
||||||
LoadFailed();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetReady();
|
SetReady();
|
||||||
mLoader->ProcessLoadedModuleTree(this);
|
mLoader->ProcessLoadedModuleTree(this);
|
||||||
mLoader = nullptr;
|
mLoader = nullptr;
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ModuleScript)
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ModuleScript)
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mModuleRecord)
|
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_COLLECTION_TRACE_END
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(ModuleScript)
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(ModuleScript)
|
||||||
@@ -44,13 +43,11 @@ ModuleScript::ModuleScript(ScriptLoader *aLoader, nsIURI* aBaseURL,
|
|||||||
JS::Handle<JSObject*> aModuleRecord)
|
JS::Handle<JSObject*> aModuleRecord)
|
||||||
: mLoader(aLoader),
|
: mLoader(aLoader),
|
||||||
mBaseURL(aBaseURL),
|
mBaseURL(aBaseURL),
|
||||||
mModuleRecord(aModuleRecord),
|
mModuleRecord(aModuleRecord)
|
||||||
mInstantiationState(Uninstantiated)
|
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mLoader);
|
MOZ_ASSERT(mLoader);
|
||||||
MOZ_ASSERT(mBaseURL);
|
MOZ_ASSERT(mBaseURL);
|
||||||
MOZ_ASSERT(mModuleRecord);
|
MOZ_ASSERT(mModuleRecord);
|
||||||
MOZ_ASSERT(mException.isUndefined());
|
|
||||||
|
|
||||||
// Make module's host defined field point to this module script object.
|
// Make module's host defined field point to this module script object.
|
||||||
// This is cleared in the UnlinkModuleRecord().
|
// This is cleared in the UnlinkModuleRecord().
|
||||||
@@ -68,7 +65,6 @@ ModuleScript::UnlinkModuleRecord()
|
|||||||
JS::SetModuleHostDefinedField(mModuleRecord, JS::UndefinedValue());
|
JS::SetModuleHostDefinedField(mModuleRecord, JS::UndefinedValue());
|
||||||
}
|
}
|
||||||
mModuleRecord = nullptr;
|
mModuleRecord = nullptr;
|
||||||
mException.setUndefined();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleScript::~ModuleScript()
|
ModuleScript::~ModuleScript()
|
||||||
@@ -80,21 +76,5 @@ ModuleScript::~ModuleScript()
|
|||||||
DropJSObjects(this);
|
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
|
} // dom namespace
|
||||||
} // mozilla namespace
|
} // mozilla namespace
|
||||||
|
|||||||
@@ -20,17 +20,9 @@ class ScriptLoader;
|
|||||||
|
|
||||||
class ModuleScript final : public nsISupports
|
class ModuleScript final : public nsISupports
|
||||||
{
|
{
|
||||||
enum InstantiationState {
|
|
||||||
Uninstantiated,
|
|
||||||
Instantiated,
|
|
||||||
Errored
|
|
||||||
};
|
|
||||||
|
|
||||||
RefPtr<ScriptLoader> mLoader;
|
RefPtr<ScriptLoader> mLoader;
|
||||||
nsCOMPtr<nsIURI> mBaseURL;
|
nsCOMPtr<nsIURI> mBaseURL;
|
||||||
JS::Heap<JSObject*> mModuleRecord;
|
JS::Heap<JSObject*> mModuleRecord;
|
||||||
JS::Heap<JS::Value> mException;
|
|
||||||
InstantiationState mInstantiationState;
|
|
||||||
|
|
||||||
~ModuleScript();
|
~ModuleScript();
|
||||||
|
|
||||||
@@ -44,20 +36,8 @@ public:
|
|||||||
|
|
||||||
ScriptLoader* Loader() const { return mLoader; }
|
ScriptLoader* Loader() const { return mLoader; }
|
||||||
JSObject* ModuleRecord() const { return mModuleRecord; }
|
JSObject* ModuleRecord() const { return mModuleRecord; }
|
||||||
JS::Value Exception() const { return mException; }
|
|
||||||
nsIURI* BaseURL() const { return mBaseURL; }
|
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();
|
void UnlinkModuleRecord();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -726,11 +726,6 @@ ScriptLoader::StartFetchingModuleDependencies(ModuleLoadRequest* aRequest)
|
|||||||
MOZ_ASSERT(aRequest->mModuleScript);
|
MOZ_ASSERT(aRequest->mModuleScript);
|
||||||
MOZ_ASSERT(!aRequest->IsReadyToRun());
|
MOZ_ASSERT(!aRequest->IsReadyToRun());
|
||||||
|
|
||||||
if (aRequest->mModuleScript->InstantiationFailed()) {
|
|
||||||
aRequest->LoadFailed();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
aRequest->mProgress = ModuleLoadRequest::Progress::FetchingImports;
|
aRequest->mProgress = ModuleLoadRequest::Progress::FetchingImports;
|
||||||
|
|
||||||
nsCOMArray<nsIURI> urls;
|
nsCOMArray<nsIURI> urls;
|
||||||
@@ -825,12 +820,6 @@ HostResolveImportedModule(JSContext* aCx, unsigned argc, JS::Value* vp)
|
|||||||
return HandleModuleNotFound(aCx, script, string);
|
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());
|
*vp = JS::ObjectValue(*ms->ModuleRecord());
|
||||||
return true;
|
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
|
nsresult
|
||||||
ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType,
|
ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType,
|
||||||
bool aScriptFromHead)
|
bool aScriptFromHead)
|
||||||
@@ -1941,18 +1868,17 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (aRequest->IsModuleRequest()) {
|
if (aRequest->IsModuleRequest()) {
|
||||||
|
rv = EnsureModuleResolveHook(aes.cx());
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
ModuleLoadRequest* request = aRequest->AsModuleRequest();
|
ModuleLoadRequest* request = aRequest->AsModuleRequest();
|
||||||
MOZ_ASSERT(request->mModuleScript);
|
MOZ_ASSERT(request->mModuleScript);
|
||||||
MOZ_ASSERT(!request->mOffThreadToken);
|
MOZ_ASSERT(!request->mOffThreadToken);
|
||||||
ModuleScript* ms = request->mModuleScript;
|
JS::Rooted<JSObject*> module(aes.cx(),
|
||||||
MOZ_ASSERT(!ms->IsUninstantiated());
|
request->mModuleScript->ModuleRecord());
|
||||||
if (ms->InstantiationFailed()) {
|
MOZ_ASSERT(module);
|
||||||
JS::Rooted<JS::Value> exception(aes.cx(), ms->Exception());
|
rv = nsJSUtils::ModuleInstantiate(aes.cx(), module);
|
||||||
JS_SetPendingException(aes.cx(), exception);
|
if (NS_SUCCEEDED(rv)) {
|
||||||
rv = NS_ERROR_FAILURE;
|
|
||||||
} else {
|
|
||||||
JS::Rooted<JSObject*> module(aes.cx(), ms->ModuleRecord());
|
|
||||||
MOZ_ASSERT(module);
|
|
||||||
rv = nsJSUtils::ModuleEvaluate(aes.cx(), module);
|
rv = nsJSUtils::ModuleEvaluate(aes.cx(), module);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -581,7 +581,6 @@ private:
|
|||||||
nsresult CreateModuleScript(ModuleLoadRequest* aRequest);
|
nsresult CreateModuleScript(ModuleLoadRequest* aRequest);
|
||||||
nsresult ProcessFetchedModuleSource(ModuleLoadRequest* aRequest);
|
nsresult ProcessFetchedModuleSource(ModuleLoadRequest* aRequest);
|
||||||
void ProcessLoadedModuleTree(ModuleLoadRequest* aRequest);
|
void ProcessLoadedModuleTree(ModuleLoadRequest* aRequest);
|
||||||
bool InstantiateModuleTree(ModuleLoadRequest* aRequest);
|
|
||||||
void StartFetchingModuleDependencies(ModuleLoadRequest* aRequest);
|
void StartFetchingModuleDependencies(ModuleLoadRequest* aRequest);
|
||||||
|
|
||||||
RefPtr<mozilla::GenericPromise>
|
RefPtr<mozilla::GenericPromise>
|
||||||
|
|||||||
Reference in New Issue
Block a user