Bug 1530745 - Part 5: Move duplicate code for standalone function compilation into a separate function. r=arai

Depends on D22669

Differential Revision: https://phabricator.services.mozilla.com/D22670

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2019-03-08 12:38:43 +00:00
Родитель cc2d6c1784
Коммит fdc89b3f4a
1 изменённых файлов: 28 добавлений и 65 удалений

Просмотреть файл

@ -1087,11 +1087,13 @@ bool frontend::CompileLazyBinASTFunction(JSContext* cx,
#endif // JS_BUILD_BINAST
bool frontend::CompileStandaloneFunction(
JSContext* cx, MutableHandleFunction fun,
const JS::ReadOnlyCompileOptions& options, JS::SourceText<char16_t>& srcBuf,
const Maybe<uint32_t>& parameterListEnd,
HandleScope enclosingScope /* = nullptr */) {
static bool CompileStandaloneFunction(JSContext* cx, MutableHandleFunction fun,
const JS::ReadOnlyCompileOptions& options,
JS::SourceText<char16_t>& srcBuf,
const Maybe<uint32_t>& parameterListEnd,
GeneratorKind generatorKind,
FunctionAsyncKind asyncKind,
HandleScope enclosingScope = nullptr) {
AutoAssertReportedException assertException(cx);
StandaloneFunctionInfo info(cx, options);
@ -1106,9 +1108,8 @@ bool frontend::CompileStandaloneFunction(
scope = &cx->global()->emptyGlobalScope();
}
FunctionNode* parsedFunction =
compiler.parse(info, fun, scope, GeneratorKind::NotGenerator,
FunctionAsyncKind::SyncFunction, parameterListEnd);
FunctionNode* parsedFunction = compiler.parse(info, fun, scope, generatorKind,
asyncKind, parameterListEnd);
if (!parsedFunction || !compiler.compile(fun, info, parsedFunction)) {
return false;
}
@ -1117,77 +1118,39 @@ bool frontend::CompileStandaloneFunction(
return true;
}
bool frontend::CompileStandaloneFunction(
JSContext* cx, MutableHandleFunction fun,
const JS::ReadOnlyCompileOptions& options, JS::SourceText<char16_t>& srcBuf,
const Maybe<uint32_t>& parameterListEnd,
HandleScope enclosingScope /* = nullptr */) {
return CompileStandaloneFunction(
cx, fun, options, srcBuf, parameterListEnd, GeneratorKind::NotGenerator,
FunctionAsyncKind::SyncFunction, enclosingScope);
}
bool frontend::CompileStandaloneGenerator(
JSContext* cx, MutableHandleFunction fun,
const JS::ReadOnlyCompileOptions& options, JS::SourceText<char16_t>& srcBuf,
const Maybe<uint32_t>& parameterListEnd) {
AutoAssertReportedException assertException(cx);
StandaloneFunctionInfo info(cx, options);
StandaloneFunctionCompiler<char16_t> compiler(srcBuf);
if (!compiler.prepare(info, parameterListEnd)) {
return false;
}
RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
FunctionNode* parsedFunction =
compiler.parse(info, fun, emptyGlobalScope, GeneratorKind::Generator,
FunctionAsyncKind::SyncFunction, parameterListEnd);
if (!parsedFunction || !compiler.compile(fun, info, parsedFunction)) {
return false;
}
assertException.reset();
return true;
return CompileStandaloneFunction(cx, fun, options, srcBuf, parameterListEnd,
GeneratorKind::Generator,
FunctionAsyncKind::SyncFunction);
}
bool frontend::CompileStandaloneAsyncFunction(
JSContext* cx, MutableHandleFunction fun,
const ReadOnlyCompileOptions& options, JS::SourceText<char16_t>& srcBuf,
const Maybe<uint32_t>& parameterListEnd) {
AutoAssertReportedException assertException(cx);
StandaloneFunctionInfo info(cx, options);
StandaloneFunctionCompiler<char16_t> compiler(srcBuf);
if (!compiler.prepare(info, parameterListEnd)) {
return false;
}
RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
FunctionNode* parsedFunction =
compiler.parse(info, fun, emptyGlobalScope, GeneratorKind::NotGenerator,
FunctionAsyncKind::AsyncFunction, parameterListEnd);
if (!parsedFunction || !compiler.compile(fun, info, parsedFunction)) {
return false;
}
assertException.reset();
return true;
return CompileStandaloneFunction(cx, fun, options, srcBuf, parameterListEnd,
GeneratorKind::NotGenerator,
FunctionAsyncKind::AsyncFunction);
}
bool frontend::CompileStandaloneAsyncGenerator(
JSContext* cx, MutableHandleFunction fun,
const ReadOnlyCompileOptions& options, JS::SourceText<char16_t>& srcBuf,
const Maybe<uint32_t>& parameterListEnd) {
AutoAssertReportedException assertException(cx);
StandaloneFunctionInfo info(cx, options);
StandaloneFunctionCompiler<char16_t> compiler(srcBuf);
if (!compiler.prepare(info, parameterListEnd)) {
return false;
}
RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
FunctionNode* parsedFunction =
compiler.parse(info, fun, emptyGlobalScope, GeneratorKind::Generator,
FunctionAsyncKind::AsyncFunction, parameterListEnd);
if (!parsedFunction || !compiler.compile(fun, info, parsedFunction)) {
return false;
}
assertException.reset();
return true;
return CompileStandaloneFunction(cx, fun, options, srcBuf, parameterListEnd,
GeneratorKind::Generator,
FunctionAsyncKind::AsyncFunction);
}