2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef JavaScriptDebugServer_h
30 #define JavaScriptDebugServer_h
32 #include <kjs/debugger.h>
34 #include <wtf/HashMap.h>
35 #include <wtf/HashSet.h>
36 #include <wtf/RefPtr.h>
39 class DebuggerCallFrame
;
49 class JavaScriptCallFrame
;
50 class JavaScriptDebugListener
;
52 class JavaScriptDebugServer
: JSC::Debugger
{
54 static JavaScriptDebugServer
& shared();
56 void addListener(JavaScriptDebugListener
*);
57 void removeListener(JavaScriptDebugListener
*);
59 void addListener(JavaScriptDebugListener
*, Page
*);
60 void removeListener(JavaScriptDebugListener
*, Page
*);
62 void addBreakpoint(intptr_t sourceID
, unsigned lineNumber
);
63 void removeBreakpoint(intptr_t sourceID
, unsigned lineNumber
);
64 bool hasBreakpoint(intptr_t sourceID
, unsigned lineNumber
) const;
65 void clearBreakpoints();
67 bool pauseOnExceptions() const { return m_pauseOnExceptions
; }
68 void setPauseOnExceptions(bool);
71 void continueProgram();
72 void stepIntoStatement();
73 void stepOverStatement();
74 void stepOutOfFunction();
76 JavaScriptCallFrame
* currentCallFrame();
78 void pageCreated(Page
*);
80 typedef HashSet
<JavaScriptDebugListener
*> ListenerSet
;
81 typedef void (JavaScriptDebugListener::*JavaScriptExecutionCallback
)();
84 JavaScriptDebugServer();
85 ~JavaScriptDebugServer();
87 bool hasListeners() const { return !m_listeners
.isEmpty() || !m_pageListenersMap
.isEmpty(); }
88 bool hasListenersInterestedInPage(Page
*);
90 void setJavaScriptPaused(const PageGroup
&, bool paused
);
91 void setJavaScriptPaused(Page
*, bool paused
);
92 void setJavaScriptPaused(Frame
*, bool paused
);
93 void setJavaScriptPaused(FrameView
*, bool paused
);
95 void dispatchFunctionToListeners(JavaScriptExecutionCallback
, Page
*);
96 void pauseIfNeeded(Page
*);
98 virtual void sourceParsed(JSC::ExecState
*, const JSC::SourceCode
&, int errorLine
, const JSC::UString
& errorMsg
);
99 virtual void callEvent(const JSC::DebuggerCallFrame
&, intptr_t sourceID
, int lineNumber
);
100 virtual void atStatement(const JSC::DebuggerCallFrame
&, intptr_t sourceID
, int firstLine
);
101 virtual void returnEvent(const JSC::DebuggerCallFrame
&, intptr_t sourceID
, int lineNumber
);
102 virtual void exception(const JSC::DebuggerCallFrame
&, intptr_t sourceID
, int lineNumber
);
103 virtual void willExecuteProgram(const JSC::DebuggerCallFrame
&, intptr_t sourceID
, int lineno
);
104 virtual void didExecuteProgram(const JSC::DebuggerCallFrame
&, intptr_t sourceID
, int lineno
);
105 virtual void didReachBreakpoint(const JSC::DebuggerCallFrame
&, intptr_t sourceID
, int lineno
);
107 typedef HashMap
<Page
*, ListenerSet
*> PageListenersMap
;
108 PageListenersMap m_pageListenersMap
;
109 ListenerSet m_listeners
;
110 bool m_callingListeners
;
111 bool m_pauseOnExceptions
;
112 bool m_pauseOnNextStatement
;
114 bool m_doneProcessingDebuggerEvents
;
115 JavaScriptCallFrame
* m_pauseOnCallFrame
;
116 RefPtr
<JavaScriptCallFrame
> m_currentCallFrame
;
117 HashMap
<RefPtr
<Frame
>, PausedTimeouts
*> m_pausedTimeouts
;
118 HashMap
<intptr_t, HashSet
<unsigned>*> m_breakpoints
;
121 } // namespace WebCore
123 #endif // JavaScriptDebugServer_h