Bug 680228 - In Disassemble show associated catch for a try opcode. r=sphink

--HG--
extra : rebase_source : f2412f188c0bb7db7f5c4e9717938a9888c7c0ed
This commit is contained in:
David Flanagan 2011-08-19 22:46:32 +02:00
parent 764b581511
commit 429a3e19b2
2 changed files with 18 additions and 1 deletions

View File

@ -2202,7 +2202,7 @@ JS_DumpBytecode(JSContext *cx, JSScript *script)
fprintf(stdout, "--- SCRIPT %s:%d ---\n", script->filename, script->lineno);
js_Disassemble(cx, script, true, &sprinter);
fprintf(stdout, "%s\n", sprinter.base);
fputs(sprinter.base, stdout);
fprintf(stdout, "--- END SCRIPT %s:%d ---\n", script->filename, script->lineno);
#endif
}

View File

@ -458,6 +458,23 @@ js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc,
type = JOF_TYPE(cs->format);
switch (type) {
case JOF_BYTE:
// Scan the trynotes to find the associated catch block
// and make the try opcode look like a jump instruction
// with an offset. This simplifies code coverage analysis
// based on this disassembled output.
if (op == JSOP_TRY) {
JSTryNoteArray *trynotes = script->trynotes();
uint32 i;
for(i = 0; i < trynotes->length; i++) {
JSTryNote note = trynotes->vector[i];
if (note.kind == JSTRY_CATCH && note.start == loc + 1) {
Sprint(sp, " %u (%+d)",
(unsigned int) (loc+note.length+1),
(int) (note.length+1));
break;
}
}
}
break;
case JOF_JUMP: