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 "ScriptBreakpoint.h"
38
#include <debugger/Debugger.h>
39
#include <wtf/HashMap.h>
40
#include <wtf/HashSet.h>
41
#include <wtf/RefPtr.h>
42
#include <wtf/Vector.h>
43
#include <wtf/text/TextPosition.h>
44
#include <wtf/text/WTFString.h>
47
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 canSetScriptSource();
84
bool setScriptSource(const String& sourceID, const String& newContent, bool preview, String* error, ScriptValue* newCallFrames, ScriptObject* result);
85
void updateCallStack(ScriptValue* callFrame);
87
bool causesRecompilation() { return true; }
88
bool supportsSeparateScriptCompilationAndExecution() { return false; }
90
void recompileAllJSFunctionsSoon();
91
virtual void recompileAllJSFunctions(Timer<ScriptDebugServer>* = 0) = 0;
93
bool isPaused() { return m_paused; }
95
void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionMessage);
96
void clearCompiledScripts();
97
void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage);
100
WTF_MAKE_FAST_ALLOCATED;
103
virtual void run() = 0;
107
typedef HashSet<ScriptDebugListener*> ListenerSet;
108
typedef void (ScriptDebugServer::*JavaScriptExecutionCallback)(ScriptDebugListener*);
111
~ScriptDebugServer();
113
virtual ListenerSet* getListenersForGlobalObject(JSC::JSGlobalObject*) = 0;
114
virtual void didPause(JSC::JSGlobalObject*) = 0;
115
virtual void didContinue(JSC::JSGlobalObject*) = 0;
117
virtual void runEventLoopWhilePaused() = 0;
119
virtual bool isContentScript(JSC::ExecState*);
121
bool hasBreakpoint(intptr_t sourceID, const TextPosition&) const;
123
void dispatchFunctionToListeners(JavaScriptExecutionCallback, JSC::JSGlobalObject*);
124
void dispatchFunctionToListeners(const ListenerSet& listeners, JavaScriptExecutionCallback callback);
125
void dispatchDidPause(ScriptDebugListener*);
126
void dispatchDidContinue(ScriptDebugListener*);
127
void dispatchDidParseSource(const ListenerSet& listeners, JSC::SourceProvider*, bool isContentScript);
128
void dispatchFailedToParseSource(const ListenerSet& listeners, JSC::SourceProvider*, int errorLine, const String& errorMessage);
130
void createCallFrame(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, int columnNumber);
131
void updateCallFrameAndPauseIfNeeded(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, int columnNumber);
132
void pauseIfNeeded(JSC::JSGlobalObject* dynamicGlobalObject);
134
virtual void detach(JSC::JSGlobalObject*);
136
virtual void sourceParsed(JSC::ExecState*, JSC::SourceProvider*, int errorLine, const String& errorMsg);
137
virtual void callEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, int columnNumber);
138
virtual void atStatement(const JSC::DebuggerCallFrame&, intptr_t sourceID, int firstLine, int columnNumber);
139
virtual void returnEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, int columnNumber);
140
virtual void exception(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, int columnNumber, bool hasHandler);
141
virtual void willExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno, int columnNumber);
142
virtual void didExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno, int columnNumber);
143
virtual void didReachBreakpoint(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno, int columnNumber);
145
typedef Vector<ScriptBreakpoint> BreakpointsInLine;
146
typedef HashMap<long, BreakpointsInLine> LineToBreakpointMap;
147
typedef HashMap<intptr_t, LineToBreakpointMap> SourceIdToBreakpointsMap;
149
bool m_callingListeners;
150
PauseOnExceptionsState m_pauseOnExceptionsState;
151
bool m_pauseOnNextStatement;
153
bool m_doneProcessingDebuggerEvents;
154
bool m_breakpointsActivated;
155
JavaScriptCallFrame* m_pauseOnCallFrame;
156
RefPtr<JavaScriptCallFrame> m_currentCallFrame;
157
SourceIdToBreakpointsMap m_sourceIdToBreakpoints;
158
Timer<ScriptDebugServer> m_recompileTimer;
160
int m_lastExecutedLine;
161
intptr_t m_lastExecutedSourceId;
164
} // namespace WebCore
166
#endif // ENABLE(JAVASCRIPT_DEBUGGER)
168
#endif // ScriptDebugServer_h