Bug 562991 - Change JS_SetTrap closure argument type from void* to jsval (r=brendan)

This commit is contained in:
Luke Wagner 2010-04-30 17:34:54 -07:00
Родитель f574b6dcec
Коммит ba4adc8ba7
9 изменённых файлов: 63 добавлений и 51 удалений

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

@ -715,9 +715,9 @@ _isActiveHook(JSDContext* jsdc, JSScript *script, JSDExecHook* jsdhook)
JSTrapStatus JSTrapStatus
jsd_TrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval, jsd_TrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
void *closure) jsval closure)
{ {
JSDExecHook* jsdhook = (JSDExecHook*) JSVAL_TO_PRIVATE(((jsval)closure)); JSDExecHook* jsdhook = (JSDExecHook*) JSVAL_TO_PRIVATE(closure);
JSD_ExecutionHookProc hook; JSD_ExecutionHookProc hook;
void* hookData; void* hookData;
JSDContext* jsdc; JSDContext* jsdc;
@ -800,7 +800,7 @@ jsd_SetExecutionHook(JSDContext* jsdc,
if( ! JS_SetTrap(jsdc->dumbContext, jsdscript->script, if( ! JS_SetTrap(jsdc->dumbContext, jsdscript->script,
(jsbytecode*)pc, jsd_TrapHandler, (jsbytecode*)pc, jsd_TrapHandler,
(void*) PRIVATE_TO_JSVAL(jsdhook)) ) PRIVATE_TO_JSVAL(jsdhook)) )
{ {
free(jsdhook); free(jsdhook);
JSD_UNLOCK(); JSD_UNLOCK();

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

@ -5,9 +5,10 @@ static int emptyTrapCallCount = 0;
static JSTrapStatus static JSTrapStatus
EmptyTrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval, EmptyTrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
void *closure) jsval closure)
{ {
JS_GC(cx); JS_GC(cx);
if (JSVAL_IS_STRING(closure))
++emptyTrapCallCount; ++emptyTrapCallCount;
return JSTRAP_CONTINUE; return JSTRAP_CONTINUE;
} }
@ -49,8 +50,8 @@ BEGIN_TEST(testTrap_gc)
static const char trapClosureText[] = "some trap closure"; static const char trapClosureText[] = "some trap closure";
JSString *trapClosure = JS_NewStringCopyZ(cx, trapClosureText); JSString *trapClosure = JS_NewStringCopyZ(cx, trapClosureText);
CHECK(trapClosure); CHECK(trapClosure);
JS_SetTrap(cx, script, line2, EmptyTrapHandler, trapClosure); JS_SetTrap(cx, script, line2, EmptyTrapHandler, STRING_TO_JSVAL(trapClosure));
JS_SetTrap(cx, script, line6, EmptyTrapHandler, trapClosure); JS_SetTrap(cx, script, line6, EmptyTrapHandler, STRING_TO_JSVAL(trapClosure));
JS_GC(cx); JS_GC(cx);

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

@ -865,7 +865,7 @@ struct JSRuntime {
#ifdef JS_TRACER #ifdef JS_TRACER
/* True if any debug hooks not supported by the JIT are enabled. */ /* True if any debug hooks not supported by the JIT are enabled. */
bool debuggerInhibitsJIT() const { bool debuggerInhibitsJIT() const {
return (globalDebugHooks.interruptHandler || return (globalDebugHooks.interruptHook ||
globalDebugHooks.callHook || globalDebugHooks.callHook ||
globalDebugHooks.objectHook); globalDebugHooks.objectHook);
} }

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

@ -77,7 +77,7 @@ typedef struct JSTrap {
jsbytecode *pc; jsbytecode *pc;
JSOp op; JSOp op;
JSTrapHandler handler; JSTrapHandler handler;
void *closure; jsval closure;
} JSTrap; } JSTrap;
#define DBG_LOCK(rt) JS_ACQUIRE_LOCK((rt)->debuggerLock) #define DBG_LOCK(rt) JS_ACQUIRE_LOCK((rt)->debuggerLock)
@ -142,7 +142,7 @@ js_UntrapScriptCode(JSContext *cx, JSScript *script)
JS_PUBLIC_API(JSBool) JS_PUBLIC_API(JSBool)
JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc, JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
JSTrapHandler handler, void *closure) JSTrapHandler handler, jsval closure)
{ {
JSTrap *junk, *trap, *twin; JSTrap *junk, *trap, *twin;
JSRuntime *rt; JSRuntime *rt;
@ -168,7 +168,7 @@ JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
trap = (JSTrap *) cx->malloc(sizeof *trap); trap = (JSTrap *) cx->malloc(sizeof *trap);
if (!trap) if (!trap)
return JS_FALSE; return JS_FALSE;
trap->closure = NULL; trap->closure = JSVAL_NULL;
DBG_LOCK(rt); DBG_LOCK(rt);
twin = (rt->debuggerMutations != sample) twin = (rt->debuggerMutations != sample)
? FindTrap(rt, script, pc) ? FindTrap(rt, script, pc)
@ -220,7 +220,7 @@ DestroyTrapAndUnlock(JSContext *cx, JSTrap *trap)
JS_PUBLIC_API(void) JS_PUBLIC_API(void)
JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
JSTrapHandler *handlerp, void **closurep) JSTrapHandler *handlerp, jsval *closurep)
{ {
JSTrap *trap; JSTrap *trap;
@ -229,7 +229,7 @@ JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
if (handlerp) if (handlerp)
*handlerp = trap ? trap->handler : NULL; *handlerp = trap ? trap->handler : NULL;
if (closurep) if (closurep)
*closurep = trap ? trap->closure : NULL; *closurep = trap ? trap->closure : JSVAL_NULL;
if (trap) if (trap)
DestroyTrapAndUnlock(cx, trap); DestroyTrapAndUnlock(cx, trap);
else else
@ -295,10 +295,8 @@ js_MarkTraps(JSTracer *trc)
for (JSTrap *trap = (JSTrap *) rt->trapList.next; for (JSTrap *trap = (JSTrap *) rt->trapList.next;
&trap->links != &rt->trapList; &trap->links != &rt->trapList;
trap = (JSTrap *) trap->links.next) { trap = (JSTrap *) trap->links.next) {
if (trap->closure) {
JS_SET_TRACING_NAME(trc, "trap->closure"); JS_SET_TRACING_NAME(trc, "trap->closure");
js_CallValueTracerIfGCThing(trc, (jsval) trap->closure); js_CallValueTracerIfGCThing(trc, trap->closure);
}
} }
} }
@ -375,15 +373,15 @@ LeaveTraceRT(JSRuntime *rt)
#endif #endif
JS_PUBLIC_API(JSBool) JS_PUBLIC_API(JSBool)
JS_SetInterrupt(JSRuntime *rt, JSTrapHandler handler, void *closure) JS_SetInterrupt(JSRuntime *rt, JSInterruptHook hook, void *closure)
{ {
#ifdef JS_TRACER #ifdef JS_TRACER
{ {
AutoLockGC lock(rt); AutoLockGC lock(rt);
bool wasInhibited = rt->debuggerInhibitsJIT(); bool wasInhibited = rt->debuggerInhibitsJIT();
#endif #endif
rt->globalDebugHooks.interruptHandler = handler; rt->globalDebugHooks.interruptHook = hook;
rt->globalDebugHooks.interruptHandlerData = closure; rt->globalDebugHooks.interruptHookData = closure;
#ifdef JS_TRACER #ifdef JS_TRACER
JITInhibitingHookChange(rt, wasInhibited); JITInhibitingHookChange(rt, wasInhibited);
} }
@ -393,18 +391,18 @@ JS_SetInterrupt(JSRuntime *rt, JSTrapHandler handler, void *closure)
} }
JS_PUBLIC_API(JSBool) JS_PUBLIC_API(JSBool)
JS_ClearInterrupt(JSRuntime *rt, JSTrapHandler *handlerp, void **closurep) JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *hoop, void **closurep)
{ {
#ifdef JS_TRACER #ifdef JS_TRACER
AutoLockGC lock(rt); AutoLockGC lock(rt);
bool wasInhibited = rt->debuggerInhibitsJIT(); bool wasInhibited = rt->debuggerInhibitsJIT();
#endif #endif
if (handlerp) if (hoop)
*handlerp = rt->globalDebugHooks.interruptHandler; *hoop = rt->globalDebugHooks.interruptHook;
if (closurep) if (closurep)
*closurep = rt->globalDebugHooks.interruptHandlerData; *closurep = rt->globalDebugHooks.interruptHookData;
rt->globalDebugHooks.interruptHandler = 0; rt->globalDebugHooks.interruptHook = 0;
rt->globalDebugHooks.interruptHandlerData = 0; rt->globalDebugHooks.interruptHookData = 0;
#ifdef JS_TRACER #ifdef JS_TRACER
JITInhibitingHookChange(rt, wasInhibited); JITInhibitingHookChange(rt, wasInhibited);
#endif #endif
@ -1561,7 +1559,7 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda)
/************************************************************************/ /************************************************************************/
JS_PUBLIC_API(JSBool) JS_PUBLIC_API(JSBool)
JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure) JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler handler, void *closure)
{ {
rt->globalDebugHooks.debuggerHandler = handler; rt->globalDebugHooks.debuggerHandler = handler;
rt->globalDebugHooks.debuggerHandlerData = closure; rt->globalDebugHooks.debuggerHandlerData = closure;
@ -1623,7 +1621,7 @@ JS_SetObjectHook(JSRuntime *rt, JSObjectHook hook, void *closure)
} }
JS_PUBLIC_API(JSBool) JS_PUBLIC_API(JSBool)
JS_SetThrowHook(JSRuntime *rt, JSTrapHandler hook, void *closure) JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure)
{ {
rt->globalDebugHooks.throwHook = hook; rt->globalDebugHooks.throwHook = hook;
rt->globalDebugHooks.throwHookData = closure; rt->globalDebugHooks.throwHookData = closure;

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

@ -57,16 +57,17 @@ JS_BEGIN_EXTERN_C
extern jsbytecode * extern jsbytecode *
js_UntrapScriptCode(JSContext *cx, JSScript *script); js_UntrapScriptCode(JSContext *cx, JSScript *script);
/* The closure argument will be marked. */
extern JS_PUBLIC_API(JSBool) extern JS_PUBLIC_API(JSBool)
JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc, JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
JSTrapHandler handler, void *closure); JSTrapHandler handler, jsval closure);
extern JS_PUBLIC_API(JSOp) extern JS_PUBLIC_API(JSOp)
JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc); JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc);
extern JS_PUBLIC_API(void) extern JS_PUBLIC_API(void)
JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc, JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
JSTrapHandler *handlerp, void **closurep); JSTrapHandler *handlerp, jsval *closurep);
extern JS_PUBLIC_API(void) extern JS_PUBLIC_API(void)
JS_ClearScriptTraps(JSContext *cx, JSScript *script); JS_ClearScriptTraps(JSContext *cx, JSScript *script);
@ -78,10 +79,10 @@ extern JS_PUBLIC_API(JSTrapStatus)
JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval); JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval);
extern JS_PUBLIC_API(JSBool) extern JS_PUBLIC_API(JSBool)
JS_SetInterrupt(JSRuntime *rt, JSTrapHandler handler, void *closure); JS_SetInterrupt(JSRuntime *rt, JSInterruptHook handler, void *closure);
extern JS_PUBLIC_API(JSBool) extern JS_PUBLIC_API(JSBool)
JS_ClearInterrupt(JSRuntime *rt, JSTrapHandler *handlerp, void **closurep); JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep);
/************************************************************************/ /************************************************************************/
@ -337,7 +338,7 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda);
/************************************************************************/ /************************************************************************/
extern JS_PUBLIC_API(JSBool) extern JS_PUBLIC_API(JSBool)
JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure); JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure);
extern JS_PUBLIC_API(JSBool) extern JS_PUBLIC_API(JSBool)
JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure); JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure);
@ -352,7 +353,7 @@ extern JS_PUBLIC_API(JSBool)
JS_SetObjectHook(JSRuntime *rt, JSObjectHook hook, void *closure); JS_SetObjectHook(JSRuntime *rt, JSObjectHook hook, void *closure);
extern JS_PUBLIC_API(JSBool) extern JS_PUBLIC_API(JSBool)
JS_SetThrowHook(JSRuntime *rt, JSTrapHandler hook, void *closure); JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure);
extern JS_PUBLIC_API(JSBool) extern JS_PUBLIC_API(JSBool)
JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure); JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure);

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

@ -2519,7 +2519,7 @@ js_Interpret(JSContext *cx)
# define CHECK_INTERRUPT_HANDLER() \ # define CHECK_INTERRUPT_HANDLER() \
JS_BEGIN_MACRO \ JS_BEGIN_MACRO \
if (cx->debugHooks->interruptHandler) \ if (cx->debugHooks->interruptHook) \
ENABLE_INTERRUPTS(); \ ENABLE_INTERRUPTS(); \
JS_END_MACRO JS_END_MACRO
@ -2679,7 +2679,7 @@ js_Interpret(JSContext *cx)
/* This is an error, not a catchable exception, quit the frame ASAP. */ /* This is an error, not a catchable exception, quit the frame ASAP. */
ok = JS_FALSE; ok = JS_FALSE;
} else { } else {
JSTrapHandler handler; JSThrowHook handler;
JSTryNote *tn, *tnlimit; JSTryNote *tn, *tnlimit;
uint32 offset; uint32 offset;

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

@ -48,14 +48,14 @@
#endif /* !JS_THREADED_INTERP */ #endif /* !JS_THREADED_INTERP */
{ {
bool moreInterrupts = false; bool moreInterrupts = false;
JSTrapHandler handler = cx->debugHooks->interruptHandler; JSInterruptHook hook = cx->debugHooks->interruptHook;
if (handler) { if (hook) {
#ifdef JS_TRACER #ifdef JS_TRACER
if (TRACE_RECORDER(cx)) if (TRACE_RECORDER(cx))
AbortRecording(cx, "interrupt handler"); AbortRecording(cx, "interrupt hook");
#endif #endif
switch (handler(cx, script, regs.pc, &rval, switch (hook(cx, script, regs.pc, &rval,
cx->debugHooks->interruptHandlerData)) { cx->debugHooks->interruptHookData)) {
case JSTRAP_ERROR: case JSTRAP_ERROR:
goto error; goto error;
case JSTRAP_CONTINUE: case JSTRAP_CONTINUE:
@ -3647,7 +3647,7 @@ END_CASE(JSOP_INSTANCEOF)
#if JS_HAS_DEBUGGER_KEYWORD #if JS_HAS_DEBUGGER_KEYWORD
BEGIN_CASE(JSOP_DEBUGGER) BEGIN_CASE(JSOP_DEBUGGER)
{ {
JSTrapHandler handler = cx->debugHooks->debuggerHandler; JSDebuggerHandler handler = cx->debugHooks->debuggerHandler;
if (handler) { if (handler) {
switch (handler(cx, script, regs.pc, &rval, cx->debugHooks->debuggerHandlerData)) { switch (handler(cx, script, regs.pc, &rval, cx->debugHooks->debuggerHandlerData)) {
case JSTRAP_ERROR: case JSTRAP_ERROR:

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

@ -212,6 +212,18 @@ typedef enum JSTrapStatus {
typedef JSTrapStatus typedef JSTrapStatus
(* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval, (* JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
jsval closure);
typedef JSTrapStatus
(* JSInterruptHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
void *closure);
typedef JSTrapStatus
(* JSDebuggerHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
void *closure);
typedef JSTrapStatus
(* JSThrowHook)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
void *closure); void *closure);
typedef JSBool typedef JSBool
@ -274,13 +286,13 @@ typedef JSBool
void *closure); void *closure);
typedef struct JSDebugHooks { typedef struct JSDebugHooks {
JSTrapHandler interruptHandler; JSInterruptHook interruptHook;
void *interruptHandlerData; void *interruptHookData;
JSNewScriptHook newScriptHook; JSNewScriptHook newScriptHook;
void *newScriptHookData; void *newScriptHookData;
JSDestroyScriptHook destroyScriptHook; JSDestroyScriptHook destroyScriptHook;
void *destroyScriptHookData; void *destroyScriptHookData;
JSTrapHandler debuggerHandler; JSDebuggerHandler debuggerHandler;
void *debuggerHandlerData; void *debuggerHandlerData;
JSSourceHandler sourceHandler; JSSourceHandler sourceHandler;
void *sourceHandlerData; void *sourceHandlerData;
@ -290,7 +302,7 @@ typedef struct JSDebugHooks {
void *callHookData; void *callHookData;
JSObjectHook objectHook; JSObjectHook objectHook;
void *objectHookData; void *objectHookData;
JSTrapHandler throwHook; JSThrowHook throwHook;
void *throwHookData; void *throwHookData;
JSDebugErrorHook debugErrorHook; JSDebugErrorHook debugErrorHook;
void *debugErrorHookData; void *debugErrorHookData;

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

@ -1457,12 +1457,12 @@ GetTrapArgs(JSContext *cx, uintN argc, jsval *argv, JSScript **scriptp,
static JSTrapStatus static JSTrapStatus
TrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval, TrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
void *closure) jsval closure)
{ {
JSString *str; JSString *str;
JSStackFrame *caller; JSStackFrame *caller;
str = (JSString *) closure; str = JSVAL_TO_STRING(closure);
caller = JS_GetScriptedCaller(cx, NULL); caller = JS_GetScriptedCaller(cx, NULL);
if (!JS_EvaluateUCInStackFrame(cx, caller, if (!JS_EvaluateUCInStackFrame(cx, caller,
JS_GetStringChars(str), JS_GetStringLength(str), JS_GetStringChars(str), JS_GetStringLength(str),
@ -1493,7 +1493,7 @@ Trap(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
argv[argc] = STRING_TO_JSVAL(str); argv[argc] = STRING_TO_JSVAL(str);
if (!GetTrapArgs(cx, argc, argv, &script, &i)) if (!GetTrapArgs(cx, argc, argv, &script, &i))
return JS_FALSE; return JS_FALSE;
return JS_SetTrap(cx, script, script->code + i, TrapHandler, str); return JS_SetTrap(cx, script, script->code + i, TrapHandler, STRING_TO_JSVAL(str));
} }
static JSBool static JSBool