c3920ec54d973c3ddae05597a7674dadca423430
[framework/web/webkit-efl.git] / Source / WebCore / bindings / v8 / ScriptDebugServer.h
1 /*
2  * Copyright (c) 2010, Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 #ifndef ScriptDebugServer_h
32 #define ScriptDebugServer_h
33
34 #if ENABLE(JAVASCRIPT_DEBUGGER)
35
36 #include "OwnHandle.h"
37 #include "PlatformString.h"
38 #include "ScriptBreakpoint.h"
39 #include "Timer.h"
40 #include <v8-debug.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>
46
47 namespace WebCore {
48
49 class ScriptDebugListener;
50 class ScriptObject;
51 class ScriptValue;
52
53 class ScriptDebugServer {
54     WTF_MAKE_NONCOPYABLE(ScriptDebugServer);
55 public:
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); }
62
63     enum PauseOnExceptionsState {
64         DontPauseOnExceptions,
65         PauseOnAllExceptions,
66         PauseOnUncaughtExceptions
67     };
68     PauseOnExceptionsState pauseOnExceptionsState();
69     void setPauseOnExceptionsState(PauseOnExceptionsState pauseOnExceptionsState);
70
71     void setPauseOnNextStatement(bool pause);
72     void breakProgram();
73     void continueProgram();
74     void stepIntoStatement();
75     void stepOverStatement();
76     void stepOutOfFunction();
77
78     bool canSetScriptSource();
79     bool setScriptSource(const String& sourceID, const String& newContent, bool preview, String* error, ScriptValue* newCallFrames, ScriptObject* result);
80
81     void recompileAllJSFunctionsSoon() { }
82     void recompileAllJSFunctions(Timer<ScriptDebugServer>* = 0) { }
83
84     class Task {
85     public:
86         virtual ~Task() { }
87         virtual void run() = 0;
88     };
89     static void interruptAndRun(PassOwnPtr<Task>);
90     void runPendingTasks();
91
92 protected:
93     ScriptDebugServer();
94     ~ScriptDebugServer() { }
95     
96     ScriptValue currentCallFrame();
97
98     virtual ScriptDebugListener* getDebugListenerForContext(v8::Handle<v8::Context>) = 0;
99     virtual void runMessageLoopOnPause(v8::Handle<v8::Context>) = 0;
100     virtual void quitMessageLoopOnPause() = 0;
101
102     static v8::Handle<v8::Value> breakProgramCallback(const v8::Arguments& args);
103     void breakProgram(v8::Handle<v8::Object> executionState, v8::Handle<v8::Value> exception);
104
105     static void v8DebugEventCallback(const v8::Debug::EventDetails& eventDetails);
106     void handleV8DebugEvent(const v8::Debug::EventDetails& eventDetails);
107
108     void dispatchDidParseSource(ScriptDebugListener* listener, v8::Handle<v8::Object> sourceObject);
109
110     void ensureDebuggerScriptCompiled();
111     
112     bool isPaused();
113
114     PauseOnExceptionsState m_pauseOnExceptionsState;
115     OwnHandle<v8::Object> m_debuggerScript;
116     OwnHandle<v8::Object> m_executionState;
117     v8::Local<v8::Context> m_pausedContext;
118
119     bool m_breakpointsActivated;
120     OwnHandle<v8::FunctionTemplate> m_breakProgramCallbackTemplate;
121 };
122
123 } // namespace WebCore
124
125 #endif // ENABLE(JAVASCRIPT_DEBUGGER)
126
127 #endif // ScriptDebugServer_h