Bug 1551489 - Part 3: Support { format: "context" } in parseBin shell built-in. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Mon, 20 May 2019 10:41:00 +0000
changeset 474507 678d5b0568490b694fbd6ffa93d001b42938f530
parent 474506 43dd49397f1458733de41dc79af75fcdb9171720
child 474508 f6b2612701f631484e59c793308e955b01eada99
push id36041
push userccoroiu@mozilla.com
push dateMon, 20 May 2019 21:55:28 +0000
treeherdermozilla-central@29bdbbe89264 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1551489
milestone68.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 1551489 - Part 3: Support { format: "context" } in parseBin shell built-in. r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D31059
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -87,17 +87,17 @@
 #include "jit/shared/CodeGenerator-shared.h"
 #include "js/ArrayBuffer.h"  // JS::{CreateMappedArrayBufferContents,NewMappedArrayBufferWithContents,IsArrayBufferObject,GetArrayBufferLengthAndData}
 #include "js/BuildId.h"      // JS::BuildIdCharVector, JS::SetProcessBuildIdOp
 #include "js/CharacterEncoding.h"
 #include "js/CompilationAndEvaluation.h"
 #include "js/CompileOptions.h"
 #include "js/ContextOptions.h"  // JS::ContextOptions{,Ref}
 #include "js/Debug.h"
-#include "js/Equality.h"  // JS::SameValue
+#include "js/Equality.h"                 // JS::SameValue
 #include "js/experimental/SourceHook.h"  // js::{Set,Forget,}SourceHook
 #include "js/GCVector.h"
 #include "js/Initialization.h"
 #include "js/JSON.h"
 #include "js/MemoryFunctions.h"
 #include "js/Printf.h"
 #include "js/PropertySpec.h"
 #include "js/Realm.h"
@@ -5095,16 +5095,22 @@ static bool BinParse(JSContext* cx, unsi
   bool buf_isSharedMemory = false;
   uint8_t* buf_data = nullptr;
   JS::GetArrayBufferLengthAndData(objBuf, &buf_length, &buf_isSharedMemory,
                                   &buf_data);
   MOZ_ASSERT(buf_data);
 
   // Extract argument 2: Options.
 
+  // BinAST currently supports 2 formats, multipart and context.
+  enum {
+    Multipart,
+    Context,
+  } mode = Multipart;
+
   if (args.length() >= 2) {
     if (!args[1].isObject()) {
       const char* typeName = InformalValueTypeName(args[1]);
       JS_ReportErrorASCII(cx, "expected object (options) to parse, got %s",
                           typeName);
       return false;
     }
     RootedObject objOptions(cx, &args[1].toObject());
@@ -5116,17 +5122,21 @@ static bool BinParse(JSContext* cx, unsi
 
     if (!optionFormat.isUndefined()) {
       RootedLinearString linearFormat(
           cx, optionFormat.toString()->ensureLinear(cx));
       if (!linearFormat) {
         return false;
       }
       // Currently not used, reserved for future.
-      if (!StringEqualsAscii(linearFormat, "multipart")) {
+      if (StringEqualsAscii(linearFormat, "multipart")) {
+        mode = Multipart;
+      } else if (StringEqualsAscii(linearFormat, "context")) {
+        mode = Context;
+      } else {
         UniqueChars printable = JS_EncodeStringToUTF8(cx, linearFormat);
         if (!printable) {
           return false;
         }
 
         JS_ReportErrorUTF8(
             cx,
             "Unknown value for option `format`, expected 'multipart', got %s",
@@ -5151,17 +5161,19 @@ static bool BinParse(JSContext* cx, unsi
       cx, frontend::CreateScriptSourceObject(cx, options, Nothing()));
   if (!sourceObj) {
     return false;
   }
 
   Directives directives(false);
   GlobalSharedContext globalsc(cx, ScopeKind::Global, directives, false);
 
-  auto parseFunc = ParseBinASTData<frontend::BinASTTokenReaderMultipart>;
+  auto parseFunc = mode == Multipart
+                       ? ParseBinASTData<frontend::BinASTTokenReaderMultipart>
+                       : ParseBinASTData<frontend::BinASTTokenReaderContext>;
   if (!parseFunc(cx, buf_data, buf_length, &globalsc, usedNames, options,
                  sourceObj)) {
     return false;
   }
 
   args.rval().setUndefined();
   return true;
 }
@@ -8679,18 +8691,21 @@ static const JSFunctionSpecWithHelp shel
     JS_FN_HELP("getModuleLoadPath", GetModuleLoadPath, 0, 0,
 "getModuleLoadPath()",
 "  Return any --module-load-path argument passed to the shell.  Used by the\n"
 "  module loader.\n"),
 
 #if defined(JS_BUILD_BINAST)
 
 JS_FN_HELP("parseBin", BinParse, 1, 0,
-"parseBin(arraybuffer)",
-"  Parses a Binary AST, potentially throwing."),
+"parseBin(arraybuffer, [options])",
+"  Parses a Binary AST, potentially throwing. If present, |options| may\n"
+"  have properties saying how the passed |arraybuffer| should be handled:\n"
+"      format: the format of the BinAST file\n"
+"        (\"multipart\" or \"context\")"),
 
 #endif // defined(JS_BUILD_BINAST)
 
     JS_FN_HELP("parse", Parse, 1, 0,
 "parse(code)",
 "  Parses a string, potentially throwing."),
 
     JS_FN_HELP("syntaxParse", SyntaxParse, 1, 0,