Bug 611060 - Allow -r and -l to be passed to disfile (r=igor)
authorPaul Biggar <pbiggar@mozilla.com>
Thu, 18 Nov 2010 11:22:24 -0800
changeset 58045 12d38422c622bbef90349e243b6633d59ffc49f0
parent 58044 3e74fd36384731d6729e0fd9655b28655cfb241d
child 58046 b12f0464da326340c65747aa4a13427bcacce7c8
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersigor
bugs611060
milestone2.0b8pre
Bug 611060 - Allow -r and -l to be passed to disfile (r=igor)
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2070,23 +2070,24 @@ DisassembleValue(JSContext *cx, jsval v,
         }
     }
     return true;
 }
 
 static JSBool
 Disassemble(JSContext *cx, uintN argc, jsval *vp)
 {
+    jsval *argv = JS_ARGV(cx, vp);
+
+    /* Read options off early arguments */
     bool lines = false, recursive = false;
-
-    jsval *argv = JS_ARGV(cx, vp);
     while (argc > 0 && JSVAL_IS_STRING(argv[0])) {
         JSString *str = JSVAL_TO_STRING(argv[0]);
-        lines = JS_MatchStringAndAscii(str, "-l");
-        recursive = JS_MatchStringAndAscii(str, "-r");
+        lines |= JS_MatchStringAndAscii(str, "-l");
+        recursive |= JS_MatchStringAndAscii(str, "-r");
         if (!lines && !recursive)
             break;
         argv++, argc--;
     }
 
     for (uintN i = 0; i < argc; i++) {
         if (!DisassembleValue(cx, argv[i], lines, recursive))
             return false;
@@ -2100,16 +2101,22 @@ DisassFile(JSContext *cx, uintN argc, js
 {
     jsval *argv = JS_ARGV(cx, vp);
 
     if (!argc) {
         JS_SET_RVAL(cx, vp, JSVAL_VOID);
         return JS_TRUE;
     }
 
+    /* Support extra options at the start, just like Dissassemble. */
+    uintN _argc = argc;
+    argv += argc-1;
+    argc = 1;
+
+
     JSObject *thisobj = JS_THIS_OBJECT(cx, vp);
     if (!thisobj)
         return JS_FALSE;
 
     JSString *str = JS_ValueToString(cx, argv[0]);
     if (!str)
         return JS_FALSE;
     JSAutoByteString filename(cx, str);
@@ -2128,17 +2135,17 @@ DisassFile(JSContext *cx, uintN argc, js
         return JS_TRUE;
     }
 
     JSObject *obj = JS_NewScriptObject(cx, script);
     if (!obj)
         return JS_FALSE;
 
     argv[0] = OBJECT_TO_JSVAL(obj); /* I like to root it, root it. */
-    JSBool ok = Disassemble(cx, 1, vp); /* gross, but works! */
+    JSBool ok = Disassemble(cx, _argc, vp); /* gross, but works! */
     JS_SET_RVAL(cx, vp, JSVAL_VOID);
     return ok;
 }
 
 static JSBool
 DisassWithSrc(JSContext *cx, uintN argc, jsval *vp)
 {
 #define LINE_BUF_LEN 512
@@ -4344,19 +4351,21 @@ static const char *const shell_help_mess
 "untrap(fun[, pc])        Remove a trap",
 "line2pc([fun,] line)     Map line number to PC",
 "pc2line(fun[, pc])       Map PC to line number",
 "stackQuota([number])     Query/set script stack quota",
 "stringsAreUTF8()         Check if strings are UTF-8 encoded",
 "testUTF8(mode)           Perform UTF-8 tests (modes are 1 to 4)",
 "throwError()             Throw an error from JS_ReportError",
 #ifdef DEBUG
-"dis([fun])               Disassemble functions into bytecodes\n"
-"dis('-r', fun)           Disassembles recursively",
-"disfile('foo.js')        Disassemble script file into bytecodes",
+"dis([fun])               Disassemble functions into bytecodes",
+"disfile('foo.js')        Disassemble script file into bytecodes\n"
+"  dis and disfile take these options as preceeding string arguments\n"
+"    \"-r\" (disassemble recursively)\n"
+"    \"-l\" (show line numbers)",
 "dissrc([fun])            Disassemble functions with source lines",
 "dumpHeap([fileName[, start[, toFind[, maxDepth[, toIgnore]]]]])\n"
 "  Interface to JS_DumpHeap with output sent to file",
 "dumpObject()             Dump an internal representation of an object",
 "notes([fun])             Show source notes for functions",
 "tracing([true|false|filename]) Turn bytecode execution tracing on/off.\n"
 "                         With filename, send to file.\n",
 "stats([string ...])      Dump 'arena', 'atom', 'global' stats",