Recover trapped opcode in js_GetIndexFromBytecode (416665, r=igor).

This commit is contained in:
brendan@mozilla.org 2008-02-17 17:32:12 -08:00
Родитель 5a517d507d
Коммит 706a1e1472
3 изменённых файлов: 24 добавлений и 27 удалений

Просмотреть файл

@ -161,21 +161,16 @@ JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
JS_PUBLIC_API(JSOp)
JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc)
{
JSRuntime *rt;
JSTrap *trap;
JSOp op;
DBG_LOCK_EVAL(cx->runtime, trap = FindTrap(cx->runtime, script, pc));
if (!trap) {
#ifdef JS_THREADSAFE
/*
* If we lost a race with another thread, return JSOP_LIMIT so our
* caller can detect this case and do something sane.
*/
#else
JS_ASSERT(0); /* XXX can't happen */
#endif
return JSOP_LIMIT;
}
return trap->op;
rt = cx->runtime;
DBG_LOCK(rt);
trap = FindTrap(rt, script, pc);
op = trap ? trap->op : (JSOp) *pc;
DBG_UNLOCK(rt);
return op;
}
static void

Просмотреть файл

@ -123,12 +123,15 @@ GetJumpOffset(jsbytecode *pc, jsbytecode *pc2)
}
uintN
js_GetIndexFromBytecode(JSScript *script, jsbytecode *pc, ptrdiff_t pcoff)
js_GetIndexFromBytecode(JSContext *cx, JSScript *script, jsbytecode *pc,
ptrdiff_t pcoff)
{
JSOp op;
uintN span, base;
op = (JSOp)*pc;
if (op == JSOP_TRAP)
op = JS_GetTrapOpcode(cx, script, pc);
JS_ASSERT(js_CodeSpec[op].length >= 1 + pcoff + UINT16_LEN);
/*
@ -241,8 +244,6 @@ js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc,
case JOF_BYTE:
if (op == JSOP_TRAP) {
op = JS_GetTrapOpcode(cx, script, pc);
if (op == JSOP_LIMIT)
return 0;
len = (ptrdiff_t) js_CodeSpec[op].length;
}
break;
@ -256,7 +257,7 @@ js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc,
case JOF_ATOM:
case JOF_OBJECT:
case JOF_REGEXP:
index = js_GetIndexFromBytecode(script, pc, 0);
index = js_GetIndexFromBytecode(cx, script, pc, 0);
if (type == JOF_ATOM) {
JS_GET_SCRIPT_ATOM(script, index, atom);
v = ATOM_KEY(atom);
@ -348,7 +349,7 @@ js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc,
case JOF_SLOTATOM:
case JOF_SLOTOBJECT:
fprintf(fp, " %u", GET_VARNO(pc));
index = js_GetIndexFromBytecode(script, pc, VARNO_LEN);
index = js_GetIndexFromBytecode(cx, script, pc, VARNO_LEN);
if (type == JOF_SLOTATOM) {
JS_GET_SCRIPT_ATOM(script, index, atom);
v = ATOM_KEY(atom);
@ -4131,10 +4132,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb, JSOp nextop)
#endif /* JS_HAS_EXPORT_IMPORT */
case JSOP_TRAP:
op = JS_GetTrapOpcode(cx, jp->script, pc);
if (op == JSOP_LIMIT)
return NULL;
saveop = op;
saveop = op = JS_GetTrapOpcode(cx, jp->script, pc);
*pc = op;
cs = &js_CodeSpec[op];
len = cs->length;

Просмотреть файл

@ -302,10 +302,14 @@ js_puts(JSPrinter *jp, const char *s);
/*
* Get index operand from the bytecode using a bytecode analysis to deduce the
* the index register.
* the index register. This function is infallible, in spite of taking cx as
* its first parameter; it uses only cx->runtime when calling JS_GetTrapOpcode.
* The GET_*_FROM_BYTECODE macros that call it pick up cx from their caller's
* lexical environments.
*/
uintN
js_GetIndexFromBytecode(JSScript *script, jsbytecode *pc, ptrdiff_t pcoff);
js_GetIndexFromBytecode(JSContext *cx, JSScript *script, jsbytecode *pc,
ptrdiff_t pcoff);
/*
* A slower version of GET_ATOM when the caller does not want to maintain
@ -313,13 +317,13 @@ js_GetIndexFromBytecode(JSScript *script, jsbytecode *pc, ptrdiff_t pcoff);
*/
#define GET_ATOM_FROM_BYTECODE(script, pc, pcoff, atom) \
JS_BEGIN_MACRO \
uintN index_ = js_GetIndexFromBytecode((script), (pc), (pcoff)); \
uintN index_ = js_GetIndexFromBytecode(cx, (script), (pc), (pcoff)); \
JS_GET_SCRIPT_ATOM((script), index_, atom); \
JS_END_MACRO
#define GET_OBJECT_FROM_BYTECODE(script, pc, pcoff, obj) \
JS_BEGIN_MACRO \
uintN index_ = js_GetIndexFromBytecode((script), (pc), (pcoff)); \
uintN index_ = js_GetIndexFromBytecode(cx, (script), (pc), (pcoff)); \
JS_GET_SCRIPT_OBJECT((script), index_, obj); \
JS_END_MACRO
@ -331,7 +335,7 @@ js_GetIndexFromBytecode(JSScript *script, jsbytecode *pc, ptrdiff_t pcoff);
#define GET_REGEXP_FROM_BYTECODE(script, pc, pcoff, obj) \
JS_BEGIN_MACRO \
uintN index_ = js_GetIndexFromBytecode((script), (pc), (pcoff)); \
uintN index_ = js_GetIndexFromBytecode(cx, (script), (pc), (pcoff)); \
JS_GET_SCRIPT_REGEXP((script), index_, obj); \
JS_END_MACRO