Bug 1530745 - Part 5: Move duplicate code for standalone function compilation into a separate function. r=arai
authorAndré Bargull <andre.bargull@gmail.com>
Fri, 08 Mar 2019 12:38:43 +0000
changeset 521220 b499a1eec1b1
parent 521219 d6cab6cee202
child 521221 f6d4e1b012e6
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1530745
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
js/src/frontend/BytecodeCompiler.cpp
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -1082,112 +1082,75 @@ bool frontend::CompileLazyBinASTFunction
 
   delazificationCompletion.complete();
   assertException.reset();
   return script;
 }
 
 #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);
 
   StandaloneFunctionCompiler<char16_t> compiler(srcBuf);
   if (!compiler.prepare(info, parameterListEnd)) {
     return false;
   }
 
   RootedScope scope(cx, enclosingScope);
   if (!scope) {
     scope = &cx->global()->emptyGlobalScope();
   }
 
-  FunctionNode* parsedFunction =
-      compiler.parse(info, fun, scope, GeneratorKind::NotGenerator,
-                     FunctionAsyncKind::SyncFunction, parameterListEnd);
-  if (!parsedFunction || !compiler.compile(fun, info, parsedFunction)) {
-    return false;
-  }
-
-  assertException.reset();
-  return true;
-}
-
-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);
+  FunctionNode* parsedFunction = compiler.parse(info, fun, scope, generatorKind,
+                                                asyncKind, parameterListEnd);
   if (!parsedFunction || !compiler.compile(fun, info, parsedFunction)) {
     return false;
   }
 
   assertException.reset();
   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) {
+  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);
 }