#include "config.h"
#include "debugger.h"
#include "JSGlobalObject.h"
#include "internal.h"
#include "ustring.h"
using namespace KJS;
namespace KJS {
struct AttachedGlobalObject
{
public:
AttachedGlobalObject(JSGlobalObject* o, AttachedGlobalObject* ai) : globalObj(o), next(ai) { ++Debugger::debuggersPresent; }
~AttachedGlobalObject() { --Debugger::debuggersPresent; }
JSGlobalObject* globalObj;
AttachedGlobalObject* next;
};
}
int Debugger::debuggersPresent = 0;
Debugger::Debugger()
{
rep = new DebuggerImp();
}
Debugger::~Debugger()
{
detach(0);
delete rep;
}
void Debugger::attach(JSGlobalObject* globalObject)
{
Debugger* other = globalObject->debugger();
if (other == this)
return;
if (other)
other->detach(globalObject);
globalObject->setDebugger(this);
rep->globalObjects = new AttachedGlobalObject(globalObject, rep->globalObjects);
}
void Debugger::detach(JSGlobalObject* globalObj)
{
AttachedGlobalObject **p = &rep->globalObjects;
AttachedGlobalObject *q;
while ((q = *p)) {
if (!globalObj || q->globalObj == globalObj) {
*p = q->next;
q->globalObj->setDebugger(0);
delete q;
} else
p = &q->next;
}
if (globalObj)
latestExceptions.remove(globalObj);
else
latestExceptions.clear();
}
bool Debugger::hasHandledException(ExecState *exec, JSValue *exception)
{
if (latestExceptions.get(exec->dynamicGlobalObject()).get() == exception)
return true;
latestExceptions.set(exec->dynamicGlobalObject(), exception);
return false;
}
bool Debugger::sourceParsed(ExecState*, int , const UString &,
const UString &, int , int , const UString & )
{
return true;
}
bool Debugger::sourceUnused(ExecState*, int )
{
return true;
}
bool Debugger::exception(ExecState*, int , int ,
JSValue* )
{
return true;
}
bool Debugger::atStatement(ExecState*, int , int ,
int )
{
return true;
}
bool Debugger::callEvent(ExecState*, int , int ,
JSObject* , const List &)
{
return true;
}
bool Debugger::returnEvent(ExecState*, int , int ,
JSObject* )
{
return true;
}