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/text/StringHash.h>
48 class ScriptDebugListener;
52 class ScriptDebugServer {
53 WTF_MAKE_NONCOPYABLE(ScriptDebugServer);
55 String setBreakpoint(const String& sourceID, const ScriptBreakpoint&, int* actualLineNumber, int* actualColumnNumber);
56 void removeBreakpoint(const String& breakpointId);
57 void clearBreakpoints();
58 void setBreakpointsActivated(bool activated);
59 void activateBreakpoints() { setBreakpointsActivated(true); }
60 void deactivateBreakpoints() { setBreakpointsActivated(false); }
62 enum PauseOnExceptionsState {
63 DontPauseOnExceptions,
65 PauseOnUncaughtExceptions
67 PauseOnExceptionsState pauseOnExceptionsState();
68 void setPauseOnExceptionsState(PauseOnExceptionsState pauseOnExceptionsState);
70 void setPauseOnNextStatement(bool pause);
72 void continueProgram();
73 void stepIntoStatement();
74 void stepOverStatement();
75 void stepOutOfFunction();
77 bool setScriptSource(const String& sourceID, const String& newContent, bool preview, String* error, ScriptValue* newCallFrames, ScriptObject* result);
79 void recompileAllJSFunctionsSoon() { }
80 void recompileAllJSFunctions(Timer<ScriptDebugServer>* = 0) { }
85 virtual void run() = 0;
87 static void interruptAndRun(PassOwnPtr<Task>);
88 void runPendingTasks();
92 ~ScriptDebugServer() { }
94 ScriptValue currentCallFrame();
96 virtual ScriptDebugListener* getDebugListenerForContext(v8::Handle<v8::Context>) = 0;
97 virtual void runMessageLoopOnPause(v8::Handle<v8::Context>) = 0;
98 virtual void quitMessageLoopOnPause() = 0;
100 static v8::Handle<v8::Value> breakProgramCallback(const v8::Arguments& args);
101 void breakProgram(v8::Handle<v8::Object> executionState, v8::Handle<v8::Value> exception);
103 static void v8DebugEventCallback(const v8::Debug::EventDetails& eventDetails);
104 void handleV8DebugEvent(const v8::Debug::EventDetails& eventDetails);
106 void dispatchDidParseSource(ScriptDebugListener* listener, v8::Handle<v8::Object> sourceObject);
108 void ensureDebuggerScriptCompiled();
112 PauseOnExceptionsState m_pauseOnExceptionsState;
113 OwnHandle<v8::Object> m_debuggerScript;
114 OwnHandle<v8::Object> m_executionState;
115 v8::Local<v8::Context> m_pausedContext;
117 bool m_breakpointsActivated;
118 OwnHandle<v8::FunctionTemplate> m_breakProgramCallbackTemplate;
121 } // namespace WebCore
123 #endif // ENABLE(JAVASCRIPT_DEBUGGER)
125 #endif // ScriptDebugServer_h