mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 19:37:15 +00:00
Bug 1436400 - Part 2: Simplify ModuleLoader::CompileOrFinishModuleScript code flow. r=jonco
As a preparation to add bytecode case to CompileOrFinishModuleScript, removed the shared nsresult variable and make each branch directly return, and also do early return for error case. Differential Revision: https://phabricator.services.mozilla.com/D140290
This commit is contained in:
parent
d02a32e588
commit
518074add7
@ -439,34 +439,39 @@ void ModuleLoader::ProcessLoadedModuleTree(ModuleLoadRequest* aRequest) {
|
||||
nsresult ModuleLoader::CompileOrFinishModuleScript(
|
||||
JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::CompileOptions& aOptions,
|
||||
ModuleLoadRequest* aRequest, JS::MutableHandle<JSObject*> aModule) {
|
||||
nsresult rv;
|
||||
if (aRequest->GetLoadContext()->mWasCompiledOMT) {
|
||||
JS::Rooted<JS::InstantiationStorage> storage(aCx);
|
||||
|
||||
RefPtr<JS::Stencil> stencil = JS::FinishCompileModuleToStencilOffThread(
|
||||
aCx, aRequest->GetLoadContext()->mOffThreadToken, storage.address());
|
||||
if (stencil) {
|
||||
JS::InstantiateOptions instantiateOptions(aOptions);
|
||||
aModule.set(JS::InstantiateModuleStencil(aCx, instantiateOptions, stencil,
|
||||
storage.address()));
|
||||
}
|
||||
|
||||
aRequest->GetLoadContext()->mOffThreadToken = nullptr;
|
||||
rv = aModule ? NS_OK : NS_ERROR_FAILURE;
|
||||
} else {
|
||||
MaybeSourceText maybeSource;
|
||||
rv = aRequest->GetScriptSource(aCx, &maybeSource);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = maybeSource.constructed<SourceText<char16_t>>()
|
||||
? nsJSUtils::CompileModule(
|
||||
aCx, maybeSource.ref<SourceText<char16_t>>(), aGlobal,
|
||||
aOptions, aModule)
|
||||
: nsJSUtils::CompileModule(
|
||||
aCx, maybeSource.ref<SourceText<Utf8Unit>>(), aGlobal,
|
||||
aOptions, aModule);
|
||||
|
||||
if (!stencil) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JS::InstantiateOptions instantiateOptions(aOptions);
|
||||
aModule.set(JS::InstantiateModuleStencil(aCx, instantiateOptions, stencil,
|
||||
storage.address()));
|
||||
if (!aModule) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
return rv;
|
||||
|
||||
MaybeSourceText maybeSource;
|
||||
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return maybeSource.constructed<SourceText<char16_t>>()
|
||||
? nsJSUtils::CompileModule(aCx,
|
||||
maybeSource.ref<SourceText<char16_t>>(),
|
||||
aGlobal, aOptions, aModule)
|
||||
: nsJSUtils::CompileModule(aCx,
|
||||
maybeSource.ref<SourceText<Utf8Unit>>(),
|
||||
aGlobal, aOptions, aModule);
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
Loading…
x
Reference in New Issue
Block a user