Bug 1597153 - Part 3: Add --binast-format parameter to JS shell. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Fri, 22 Nov 2019 14:19:11 +0000
changeset 503375 da0c2ed5c0e3326277f21d7a6fc1c95382c92bd0
parent 503374 613769723c834446d37ef4b01620a7bc19b2ebe9
child 503376 24087ff1dfa9c14fc5f665eab2d06a606989dc30
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 3: Add --binast-format parameter to JS shell. r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D53367
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -906,26 +906,27 @@ static MOZ_MUST_USE bool RunFile(JSConte
     }
   }
   return true;
 }
 
 #if defined(JS_BUILD_BINAST)
 
 static MOZ_MUST_USE bool RunBinAST(JSContext* cx, const char* filename,
-                                   FILE* file, bool compileOnly) {
+                                   FILE* file, bool compileOnly,
+                                   JS::BinASTFormat format) {
   RootedScript script(cx);
 
   {
     CompileOptions options(cx);
     options.setFileAndLine(filename, 0)
         .setIsRunOnce(true)
         .setNoScriptRval(true);
 
-    script = JS::DecodeBinAST(cx, options, file, JS::BinASTFormat::Multipart);
+    script = JS::DecodeBinAST(cx, options, file, format);
     if (!script) {
       return false;
     }
   }
 
   if (!RegisterScriptPathWithModuleLoader(cx, script, filename)) {
     return false;
   }
@@ -1462,17 +1463,18 @@ static MOZ_MUST_USE bool ReadEvalPrintLo
 
   return true;
 }
 
 enum FileKind {
   FileScript,       // UTF-8, directly parsed as such
   FileScriptUtf16,  // FileScript, but inflate to UTF-16 before parsing
   FileModule,
-  FileBinAST
+  FileBinASTMultipart,
+  FileBinASTContext,
 };
 
 static void ReportCantOpenErrorUnknownEncoding(JSContext* cx,
                                                const char* filename) {
   /*
    * Filenames are in some random system encoding.  *Probably* it's UTF-8,
    * but no guarantees.
    *
@@ -1516,18 +1518,25 @@ static MOZ_MUST_USE bool Process(JSConte
         }
         break;
       case FileModule:
         if (!RunModule(cx, filename, file, compileOnly)) {
           return false;
         }
         break;
 #if defined(JS_BUILD_BINAST)
-      case FileBinAST:
-        if (!RunBinAST(cx, filename, file, compileOnly)) {
+      case FileBinASTMultipart:
+        if (!RunBinAST(cx, filename, file, compileOnly,
+                       JS::BinASTFormat::Multipart)) {
+          return false;
+        }
+        break;
+      case FileBinASTContext:
+        if (!RunBinAST(cx, filename, file, compileOnly,
+                       JS::BinASTFormat::Context)) {
           return false;
         }
         break;
 #endif  // JS_BUILD_BINAST
       default:
         MOZ_CRASH("Impossible FileKind!");
     }
   } else {
@@ -10112,18 +10121,28 @@ static MOZ_MUST_USE bool ProcessArgs(JSC
     return false;
   }
 
   MultiStringRange filePaths = op->getMultiStringOption('f');
   MultiStringRange utf16FilePaths = op->getMultiStringOption('u');
   MultiStringRange codeChunks = op->getMultiStringOption('e');
   MultiStringRange modulePaths = op->getMultiStringOption('m');
   MultiStringRange binASTPaths(nullptr, nullptr);
+  FileKind binASTFileKind = FileBinASTMultipart;
 #if defined(JS_BUILD_BINAST)
   binASTPaths = op->getMultiStringOption('B');
+  if (const char* str = op->getStringOption("binast-format")) {
+    if (strcmp(str, "multipart") == 0) {
+      binASTFileKind = FileBinASTMultipart;
+    } else if (strcmp(str, "context") == 0) {
+      binASTFileKind = FileBinASTContext;
+    } else {
+      return OptionFailure("binast-format", str);
+    }
+  }
 #endif  // JS_BUILD_BINAST
 
   if (filePaths.empty() && utf16FilePaths.empty() && codeChunks.empty() &&
       modulePaths.empty() && binASTPaths.empty() &&
       !op->getStringArg("script")) {
     return Process(cx, nullptr, true, FileScript); /* Interactive. */
   }
 
@@ -10205,17 +10224,17 @@ static MOZ_MUST_USE bool ProcessArgs(JSC
       }
 
       continue;
     }
 
     if (baArgno < fpArgno && baArgno < ufpArgno && baArgno < ccArgno &&
         baArgno < mpArgno) {
       char* path = binASTPaths.front();
-      if (!Process(cx, path, false, FileBinAST)) {
+      if (!Process(cx, path, false, binASTFileKind)) {
         return false;
       }
 
       binASTPaths.popFront();
       continue;
     }
 
     MOZ_ASSERT(mpArgno < fpArgno && mpArgno < ufpArgno && mpArgno < ccArgno &&
@@ -10985,18 +11004,21 @@ int main(int argc, char** argv, char** e
           "File path to run, parsing file contents as UTF-8") ||
       !op.addMultiStringOption(
           'u', "utf16-file", "PATH",
           "File path to run, inflating the file's UTF-8 contents to UTF-16 and "
           "then parsing that") ||
       !op.addMultiStringOption('m', "module", "PATH", "Module path to run") ||
 #if defined(JS_BUILD_BINAST)
       !op.addMultiStringOption('B', "binast", "PATH", "BinAST path to run") ||
+      !op.addStringOption('\0', "binast-format", "[format]",
+                          "Format of BinAST file (multipart/context)") ||
 #else
       !op.addMultiStringOption('B', "binast", "", "No-op") ||
+      !op.addStringOption('\0', "binast-format", "No-op") ||
 #endif  // JS_BUILD_BINAST
       !op.addMultiStringOption('e', "execute", "CODE", "Inline code to run") ||
       !op.addBoolOption('i', "shell", "Enter prompt after running code") ||
       !op.addBoolOption('c', "compileonly",
                         "Only compile, don't run (syntax checking mode)") ||
       !op.addBoolOption('w', "warnings", "Emit warnings") ||
       !op.addBoolOption('W', "nowarnings", "Don't emit warnings") ||
       !op.addBoolOption('s', "strict", "Check strictness") ||