bug 730987 - remove per-context debug hooks. r=luke

This commit is contained in:
Igor Bukanov 2012-02-28 11:54:40 +01:00
parent c8b6e49dd7
commit fef7f4a40e
12 changed files with 67 additions and 105 deletions

View File

@ -178,8 +178,8 @@ TokenStream::init(const jschar *base, size_t length, const char *fn, uintN ln, J
prevLinebase = NULL;
sourceMap = NULL;
JSSourceHandler listener = cx->debugHooks->sourceHandler;
void *listenerData = cx->debugHooks->sourceHandlerData;
JSSourceHandler listener = cx->runtime->debugHooks.sourceHandler;
void *listenerData = cx->runtime->debugHooks.sourceHandlerData;
if (listener)
listener(fn, ln, base, length, &listenerTSData, listenerData);
@ -521,8 +521,8 @@ TokenStream::reportCompileErrorNumberVA(ParseNode *pn, uintN flags, uintN errorN
* sending the error on to the regular error reporter.
*/
bool reportError = true;
if (JSDebugErrorHook hook = cx->debugHooks->debugErrorHook)
reportError = hook(cx, message, &report, cx->debugHooks->debugErrorHookData);
if (JSDebugErrorHook hook = cx->runtime->debugHooks.debugErrorHook)
reportError = hook(cx, message, &report, cx->runtime->debugHooks.debugErrorHookData);
/* Report the error */
if (reportError && cx->errorReporter)

View File

@ -110,6 +110,7 @@ bool called = false;
static JSTrapStatus
ThrowHook(JSContext *cx, JSScript *, jsbytecode *, jsval *rval, void *closure)
{
JS_ASSERT(!closure);
called = true;
JSObject *global = JS_GetGlobalForScopeChain(cx);
@ -126,9 +127,7 @@ BEGIN_TEST(testDebugger_throwHook)
uint32_t newopts = JS_GetOptions(cx) | JSOPTION_METHODJIT | JSOPTION_METHODJIT_ALWAYS;
uint32_t oldopts = JS_SetOptions(cx, newopts);
JSDebugHooks hooks = { 0 };
hooks.throwHook = ThrowHook;
JSDebugHooks *old = JS_SetContextDebugHooks(cx, &hooks);
CHECK(JS_SetThrowHook(rt, ThrowHook, NULL));
EXEC("function foo() { throw 3 };\n"
"for (var i = 0; i < 10; ++i) { \n"
" var x = <tag></tag>;\n"
@ -137,8 +136,7 @@ BEGIN_TEST(testDebugger_throwHook)
" } catch(e) {}\n"
"}\n");
CHECK(called);
JS_SetContextDebugHooks(cx, old);
CHECK(JS_SetThrowHook(rt, NULL, NULL));
JS_SetOptions(cx, oldopts);
return true;
}

View File

@ -800,7 +800,7 @@ JSRuntime::JSRuntime()
JS_INIT_CLIST(&contextList);
JS_INIT_CLIST(&debuggerList);
PodZero(&globalDebugHooks);
PodZero(&debugHooks);
PodZero(&atomState);
#if JS_STACK_GROWTH_DIRECTION > 0

View File

@ -359,11 +359,9 @@ ReportError(JSContext *cx, const char *message, JSErrorReport *reportp,
if (!JS_IsRunning(cx) ||
!js_ErrorToException(cx, message, reportp, callback, userRef)) {
js_ReportErrorAgain(cx, message, reportp);
} else if (cx->debugHooks->debugErrorHook && cx->errorReporter) {
JSDebugErrorHook hook = cx->debugHooks->debugErrorHook;
/* test local in case debugErrorHook changed on another thread */
if (hook)
hook(cx, message, reportp, cx->debugHooks->debugErrorHookData);
} else if (JSDebugErrorHook hook = cx->runtime->debugHooks.debugErrorHook) {
if (cx->errorReporter)
hook(cx, message, reportp, cx->runtime->debugHooks.debugErrorHookData);
}
}
@ -422,9 +420,9 @@ js_ReportOutOfMemory(JSContext *cx)
*/
cx->clearPendingException();
if (onError) {
JSDebugErrorHook hook = cx->debugHooks->debugErrorHook;
JSDebugErrorHook hook = cx->runtime->debugHooks.debugErrorHook;
if (hook &&
!hook(cx, msg, &report, cx->debugHooks->debugErrorHookData)) {
!hook(cx, msg, &report, cx->runtime->debugHooks.debugErrorHookData)) {
onError = NULL;
}
}
@ -754,12 +752,9 @@ js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *reportp)
* sending the error on to the regular ErrorReporter.
*/
if (onError) {
JSDebugErrorHook hook = cx->debugHooks->debugErrorHook;
if (hook &&
!hook(cx, cx->lastMessage, reportp,
cx->debugHooks->debugErrorHookData)) {
JSDebugErrorHook hook = cx->runtime->debugHooks.debugErrorHook;
if (hook && !hook(cx, cx->lastMessage, reportp, cx->runtime->debugHooks.debugErrorHookData))
onError = NULL;
}
}
if (onError)
onError(cx, cx->lastMessage, reportp);
@ -984,7 +979,6 @@ JSContext::JSContext(JSRuntime *rt)
outstandingRequests(0),
#endif
autoGCRooters(NULL),
debugHooks(&rt->globalDebugHooks),
securityCallbacks(NULL),
resolveFlags(0),
rngSeed(0),

View File

@ -475,7 +475,7 @@ struct JSRuntime : js::RuntimeFriendFields
}
/* Per runtime debug hooks -- see jsprvtd.h and jsdbgapi.h. */
JSDebugHooks globalDebugHooks;
JSDebugHooks debugHooks;
/* If true, new compartments are initially in debug mode. */
bool debugMode;
@ -714,8 +714,6 @@ struct JSArgumentFormatMap {
};
#endif
extern const JSDebugHooks js_NullDebugHooks; /* defined in jsdbgapi.cpp */
namespace js {
template <typename T> class Root;
@ -1015,9 +1013,6 @@ struct JSContext : js::ContextFriendFields
#endif /* JSGC_ROOT_ANALYSIS */
/* Debug hooks associated with the current context. */
const JSDebugHooks *debugHooks;
/* Security callbacks that override any defined on the runtime. */
JSSecurityCallbacks *securityCallbacks;

View File

@ -113,11 +113,11 @@ ScriptDebugPrologue(JSContext *cx, StackFrame *fp)
JS_ASSERT(fp == cx->fp());
if (fp->isFramePushedByExecute()) {
if (JSInterpreterHook hook = cx->debugHooks->executeHook)
fp->setHookData(hook(cx, Jsvalify(fp), true, 0, cx->debugHooks->executeHookData));
if (JSInterpreterHook hook = cx->runtime->debugHooks.executeHook)
fp->setHookData(hook(cx, Jsvalify(fp), true, 0, cx->runtime->debugHooks.executeHookData));
} else {
if (JSInterpreterHook hook = cx->debugHooks->callHook)
fp->setHookData(hook(cx, Jsvalify(fp), true, 0, cx->debugHooks->callHookData));
if (JSInterpreterHook hook = cx->runtime->debugHooks.callHook)
fp->setHookData(hook(cx, Jsvalify(fp), true, 0, cx->runtime->debugHooks.callHookData));
}
Value rval;
@ -148,10 +148,10 @@ ScriptDebugEpilogue(JSContext *cx, StackFrame *fp, bool okArg)
if (void *hookData = fp->maybeHookData()) {
if (fp->isFramePushedByExecute()) {
if (JSInterpreterHook hook = cx->debugHooks->executeHook)
if (JSInterpreterHook hook = cx->runtime->debugHooks.executeHook)
hook(cx, Jsvalify(fp), false, &ok, hookData);
} else {
if (JSInterpreterHook hook = cx->debugHooks->callHook)
if (JSInterpreterHook hook = cx->runtime->debugHooks.callHook)
hook(cx, Jsvalify(fp), false, &ok, hookData);
}
}
@ -238,8 +238,8 @@ JS_ClearAllTrapsForCompartment(JSContext *cx)
JS_PUBLIC_API(JSBool)
JS_SetInterrupt(JSRuntime *rt, JSInterruptHook hook, void *closure)
{
rt->globalDebugHooks.interruptHook = hook;
rt->globalDebugHooks.interruptHookData = closure;
rt->debugHooks.interruptHook = hook;
rt->debugHooks.interruptHookData = closure;
return JS_TRUE;
}
@ -247,11 +247,11 @@ JS_PUBLIC_API(JSBool)
JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *hoop, void **closurep)
{
if (hoop)
*hoop = rt->globalDebugHooks.interruptHook;
*hoop = rt->debugHooks.interruptHook;
if (closurep)
*closurep = rt->globalDebugHooks.interruptHookData;
rt->globalDebugHooks.interruptHook = 0;
rt->globalDebugHooks.interruptHookData = 0;
*closurep = rt->debugHooks.interruptHookData;
rt->debugHooks.interruptHook = 0;
rt->debugHooks.interruptHookData = 0;
return JS_TRUE;
}
@ -728,16 +728,16 @@ JS_GetScriptVersion(JSContext *cx, JSScript *script)
JS_PUBLIC_API(void)
JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata)
{
rt->globalDebugHooks.newScriptHook = hook;
rt->globalDebugHooks.newScriptHookData = callerdata;
rt->debugHooks.newScriptHook = hook;
rt->debugHooks.newScriptHookData = callerdata;
}
JS_PUBLIC_API(void)
JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
void *callerdata)
{
rt->globalDebugHooks.destroyScriptHook = hook;
rt->globalDebugHooks.destroyScriptHookData = callerdata;
rt->debugHooks.destroyScriptHook = hook;
rt->debugHooks.destroyScriptHookData = callerdata;
}
/***************************************************************************/
@ -928,48 +928,48 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda)
JS_PUBLIC_API(JSBool)
JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler handler, void *closure)
{
rt->globalDebugHooks.debuggerHandler = handler;
rt->globalDebugHooks.debuggerHandlerData = closure;
rt->debugHooks.debuggerHandler = handler;
rt->debugHooks.debuggerHandlerData = closure;
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure)
{
rt->globalDebugHooks.sourceHandler = handler;
rt->globalDebugHooks.sourceHandlerData = closure;
rt->debugHooks.sourceHandler = handler;
rt->debugHooks.sourceHandlerData = closure;
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure)
{
rt->globalDebugHooks.executeHook = hook;
rt->globalDebugHooks.executeHookData = closure;
rt->debugHooks.executeHook = hook;
rt->debugHooks.executeHookData = closure;
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure)
{
rt->globalDebugHooks.callHook = hook;
rt->globalDebugHooks.callHookData = closure;
rt->debugHooks.callHook = hook;
rt->debugHooks.callHookData = closure;
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure)
{
rt->globalDebugHooks.throwHook = hook;
rt->globalDebugHooks.throwHookData = closure;
rt->debugHooks.throwHook = hook;
rt->debugHooks.throwHookData = closure;
return JS_TRUE;
}
JS_PUBLIC_API(JSBool)
JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure)
{
rt->globalDebugHooks.debugErrorHook = hook;
rt->globalDebugHooks.debugErrorHookData = closure;
rt->debugHooks.debugErrorHook = hook;
rt->debugHooks.debugErrorHookData = closure;
return JS_TRUE;
}
@ -1086,25 +1086,7 @@ js_RevertVersion(JSContext *cx)
JS_PUBLIC_API(const JSDebugHooks *)
JS_GetGlobalDebugHooks(JSRuntime *rt)
{
return &rt->globalDebugHooks;
}
const JSDebugHooks js_NullDebugHooks = {};
JS_PUBLIC_API(JSDebugHooks *)
JS_SetContextDebugHooks(JSContext *cx, const JSDebugHooks *hooks)
{
JS_ASSERT(hooks);
JSDebugHooks *old = const_cast<JSDebugHooks *>(cx->debugHooks);
cx->debugHooks = hooks;
return old;
}
JS_PUBLIC_API(JSDebugHooks *)
JS_ClearContextDebugHooks(JSContext *cx)
{
return JS_SetContextDebugHooks(cx, &js_NullDebugHooks);
return &rt->debugHooks;
}
/************************************************************************/

View File

@ -477,13 +477,6 @@ js_RevertVersion(JSContext *cx);
extern JS_PUBLIC_API(const JSDebugHooks *)
JS_GetGlobalDebugHooks(JSRuntime *rt);
extern JS_PUBLIC_API(JSDebugHooks *)
JS_SetContextDebugHooks(JSContext *cx, const JSDebugHooks *hooks);
/* Disable debug hooks for this context. */
extern JS_PUBLIC_API(JSDebugHooks *)
JS_ClearContextDebugHooks(JSContext *cx);
/**
* Start any profilers that are available and have been configured on for this
* platform. This is NOT thread safe.

View File

@ -591,17 +591,17 @@ VersionSetXML(JSVersion version, bool enable)
JS_FRIEND_API(bool)
CanCallContextDebugHandler(JSContext *cx)
{
return cx->debugHooks && cx->debugHooks->debuggerHandler;
return !!cx->runtime->debugHooks.debuggerHandler;
}
JS_FRIEND_API(JSTrapStatus)
CallContextDebugHandler(JSContext *cx, JSScript *script, jsbytecode *bc, Value *rval)
{
if (!CanCallContextDebugHandler(cx))
if (!cx->runtime->debugHooks.debuggerHandler)
return JSTRAP_RETURN;
return cx->debugHooks->debuggerHandler(cx, script, bc, rval,
cx->debugHooks->debuggerHandlerData);
return cx->runtime->debugHooks.debuggerHandler(cx, script, bc, rval,
cx->runtime->debugHooks.debuggerHandlerData);
}
#ifdef JS_THREADSAFE

View File

@ -1444,7 +1444,7 @@ js::Interpret(JSContext *cx, StackFrame *entryFrame, InterpMode interpMode)
#define CHECK_INTERRUPT_HANDLER() \
JS_BEGIN_MACRO \
if (cx->debugHooks->interruptHook) \
if (cx->runtime->debugHooks.interruptHook) \
ENABLE_INTERRUPTS(); \
JS_END_MACRO
@ -1591,12 +1591,12 @@ js::Interpret(JSContext *cx, StackFrame *entryFrame, InterpMode interpMode)
moreInterrupts = true;
}
JSInterruptHook hook = cx->debugHooks->interruptHook;
JSInterruptHook hook = cx->runtime->debugHooks.interruptHook;
if (hook || script->stepModeEnabled()) {
Value rval;
JSTrapStatus status = JSTRAP_CONTINUE;
if (hook)
status = hook(cx, script, regs.pc, &rval, cx->debugHooks->interruptHookData);
status = hook(cx, script, regs.pc, &rval, cx->runtime->debugHooks.interruptHookData);
if (status == JSTRAP_CONTINUE && script->stepModeEnabled())
status = Debugger::onSingleStep(cx, &rval);
switch (status) {
@ -3671,8 +3671,8 @@ BEGIN_CASE(JSOP_DEBUGGER)
{
JSTrapStatus st = JSTRAP_CONTINUE;
Value rval;
if (JSDebuggerHandler handler = cx->debugHooks->debuggerHandler)
st = handler(cx, script, regs.pc, &rval, cx->debugHooks->debuggerHandlerData);
if (JSDebuggerHandler handler = cx->runtime->debugHooks.debuggerHandler)
st = handler(cx, script, regs.pc, &rval, cx->runtime->debugHooks.debuggerHandlerData);
if (st == JSTRAP_CONTINUE)
st = Debugger::onDebuggerStatement(cx, &rval);
switch (st) {
@ -4231,13 +4231,13 @@ END_CASE(JSOP_ARRAYPUSH)
atoms = script->atoms;
/* Call debugger throw hook if set. */
if (cx->debugHooks->throwHook || !cx->compartment->getDebuggees().empty()) {
if (cx->runtime->debugHooks.throwHook || !cx->compartment->getDebuggees().empty()) {
Value rval;
JSTrapStatus st = Debugger::onExceptionUnwind(cx, &rval);
if (st == JSTRAP_CONTINUE) {
handler = cx->debugHooks->throwHook;
handler = cx->runtime->debugHooks.throwHook;
if (handler)
st = handler(cx, script, regs.pc, &rval, cx->debugHooks->throwHookData);
st = handler(cx, script, regs.pc, &rval, cx->runtime->debugHooks.throwHookData);
}
switch (st) {

View File

@ -1433,10 +1433,10 @@ JS_FRIEND_API(void)
js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun)
{
JS_ASSERT(!script->callDestroyHook);
if (JSNewScriptHook hook = cx->debugHooks->newScriptHook) {
if (JSNewScriptHook hook = cx->runtime->debugHooks.newScriptHook) {
AutoKeepAtoms keep(cx->runtime);
hook(cx, script->filename, script->lineno, script, fun,
cx->debugHooks->newScriptHookData);
cx->runtime->debugHooks.newScriptHookData);
}
script->callDestroyHook = true;
}
@ -1447,8 +1447,8 @@ js_CallDestroyScriptHook(JSContext *cx, JSScript *script)
if (!script->callDestroyHook)
return;
if (JSDestroyScriptHook hook = cx->debugHooks->destroyScriptHook)
hook(cx, script, cx->debugHooks->destroyScriptHookData);
if (JSDestroyScriptHook hook = cx->runtime->debugHooks.destroyScriptHook)
hook(cx, script, cx->runtime->debugHooks.destroyScriptHookData);
script->callDestroyHook = false;
JS_ClearScriptTraps(cx, script);
}

View File

@ -531,13 +531,13 @@ js_InternalThrow(VMFrame &f)
for (;;) {
if (cx->isExceptionPending()) {
// Call the throw hook if necessary
JSThrowHook handler = cx->debugHooks->throwHook;
JSThrowHook handler = cx->runtime->debugHooks.throwHook;
if (handler || !cx->compartment->getDebuggees().empty()) {
Value rval;
JSTrapStatus st = Debugger::onExceptionUnwind(cx, &rval);
if (st == JSTRAP_CONTINUE && handler) {
st = handler(cx, cx->fp()->script(), cx->regs().pc, &rval,
cx->debugHooks->throwHookData);
cx->runtime->debugHooks.throwHookData);
}
switch (st) {

View File

@ -845,12 +845,12 @@ stubs::Mod(VMFrame &f)
void JS_FASTCALL
stubs::DebuggerStatement(VMFrame &f, jsbytecode *pc)
{
JSDebuggerHandler handler = f.cx->debugHooks->debuggerHandler;
JSDebuggerHandler handler = f.cx->runtime->debugHooks.debuggerHandler;
if (handler || !f.cx->compartment->getDebuggees().empty()) {
JSTrapStatus st = JSTRAP_CONTINUE;
Value rval;
if (handler)
st = handler(f.cx, f.script(), pc, &rval, f.cx->debugHooks->debuggerHandlerData);
st = handler(f.cx, f.script(), pc, &rval, f.cx->runtime->debugHooks.debuggerHandlerData);
if (st == JSTRAP_CONTINUE)
st = Debugger::onDebuggerStatement(f.cx, &rval);
@ -908,9 +908,9 @@ stubs::Trap(VMFrame &f, uint32_t trapTypes)
* single step mode may be paused without recompiling by
* setting the interruptHook to NULL.
*/
JSInterruptHook hook = f.cx->debugHooks->interruptHook;
JSInterruptHook hook = f.cx->runtime->debugHooks.interruptHook;
if (hook)
result = hook(f.cx, f.script(), f.pc(), &rval, f.cx->debugHooks->interruptHookData);
result = hook(f.cx, f.script(), f.pc(), &rval, f.cx->runtime->debugHooks.interruptHookData);
if (result == JSTRAP_CONTINUE)
result = Debugger::onSingleStep(f.cx, &rval);