Bug 1766276 - Give MaybeOneOf a map method r=jandem

There are a few places where we call one of two overloads of a fuction based on
the contents of a MaybeOneOf. We can simplify this code by giving the class a
map method.

Differential Revision: https://phabricator.services.mozilla.com/D144595
This commit is contained in:
Jon Coppeard
2022-04-26 12:29:24 +00:00
parent 17408bc611
commit 3037c5c55b
4 changed files with 50 additions and 31 deletions

View File

@@ -187,11 +187,10 @@ nsresult ModuleLoader::CompileOrFinishModuleScript(
nsresult rv = aRequest->GetScriptSource(aCx, &maybeSource);
NS_ENSURE_SUCCESS(rv, rv);
stencil = maybeSource.constructed<SourceText<char16_t>>()
? JS::CompileModuleScriptToStencil(
aCx, aOptions, maybeSource.ref<SourceText<char16_t>>())
: JS::CompileModuleScriptToStencil(
aCx, aOptions, maybeSource.ref<SourceText<Utf8Unit>>());
auto compile = [&](auto& source) {
return JS::CompileModuleScriptToStencil(aCx, aOptions, source);
};
stencil = maybeSource.mapNonEmpty(compile);
} else {
MOZ_ASSERT(aRequest->IsBytecode());
JS::DecodeOptions decodeOptions(aOptions);