2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2010-2011 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef ScriptDebugServer_h
31 #define ScriptDebugServer_h
33 #if ENABLE(JAVASCRIPT_DEBUGGER)
35 #include "ScriptDebugListener.h"
36 #include "PlatformString.h"
37 #include "ScriptBreakpoint.h"
40 #include <debugger/Debugger.h>
41 #include <runtime/UString.h>
42 #include <wtf/HashMap.h>
43 #include <wtf/HashSet.h>
44 #include <wtf/RefPtr.h>
45 #include <wtf/text/TextPosition.h>
48 class DebuggerCallFrame;
53 class JavaScriptCallFrame;
54 class ScriptDebugListener;
58 class ScriptDebugServer : protected JSC::Debugger {
59 WTF_MAKE_NONCOPYABLE(ScriptDebugServer); WTF_MAKE_FAST_ALLOCATED;
61 String setBreakpoint(const String& sourceID, const ScriptBreakpoint&, int* actualLineNumber, int* actualColumnNumber);
62 void removeBreakpoint(const String& breakpointId);
63 void clearBreakpoints();
64 void setBreakpointsActivated(bool activated);
65 void activateBreakpoints() { setBreakpointsActivated(true); }
66 void deactivateBreakpoints() { setBreakpointsActivated(false); }
68 enum PauseOnExceptionsState {
69 DontPauseOnExceptions,
71 PauseOnUncaughtExceptions
73 PauseOnExceptionsState pauseOnExceptionsState() const { return m_pauseOnExceptionsState; }
74 void setPauseOnExceptionsState(PauseOnExceptionsState);
76 void setPauseOnNextStatement(bool pause);
78 void continueProgram();
79 void stepIntoStatement();
80 void stepOverStatement();
81 void stepOutOfFunction();
83 bool setScriptSource(const String& sourceID, const String& newContent, bool preview, String* error, ScriptValue* newCallFrames, ScriptObject* result);
85 void recompileAllJSFunctionsSoon();
86 virtual void recompileAllJSFunctions(Timer<ScriptDebugServer>* = 0) = 0;
89 typedef HashSet<ScriptDebugListener*> ListenerSet;
90 typedef void (ScriptDebugServer::*JavaScriptExecutionCallback)(ScriptDebugListener*);
95 virtual ListenerSet* getListenersForGlobalObject(JSC::JSGlobalObject*) = 0;
96 virtual void didPause(JSC::JSGlobalObject*) = 0;
97 virtual void didContinue(JSC::JSGlobalObject*) = 0;
99 bool hasBreakpoint(intptr_t sourceID, const TextPosition0&) const;
101 void dispatchFunctionToListeners(JavaScriptExecutionCallback, JSC::JSGlobalObject*);
102 void dispatchFunctionToListeners(const ListenerSet& listeners, JavaScriptExecutionCallback callback);
103 void dispatchDidPause(ScriptDebugListener*);
104 void dispatchDidContinue(ScriptDebugListener*);
105 void dispatchDidParseSource(const ListenerSet& listeners, JSC::SourceProvider*, bool isContentScript);
106 void dispatchFailedToParseSource(const ListenerSet& listeners, JSC::SourceProvider*, int errorLine, const String& errorMessage);
108 void createCallFrameAndPauseIfNeeded(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
109 void updateCallFrameAndPauseIfNeeded(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
110 void pauseIfNeeded(JSC::JSGlobalObject* dynamicGlobalObject);
112 virtual void detach(JSC::JSGlobalObject*);
114 virtual void sourceParsed(JSC::ExecState*, JSC::SourceProvider*, int errorLine, const JSC::UString& errorMsg);
115 virtual void callEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
116 virtual void atStatement(const JSC::DebuggerCallFrame&, intptr_t sourceID, int firstLine);
117 virtual void returnEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
118 virtual void exception(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, bool hasHandler);
119 virtual void willExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno);
120 virtual void didExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno);
121 virtual void didReachBreakpoint(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno);
123 typedef HashMap<Page*, ListenerSet*> PageListenersMap;
124 typedef HashMap<long, ScriptBreakpoint> LineToBreakpointMap;
125 typedef HashMap<intptr_t, LineToBreakpointMap> SourceIdToBreakpointsMap;
127 PageListenersMap m_pageListenersMap;
128 bool m_callingListeners;
129 PauseOnExceptionsState m_pauseOnExceptionsState;
130 bool m_pauseOnNextStatement;
132 bool m_doneProcessingDebuggerEvents;
133 bool m_breakpointsActivated;
134 JavaScriptCallFrame* m_pauseOnCallFrame;
135 RefPtr<JavaScriptCallFrame> m_currentCallFrame;
136 SourceIdToBreakpointsMap m_sourceIdToBreakpoints;
137 Timer<ScriptDebugServer> m_recompileTimer;
140 } // namespace WebCore
142 #endif // ENABLE(JAVASCRIPT_DEBUGGER)
144 #endif // ScriptDebugServer_h