Bug 1597153 - Part 2: Use context parser when JS::BinASTFormat::Context is passed. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Fri, 22 Nov 2019 14:18:59 +0000
changeset 503374 613769723c834446d37ef4b01620a7bc19b2ebe9
parent 503373 7f5fc05b10a10b3d897319ba47f0467c8ef4449d
child 503375 da0c2ed5c0e3326277f21d7a6fc1c95382c92bd0
push id36833
push userbtara@mozilla.com
push dateFri, 22 Nov 2019 21:40:53 +0000
treeherdermozilla-central@2c912e46295e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1597153
milestone72.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 1597153 - Part 2: Use context parser when JS::BinASTFormat::Context is passed. r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D53366
js/src/frontend/BytecodeCompiler.cpp
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -734,17 +734,18 @@ ScriptSourceObject* frontend::CreateScri
     }
   }
 
   return sso;
 }
 
 #if defined(JS_BUILD_BINAST)
 
-JSScript* frontend::CompileGlobalBinASTScript(
+template <class ParserT>
+static JSScript* CompileGlobalBinASTScriptImpl(
     JSContext* cx, const ReadOnlyCompileOptions& options, const uint8_t* src,
     size_t len, JS::BinASTFormat format, ScriptSourceObject** sourceObjectOut) {
   AutoAssertReportedException assertException(cx);
 
   LifoAllocScope allocScope(&cx->tempLifoAlloc());
   frontend::ParseInfo parseInfo(cx, allocScope);
 
   RootedScriptSourceObject sourceObj(cx, CreateScriptSourceObject(cx, options));
@@ -763,20 +764,17 @@ JSScript* frontend::CompileGlobalBinASTS
   if (!script) {
     return nullptr;
   }
 
   Directives directives(options.forceStrictMode());
   GlobalSharedContext globalsc(cx, ScopeKind::Global, directives,
                                options.extraWarningsOption);
 
-  MOZ_ASSERT(format == JS::BinASTFormat::Multipart);
-
-  frontend::BinASTParser<BinASTTokenReaderMultipart> parser(cx, parseInfo,
-                                                            options, sourceObj);
+  frontend::BinASTParser<ParserT> parser(cx, parseInfo, options, sourceObj);
 
   // Metadata stores internal pointers, so we must use the same buffer every
   // time, including for lazy parses
   ScriptSource* ss = sourceObj->source();
   BinASTSourceMetadata* metadata = nullptr;
   auto parsed =
       parser.parse(&globalsc, ss->binASTSource(), ss->length(), &metadata);
 
@@ -801,16 +799,29 @@ JSScript* frontend::CompileGlobalBinASTS
   if (sourceObjectOut) {
     *sourceObjectOut = sourceObj;
   }
 
   assertException.reset();
   return script;
 }
 
+JSScript* frontend::CompileGlobalBinASTScript(
+    JSContext* cx, const ReadOnlyCompileOptions& options, const uint8_t* src,
+    size_t len, JS::BinASTFormat format, ScriptSourceObject** sourceObjectOut) {
+  if (format == JS::BinASTFormat::Multipart) {
+    return CompileGlobalBinASTScriptImpl<BinASTTokenReaderMultipart>(
+        cx, options, src, len, format, sourceObjectOut);
+  }
+
+  MOZ_ASSERT(format == JS::BinASTFormat::Context);
+  return CompileGlobalBinASTScriptImpl<BinASTTokenReaderContext>(
+      cx, options, src, len, format, sourceObjectOut);
+}
+
 #endif  // JS_BUILD_BINAST
 
 template <typename Unit>
 static ModuleObject* InternalParseModule(
     JSContext* cx, const ReadOnlyCompileOptions& optionsInput,
     SourceText<Unit>& srcBuf, ScriptSourceObject** sourceObjectOut) {
   MOZ_ASSERT(srcBuf.get());
   MOZ_ASSERT_IF(sourceObjectOut, *sourceObjectOut == nullptr);