Bug 1498320 - Move standalone function-compilation's createSourceAndParser call into a separate prepareStandaloneFunctionParse function, anticipating when that function will have to deal with multiple kinds of SourceBufferHolder. r=tcampbell
authorJeff Walden <jwalden@mit.edu>
Thu, 11 Oct 2018 13:54:42 -0700
changeset 445947 ac6aea751ee94e8cdff017c7955ee4e92da7c190
parent 445946 d9e71df3d1d7a6dbf8effeb426273cd901d7700b
child 445948 37b4694f5fcf00a528927af61f53aef699f994ee
push id109805
push userjwalden@mit.edu
push dateTue, 13 Nov 2018 01:51:46 +0000
treeherdermozilla-inbound@17243a560006 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1498320
milestone65.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 1498320 - Move standalone function-compilation's createSourceAndParser call into a separate prepareStandaloneFunctionParse function, anticipating when that function will have to deal with multiple kinds of SourceBufferHolder. r=tcampbell
js/src/frontend/BytecodeCompiler.cpp
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -59,16 +59,21 @@ class MOZ_STACK_CLASS BytecodeCompiler
 
     // Call this before calling compileModule.
     MOZ_MUST_USE bool prepareModuleParse() {
         return createSourceAndParser(ParseGoal::Module);
     }
 
     ModuleObject* compileModule();
 
+    // Call this before calling compileStandaloneFunction.
+    MOZ_MUST_USE bool prepareStandaloneFunctionParse(const Maybe<uint32_t>& parameterListEnd) {
+        return createSourceAndParser(ParseGoal::Script, parameterListEnd);
+    }
+
     bool compileStandaloneFunction(MutableHandleFunction fun, GeneratorKind generatorKind,
                                    FunctionAsyncKind asyncKind,
                                    const Maybe<uint32_t>& parameterListEnd);
 
     ScriptSourceObject* sourceObjectPtr() const;
 
   private:
     void assertSourceAndParserCreated() const {
@@ -494,19 +499,17 @@ bool
 BytecodeCompiler::compileStandaloneFunction(MutableHandleFunction fun,
                                             GeneratorKind generatorKind,
                                             FunctionAsyncKind asyncKind,
                                             const Maybe<uint32_t>& parameterListEnd)
 {
     MOZ_ASSERT(fun);
     MOZ_ASSERT(fun->isTenured());
 
-    if (!createSourceAndParser(ParseGoal::Script, parameterListEnd)) {
-        return false;
-    }
+    assertSourceAndParserCreated();
 
     TokenStreamPosition startPosition(keepAtoms, parser->tokenStream);
 
     // Speculatively parse using the default directives implied by the context.
     // If a directive is encountered (e.g., "use strict") that changes how the
     // function should have been parsed, we backup and reparse with the new set
     // of directives.
 
@@ -1033,17 +1036,18 @@ frontend::CompileStandaloneFunction(JSCo
     AutoAssertReportedException assertException(cx);
 
     RootedScope scope(cx, enclosingScope);
     if (!scope) {
         scope = &cx->global()->emptyGlobalScope();
     }
 
     BytecodeCompiler compiler(cx, options, srcBuf, scope);
-    if (!compiler.compileStandaloneFunction(fun, GeneratorKind::NotGenerator,
+    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd) ||
+        !compiler.compileStandaloneFunction(fun, GeneratorKind::NotGenerator,
                                             FunctionAsyncKind::SyncFunction,
                                             parameterListEnd))
     {
         return false;
     }
 
     assertException.reset();
     return true;
@@ -1055,17 +1059,18 @@ frontend::CompileStandaloneGenerator(JSC
                                      JS::SourceBufferHolder& srcBuf,
                                      const Maybe<uint32_t>& parameterListEnd)
 {
     AutoAssertReportedException assertException(cx);
 
     RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
 
     BytecodeCompiler compiler(cx, options, srcBuf, emptyGlobalScope);
-    if (!compiler.compileStandaloneFunction(fun, GeneratorKind::Generator,
+    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd) ||
+        !compiler.compileStandaloneFunction(fun, GeneratorKind::Generator,
                                             FunctionAsyncKind::SyncFunction,
                                             parameterListEnd))
     {
         return false;
     }
 
     assertException.reset();
     return true;
@@ -1077,17 +1082,18 @@ frontend::CompileStandaloneAsyncFunction
                                          JS::SourceBufferHolder& srcBuf,
                                          const Maybe<uint32_t>& parameterListEnd)
 {
     AutoAssertReportedException assertException(cx);
 
     RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
 
     BytecodeCompiler compiler(cx, options, srcBuf, emptyGlobalScope);
-    if (!compiler.compileStandaloneFunction(fun, GeneratorKind::NotGenerator,
+    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd) ||
+        !compiler.compileStandaloneFunction(fun, GeneratorKind::NotGenerator,
                                             FunctionAsyncKind::AsyncFunction,
                                             parameterListEnd))
     {
         return false;
     }
 
     assertException.reset();
     return true;
@@ -1099,17 +1105,18 @@ frontend::CompileStandaloneAsyncGenerato
                                           JS::SourceBufferHolder& srcBuf,
                                           const Maybe<uint32_t>& parameterListEnd)
 {
     AutoAssertReportedException assertException(cx);
 
     RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope());
 
     BytecodeCompiler compiler(cx, options, srcBuf, emptyGlobalScope);
-    if (!compiler.compileStandaloneFunction(fun, GeneratorKind::Generator,
+    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd) ||
+        !compiler.compileStandaloneFunction(fun, GeneratorKind::Generator,
                                             FunctionAsyncKind::AsyncFunction,
                                             parameterListEnd))
     {
         return false;
     }
 
     assertException.reset();
     return true;