2 * Copyright (c) 2010, Google 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 are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef ScriptDebugServer_h
32 #define ScriptDebugServer_h
34 #if ENABLE(JAVASCRIPT_DEBUGGER)
36 #include "OwnHandle.h"
37 #include "PlatformString.h"
38 #include "ScriptBreakpoint.h"
41 #include <wtf/HashMap.h>
42 #include <wtf/Noncopyable.h>
43 #include <wtf/PassOwnPtr.h>
44 #include <wtf/Vector.h>
45 #include <wtf/text/StringHash.h>
49 class ScriptDebugListener;
53 class ScriptDebugServer {
54 WTF_MAKE_NONCOPYABLE(ScriptDebugServer);
56 String setBreakpoint(const String& sourceID, const ScriptBreakpoint&, int* actualLineNumber, int* actualColumnNumber);
57 void removeBreakpoint(const String& breakpointId);
58 void clearBreakpoints();
59 void setBreakpointsActivated(bool activated);
60 void activateBreakpoints() { setBreakpointsActivated(true); }
61 void deactivateBreakpoints() { setBreakpointsActivated(false); }
63 enum PauseOnExceptionsState {
64 DontPauseOnExceptions,
66 PauseOnUncaughtExceptions
68 PauseOnExceptionsState pauseOnExceptionsState();
69 void setPauseOnExceptionsState(PauseOnExceptionsState pauseOnExceptionsState);
71 void setPauseOnNextStatement(bool pause);
73 void continueProgram();
74 void stepIntoStatement();
75 void stepOverStatement();
76 void stepOutOfFunction();
78 bool canSetScriptSource();
79 bool setScriptSource(const String& sourceID, const String& newContent, bool preview, String* error, ScriptValue* newCallFrames, ScriptObject* result);
81 void recompileAllJSFunctionsSoon() { }
82 void recompileAllJSFunctions(Timer<ScriptDebugServer>* = 0) { }
87 virtual void run() = 0;
89 static void interruptAndRun(PassOwnPtr<Task>);
90 void runPendingTasks();
94 ~ScriptDebugServer() { }
96 ScriptValue currentCallFrame();
98 virtual ScriptDebugListener* getDebugListenerForContext(v8::Handle<v8::Context>) = 0;
99 virtual void runMessageLoopOnPause(v8::Handle<v8::Context>) = 0;
100 virtual void quitMessageLoopOnPause() = 0;
102 static v8::Handle<v8::Value> breakProgramCallback(const v8::Arguments& args);
103 void breakProgram(v8::Handle<v8::Object> executionState, v8::Handle<v8::Value> exception);
105 static void v8DebugEventCallback(const v8::Debug::EventDetails& eventDetails);
106 void handleV8DebugEvent(const v8::Debug::EventDetails& eventDetails);
108 void dispatchDidParseSource(ScriptDebugListener* listener, v8::Handle<v8::Object> sourceObject);
110 void ensureDebuggerScriptCompiled();
114 PauseOnExceptionsState m_pauseOnExceptionsState;
115 OwnHandle<v8::Object> m_debuggerScript;
116 OwnHandle<v8::Object> m_executionState;
117 v8::Local<v8::Context> m_pausedContext;
119 bool m_breakpointsActivated;
120 OwnHandle<v8::FunctionTemplate> m_breakProgramCallbackTemplate;
123 } // namespace WebCore
125 #endif // ENABLE(JAVASCRIPT_DEBUGGER)
127 #endif // ScriptDebugServer_h