Bug 1498320 - Split BytecodeCompiler::compileStandaloneFunction into BytecodeCompiler::{parse,compile}StandaloneFunction. r=tcampbell
authorJeff Walden <jwalden@mit.edu>
Thu, 11 Oct 2018 13:54:42 -0700
changeset 445951 1737079f61dd46af29ab735da95acf814274caa8
parent 445950 2792e47984ee1fa13fe2442864cab100a4b425b3
child 445952 49b72ccc968279c7264d47b8e9b609c25ece0650
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 - Split BytecodeCompiler::compileStandaloneFunction into BytecodeCompiler::{parse,compile}StandaloneFunction. r=tcampbell
js/src/frontend/BytecodeCompiler.cpp
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -59,24 +59,27 @@ class MOZ_STACK_CLASS BytecodeCompiler
 
     // Call this before calling compileModule.
     MOZ_MUST_USE bool prepareModuleParse() {
         return createSourceAndParser(ParseGoal::Module) && createCompleteScript();
     }
 
     ModuleObject* compileModule();
 
-    // Call this before calling compileStandaloneFunction.
+    // Call this before calling parseStandaloneFunction.
     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);
+    // Call this before calling compileStandaloneFunction.
+    CodeNode* parseStandaloneFunction(MutableHandleFunction fun, GeneratorKind generatorKind,
+                                      FunctionAsyncKind asyncKind,
+                                      const Maybe<uint32_t>& parameterListEnd);
+
+    bool compileStandaloneFunction(CodeNode* parsedFunction, MutableHandleFunction fun);
 
     ScriptSourceObject* sourceObjectPtr() const;
 
   private:
     void assertSourceAndParserCreated() const {
         MOZ_ASSERT(sourceObject != nullptr);
         MOZ_ASSERT(scriptSource != nullptr);
         MOZ_ASSERT(usedNames.isSome());
@@ -487,24 +490,24 @@ BytecodeCompiler::compileModule()
     if (!scriptSource->tryCompressOffThread(cx)) {
         return nullptr;
     }
 
     MOZ_ASSERT_IF(!cx->helperThread(), !cx->isExceptionPending());
     return module;
 }
 
-// Compile a standalone JS function, which might appear as the value of an
+// Parse a standalone JS function, which might appear as the value of an
 // event handler attribute in an HTML <INPUT> tag, or in a Function()
 // constructor.
-bool
-BytecodeCompiler::compileStandaloneFunction(MutableHandleFunction fun,
-                                            GeneratorKind generatorKind,
-                                            FunctionAsyncKind asyncKind,
-                                            const Maybe<uint32_t>& parameterListEnd)
+CodeNode*
+BytecodeCompiler::parseStandaloneFunction(MutableHandleFunction fun,
+                                          GeneratorKind generatorKind,
+                                          FunctionAsyncKind asyncKind,
+                                          const Maybe<uint32_t>& parameterListEnd)
 {
     MOZ_ASSERT(fun);
     MOZ_ASSERT(fun->isTenured());
 
     assertSourceAndParserCreated();
 
     TokenStreamPosition startPosition(keepAtoms, parser->tokenStream);
 
@@ -514,48 +517,49 @@ BytecodeCompiler::compileStandaloneFunct
     // of directives.
 
     ParseNode* fn;
     do {
         Directives newDirectives = directives;
         fn = parser->standaloneFunction(fun, enclosingScope, parameterListEnd, generatorKind,
                                         asyncKind, directives, &newDirectives);
         if (!fn && !handleParseFailure(newDirectives, startPosition)) {
-            return false;
+            return nullptr;
         }
     } while (!fn);
 
-    FunctionBox* funbox = fn->as<CodeNode>().funbox();
+    return &fn->as<CodeNode>();
+}
+
+// Compile a standalone JS function.
+bool
+BytecodeCompiler::compileStandaloneFunction(CodeNode* parsedFunction, MutableHandleFunction fun)
+{
+    FunctionBox* funbox = parsedFunction->funbox();
     if (funbox->function()->isInterpreted()) {
         MOZ_ASSERT(fun == funbox->function());
 
         if (!createScript(funbox->toStringStart, funbox->toStringEnd)) {
             return false;
         }
 
         Maybe<BytecodeEmitter> emitter;
         if (!emplaceEmitter(emitter, funbox)) {
             return false;
         }
-        if (!emitter->emitFunctionScript(&fn->as<CodeNode>(),
-                                         BytecodeEmitter::TopLevelFunction::Yes))
-        {
+        if (!emitter->emitFunctionScript(parsedFunction, BytecodeEmitter::TopLevelFunction::Yes)) {
             return false;
         }
     } else {
         fun.set(funbox->function());
         MOZ_ASSERT(IsAsmJSModule(fun));
     }
 
     // Enqueue an off-thread source compression task after finishing parsing.
-    if (!scriptSource->tryCompressOffThread(cx)) {
-        return false;
-    }
-
-    return true;
+    return scriptSource->tryCompressOffThread(cx);
 }
 
 ScriptSourceObject*
 BytecodeCompiler::sourceObjectPtr() const
 {
     return sourceObject.get();
 }
 
@@ -1036,21 +1040,24 @@ frontend::CompileStandaloneFunction(JSCo
     AutoAssertReportedException assertException(cx);
 
     RootedScope scope(cx, enclosingScope);
     if (!scope) {
         scope = &cx->global()->emptyGlobalScope();
     }
 
     BytecodeCompiler compiler(cx, options, srcBuf, scope);
-    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd) ||
-        !compiler.compileStandaloneFunction(fun, GeneratorKind::NotGenerator,
-                                            FunctionAsyncKind::SyncFunction,
-                                            parameterListEnd))
-    {
+    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd)) {
+        return false;
+    }
+
+    CodeNode* parsedFunction = compiler.parseStandaloneFunction(fun, GeneratorKind::NotGenerator,
+                                                                FunctionAsyncKind::SyncFunction,
+                                                                parameterListEnd);
+    if (!parsedFunction || !compiler.compileStandaloneFunction(parsedFunction, fun)) {
         return false;
     }
 
     assertException.reset();
     return true;
 }
 
 bool
@@ -1059,21 +1066,24 @@ 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.prepareStandaloneFunctionParse(parameterListEnd) ||
-        !compiler.compileStandaloneFunction(fun, GeneratorKind::Generator,
-                                            FunctionAsyncKind::SyncFunction,
-                                            parameterListEnd))
-    {
+    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd)) {
+        return false;
+    }
+
+    CodeNode* parsedFunction = compiler.parseStandaloneFunction(fun, GeneratorKind::Generator,
+                                                                FunctionAsyncKind::SyncFunction,
+                                                                parameterListEnd);
+    if (!parsedFunction || !compiler.compileStandaloneFunction(parsedFunction, fun)) {
         return false;
     }
 
     assertException.reset();
     return true;
 }
 
 bool
@@ -1082,21 +1092,24 @@ 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.prepareStandaloneFunctionParse(parameterListEnd) ||
-        !compiler.compileStandaloneFunction(fun, GeneratorKind::NotGenerator,
-                                            FunctionAsyncKind::AsyncFunction,
-                                            parameterListEnd))
-    {
+    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd)) {
+        return false;
+    }
+
+    CodeNode* parsedFunction = compiler.parseStandaloneFunction(fun, GeneratorKind::NotGenerator,
+                                                                FunctionAsyncKind::AsyncFunction,
+                                                                parameterListEnd);
+    if (!parsedFunction || !compiler.compileStandaloneFunction(parsedFunction, fun)) {
         return false;
     }
 
     assertException.reset();
     return true;
 }
 
 bool
@@ -1105,19 +1118,22 @@ 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.prepareStandaloneFunctionParse(parameterListEnd) ||
-        !compiler.compileStandaloneFunction(fun, GeneratorKind::Generator,
-                                            FunctionAsyncKind::AsyncFunction,
-                                            parameterListEnd))
-    {
+    if (!compiler.prepareStandaloneFunctionParse(parameterListEnd)) {
+        return false;
+    }
+
+    CodeNode* parsedFunction = compiler.parseStandaloneFunction(fun, GeneratorKind::Generator,
+                                                                FunctionAsyncKind::AsyncFunction,
+                                                                parameterListEnd);
+    if (!parsedFunction || !compiler.compileStandaloneFunction(parsedFunction, fun)) {
         return false;
     }
 
     assertException.reset();
     return true;
 }