Add disfile() helper to debug shell, to make it easier to see disassembly of top-level scripts.

This commit is contained in:
shaver@mozilla.org 2008-07-08 14:33:56 -04:00
parent c1491b01c2
commit ae64a20e56

View File

@ -1408,6 +1408,37 @@ Disassemble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return JS_TRUE;
}
static JSBool
DisassFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSString *str;
const char *filename;
JSScript *script;
JSBool ok;
if (!argc)
return JS_TRUE;
str = JS_ValueToString(cx, argv[0]);
if (!str)
return JS_FALSE;
filename = JS_GetStringBytes(str);
script = JS_CompileFile(cx, obj, filename);
if (!script)
return JS_FALSE;
obj = JS_NewScriptObject(cx, script);
if (!obj)
return JS_FALSE;
*rval = OBJECT_TO_JSVAL(obj); /* I like to root it, root it. */
ok = Disassemble(cx, obj, 1, rval, rval); /* gross, but works! */
*rval = JSVAL_VOID;
return ok;
}
static JSBool
DisassWithSrc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
@ -2802,6 +2833,7 @@ static JSFunctionSpec shell_functions[] = {
JS_FS("throwError", ThrowError, 0,0,0),
#ifdef DEBUG
JS_FS("dis", Disassemble, 1,0,0),
JS_FS("disfile", DisassFile, 1,0,0),
JS_FS("dissrc", DisassWithSrc, 1,0,0),
JS_FN("dumpHeap", DumpHeap, 0,0,0),
JS_FS("notes", Notes, 1,0,0),
@ -2873,6 +2905,7 @@ static const char *const shell_help_messages[] = {
"throwError() Throw an error from JS_ReportError",
#ifdef DEBUG
"dis([fun]) Disassemble functions into bytecodes",
"disfile('foo.js') Disassemble script file into bytecodes",
"dissrc([fun]) Disassemble functions with source lines",
"dumpHeap([fileName[, start[, toFind[, maxDepth[, toIgnore]]]]])\n"
" Interface to JS_DumpHeap with output sent to file",