diff --git a/js/src/js.c b/js/src/js.c index 353c0690f08..07e779a3856 100644 --- a/js/src/js.c +++ b/js/src/js.c @@ -1030,7 +1030,8 @@ Disassemble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) } } - js_Disassemble(cx, script, lines, stdout); + if (!js_Disassemble(cx, script, lines, stdout)) + return JS_FALSE; SrcNotes(cx, script); TryNotes(cx, script); } diff --git a/js/src/jsopcode.c b/js/src/jsopcode.c index 06dafcce8d0..2135e69ec13 100644 --- a/js/src/jsopcode.c +++ b/js/src/jsopcode.c @@ -122,7 +122,7 @@ GetJumpOffset(jsbytecode *pc, jsbytecode *pc2) #ifdef DEBUG -JS_FRIEND_API(void) +JS_FRIEND_API(JSBool) js_Disassemble(JSContext *cx, JSScript *script, JSBool lines, FILE *fp) { jsbytecode *pc, *end; @@ -137,9 +137,10 @@ js_Disassemble(JSContext *cx, JSScript *script, JSBool lines, FILE *fp) PTRDIFF(pc, script->code, jsbytecode), lines, fp); if (!len) - return; + return JS_FALSE; pc += len; } + return JS_TRUE; } JS_FRIEND_API(uintN) @@ -274,6 +275,48 @@ js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc, uintN loc, break; #endif + case JOF_UINT24: + if (op == JSOP_FINDNAME) { + /* Special case to avoid a JOF_FINDNAME just for this op. */ + atom = js_GetAtom(cx, &script->atomMap, GET_LITERAL_INDEX(pc)); + str = js_ValueToSource(cx, ATOM_KEY(atom)); + if (!str) + return 0; + fprintf(fp, " %s", JS_GetStringBytes(str)); + break; + } + + JS_ASSERT(op == JSOP_UINT24 || op == JSOP_LITERAL); + fprintf(fp, " %u", GET_LITERAL_INDEX(pc)); + break; + + case JOF_LITOPX: + atom = js_GetAtom(cx, &script->atomMap, GET_LITERAL_INDEX(pc)); + str = js_ValueToSource(cx, ATOM_KEY(atom)); + if (!str) + return 0; + + /* + * Bytecode: JSOP_LITOPX op [ if JSOP_DEFLOCALFUN]. + * Advance pc to point at op. + */ + pc += 1 + LITERAL_INDEX_LEN; + op = *pc; + cs = &js_CodeSpec[op]; + fprintf(fp, " %s op %s", JS_GetStringBytes(str), cs->name); +#if JS_HAS_LEXICAL_CLOSURE + if ((cs->format & JOF_TYPEMASK) == JOF_INDEXCONST) + fprintf(fp, " %u", GET_VARNO(pc)); +#endif + + /* + * Set len to advance pc to skip op and any other immediates (namely, + * if JSOP_DEFLOCALFUN). + */ + JS_ASSERT(cs->length > ATOM_INDEX_LEN); + len = cs->length - ATOM_INDEX_LEN; + break; + default: { char numBuf[12]; JS_snprintf(numBuf, sizeof numBuf, "%lx", (unsigned long) cs->format); diff --git a/js/src/jsopcode.h b/js/src/jsopcode.h index 237be8c30af..2a488f6eb66 100644 --- a/js/src/jsopcode.h +++ b/js/src/jsopcode.h @@ -256,7 +256,7 @@ js_puts(JSPrinter *jp, const char *s); */ #include -extern JS_FRIEND_API(void) +extern JS_FRIEND_API(JSBool) js_Disassemble(JSContext *cx, JSScript *script, JSBool lines, FILE *fp); extern JS_FRIEND_API(uintN)