]> git.saurik.com Git - apple/javascriptcore.git/blame - kjs/debugger.cpp
JavaScriptCore-466.1.tar.gz
[apple/javascriptcore.git] / kjs / debugger.cpp
CommitLineData
b37bf2e1
A
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
5 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23#include "config.h"
24#include "debugger.h"
25
26#include "JSGlobalObject.h"
27#include "internal.h"
28#include "ustring.h"
29
30using namespace KJS;
31
32// ------------------------------ Debugger -------------------------------------
33
34namespace KJS {
35 struct AttachedGlobalObject
36 {
37 public:
38 AttachedGlobalObject(JSGlobalObject* o, AttachedGlobalObject* ai) : globalObj(o), next(ai) { ++Debugger::debuggersPresent; }
39 ~AttachedGlobalObject() { --Debugger::debuggersPresent; }
40 JSGlobalObject* globalObj;
41 AttachedGlobalObject* next;
42 };
43
44}
45
46int Debugger::debuggersPresent = 0;
47
48Debugger::Debugger()
49{
50 rep = new DebuggerImp();
51}
52
53Debugger::~Debugger()
54{
55 detach(0);
56 delete rep;
57}
58
59void Debugger::attach(JSGlobalObject* globalObject)
60{
61 Debugger* other = globalObject->debugger();
62 if (other == this)
63 return;
64 if (other)
65 other->detach(globalObject);
66 globalObject->setDebugger(this);
67 rep->globalObjects = new AttachedGlobalObject(globalObject, rep->globalObjects);
68}
69
70void Debugger::detach(JSGlobalObject* globalObj)
71{
72 // iterate the addresses where AttachedGlobalObject pointers are stored
73 // so we can unlink items from the list
74 AttachedGlobalObject **p = &rep->globalObjects;
75 AttachedGlobalObject *q;
76 while ((q = *p)) {
77 if (!globalObj || q->globalObj == globalObj) {
78 *p = q->next;
79 q->globalObj->setDebugger(0);
80 delete q;
81 } else
82 p = &q->next;
83 }
84
85 if (globalObj)
86 latestExceptions.remove(globalObj);
87 else
88 latestExceptions.clear();
89}
90
91bool Debugger::hasHandledException(ExecState *exec, JSValue *exception)
92{
93 if (latestExceptions.get(exec->dynamicGlobalObject()).get() == exception)
94 return true;
95
96 latestExceptions.set(exec->dynamicGlobalObject(), exception);
97 return false;
98}
99
100bool Debugger::sourceParsed(ExecState*, int /*sourceId*/, const UString &/*sourceURL*/,
101 const UString &/*source*/, int /*startingLineNumber*/, int /*errorLine*/, const UString & /*errorMsg*/)
102{
103 return true;
104}
105
106bool Debugger::sourceUnused(ExecState*, int /*sourceId*/)
107{
108 return true;
109}
110
111bool Debugger::exception(ExecState*, int /*sourceId*/, int /*lineno*/,
112 JSValue* /*exception */)
113{
114 return true;
115}
116
117bool Debugger::atStatement(ExecState*, int /*sourceId*/, int /*firstLine*/,
118 int /*lastLine*/)
119{
120 return true;
121}
122
123bool Debugger::callEvent(ExecState*, int /*sourceId*/, int /*lineno*/,
124 JSObject* /*function*/, const List &/*args*/)
125{
126 return true;
127}
128
129bool Debugger::returnEvent(ExecState*, int /*sourceId*/, int /*lineno*/,
130 JSObject* /*function*/)
131{
132 return true;
133}
134