OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "wtf/PassOwnPtr.h" | 41 #include "wtf/PassOwnPtr.h" |
42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
43 #include "wtf/text/StringHash.h" | 43 #include "wtf/text/StringHash.h" |
44 #include "wtf/text/WTFString.h" | 44 #include "wtf/text/WTFString.h" |
45 | 45 |
46 namespace WebCore { | 46 namespace WebCore { |
47 | 47 |
48 class ScriptState; | 48 class ScriptState; |
49 class ScriptController; | 49 class ScriptController; |
50 class ScriptDebugListener; | 50 class ScriptDebugListener; |
51 class ScriptObject; | |
52 class ScriptSourceCode; | 51 class ScriptSourceCode; |
53 class ScriptValue; | 52 class ScriptValue; |
| 53 class StackTrace; |
| 54 class ActivationFrame; |
54 class JavaScriptCallFrame; | 55 class JavaScriptCallFrame; |
55 | 56 |
56 class ScriptDebugServer { | 57 class ScriptDebugServerBase { |
57 WTF_MAKE_NONCOPYABLE(ScriptDebugServer); | |
58 public: | 58 public: |
59 String setBreakpoint(const String& sourceID, const ScriptBreakpoint&, int* a
ctualLineNumber, int* actualColumnNumber, bool interstatementLocation); | 59 virtual String setBreakpoint(const String& sourceID, const ScriptBreakpoint&
, int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation) =
0; |
60 void removeBreakpoint(const String& breakpointId); | 60 virtual void removeBreakpoint(const String& breakpointId) = 0; |
61 void clearBreakpoints(); | 61 virtual void clearBreakpoints() = 0; |
62 void setBreakpointsActivated(bool activated); | 62 virtual void setBreakpointsActivated(bool) = 0; |
63 | 63 |
64 enum PauseOnExceptionsState { | 64 enum PauseOnExceptionsState { |
65 DontPauseOnExceptions, | 65 DontPauseOnExceptions, |
66 PauseOnAllExceptions, | 66 PauseOnAllExceptions, |
67 PauseOnUncaughtExceptions | 67 PauseOnUncaughtExceptions |
68 }; | 68 }; |
69 PauseOnExceptionsState pauseOnExceptionsState(); | 69 virtual PauseOnExceptionsState pauseOnExceptionsState() = 0; |
70 void setPauseOnExceptionsState(PauseOnExceptionsState pauseOnExceptionsState
); | 70 virtual void setPauseOnExceptionsState(PauseOnExceptionsState) = 0; |
71 | 71 |
72 void setPauseOnNextStatement(bool pause); | 72 virtual void setPauseOnNextStatement(bool) = 0; |
73 bool canBreakProgram(); | 73 virtual bool canBreakProgram() = 0; |
74 void breakProgram(); | 74 virtual void breakProgram() = 0; |
75 void continueProgram(); | 75 virtual void continueProgram() = 0; |
76 void stepIntoStatement(); | 76 virtual void stepIntoStatement() = 0; |
77 void stepOverStatement(const ScriptValue& frame); | 77 virtual void stepOverStatement(const ActivationFrame&) = 0; |
78 void stepOutOfFunction(const ScriptValue& frame); | 78 virtual void stepOutOfFunction(const ActivationFrame&) = 0; |
79 | 79 |
80 bool setScriptSource(const String& sourceID, const String& newContent, bool
preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceError>&, Sc
riptValue* newCallFrames, RefPtr<JSONObject>* result); | 80 virtual bool setScriptSource(const String& sourceID, const String& newConten
t, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceErr
or>&, StackTrace* newCallFrames, RefPtr<JSONObject>& result) = 0; |
81 ScriptValue currentCallFrames(); | |
82 ScriptValue currentCallFramesForAsyncStack(); | |
83 | 81 |
84 // FIXMEDART: moved to public to dispatch Dart debug events. | 82 virtual StackTrace currentCallFrames() = 0; |
85 void handleV8DebugEvent(const v8::Debug::EventDetails& eventDetails); | 83 virtual StackTrace currentCallFramesForAsyncStack() = 0; |
| 84 |
| 85 virtual bool isPaused() = 0; |
| 86 virtual bool runningNestedMessageLoop() = 0; |
| 87 |
| 88 virtual void compileScript(ScriptState*, const String& expression, const Str
ing& sourceURL, String* scriptId, String* exceptionMessage) { }; |
| 89 virtual void clearCompiledScripts() = 0; |
| 90 virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* re
sult, bool* wasThrown, String* exceptionMessage) = 0; |
| 91 virtual void setPreprocessorSource(const String&) { }; |
| 92 // FIXMEDART: refactor this method to not be V8 specific. |
| 93 virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&) { } |
| 94 virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSou
rceCode&) = 0; |
| 95 virtual String preprocessEventListener(LocalFrame*, const String& source, co
nst String& url, const String& functionName) = 0; |
| 96 |
| 97 virtual void muteWarningsAndDeprecations() { } |
| 98 virtual void unmuteWarningsAndDeprecations() { } |
| 99 }; |
| 100 |
| 101 class ScriptDebugServer : public ScriptDebugServerBase { |
| 102 WTF_MAKE_NONCOPYABLE(ScriptDebugServer); |
| 103 public: |
| 104 virtual String setBreakpoint(const String& sourceID, const ScriptBreakpoint&
, int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation); |
| 105 virtual void removeBreakpoint(const String& breakpointId); |
| 106 virtual void clearBreakpoints(); |
| 107 virtual void setBreakpointsActivated(bool); |
| 108 virtual void setPauseOnNextStatement(bool); |
| 109 virtual bool canBreakProgram(); |
| 110 virtual void breakProgram(); |
| 111 virtual void continueProgram(); |
| 112 virtual void stepIntoStatement(); |
| 113 virtual void stepOverStatement(const ActivationFrame&); |
| 114 virtual void stepOutOfFunction(const ActivationFrame&); |
| 115 |
| 116 virtual PauseOnExceptionsState pauseOnExceptionsState(); |
| 117 virtual void setPauseOnExceptionsState(PauseOnExceptionsState); |
| 118 |
| 119 virtual bool setScriptSource(const String& sourceID, const String& newConten
t, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceErr
or>&, StackTrace* newCallFrames, RefPtr<JSONObject>& result); |
| 120 virtual StackTrace currentCallFrames(); |
| 121 virtual StackTrace currentCallFramesForAsyncStack(); |
86 | 122 |
87 class Task { | 123 class Task { |
88 public: | 124 public: |
89 virtual ~Task() { } | 125 virtual ~Task() { } |
90 virtual void run() = 0; | 126 virtual void run() = 0; |
91 }; | 127 }; |
92 static void interruptAndRun(PassOwnPtr<Task>, v8::Isolate*); | 128 static void interruptAndRun(PassOwnPtr<Task>, v8::Isolate*); |
93 void runPendingTasks(); | 129 void runPendingTasks(); |
94 | 130 |
95 bool isPaused(); | 131 virtual bool isPaused(); |
96 bool runningNestedMessageLoop() { return m_runningNestedMessageLoop; } | 132 bool runningNestedMessageLoop() { return m_runningNestedMessageLoop; } |
97 | 133 |
98 v8::Local<v8::Value> functionScopes(v8::Handle<v8::Function>); | 134 v8::Local<v8::Value> functionScopes(v8::Handle<v8::Function>); |
99 v8::Local<v8::Value> getInternalProperties(v8::Handle<v8::Object>&); | 135 v8::Local<v8::Value> getInternalProperties(v8::Handle<v8::Object>&); |
100 v8::Handle<v8::Value> setFunctionVariableValue(v8::Handle<v8::Value> functio
nValue, int scopeNumber, const String& variableName, v8::Handle<v8::Value> newVa
lue); | 136 v8::Handle<v8::Value> setFunctionVariableValue(v8::Handle<v8::Value> functio
nValue, int scopeNumber, const String& variableName, v8::Handle<v8::Value> newVa
lue); |
101 v8::Local<v8::Value> callDebuggerMethod(const char* functionName, int argc,
v8::Handle<v8::Value> argv[]); | 137 v8::Local<v8::Value> callDebuggerMethod(const char* functionName, int argc,
v8::Handle<v8::Value> argv[]); |
102 | 138 |
103 virtual void compileScript(ScriptState*, const String& expression, const Str
ing& sourceURL, String* scriptId, String* exceptionMessage); | 139 virtual void compileScript(ScriptState*, const String& expression, const Str
ing& sourceURL, String* scriptId, String* exceptionMessage); |
104 virtual void clearCompiledScripts(); | 140 virtual void clearCompiledScripts(); |
105 virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* re
sult, bool* wasThrown, String* exceptionMessage); | 141 virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* re
sult, bool* wasThrown, String* exceptionMessage); |
106 virtual void setPreprocessorSource(const String&) { } | |
107 virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&) { } | |
108 virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSou
rceCode&); | 142 virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSou
rceCode&); |
109 virtual String preprocessEventListener(LocalFrame*, const String& source, co
nst String& url, const String& functionName); | 143 virtual String preprocessEventListener(LocalFrame*, const String& source, co
nst String& url, const String& functionName); |
110 | 144 |
111 virtual void muteWarningsAndDeprecations() { } | |
112 virtual void unmuteWarningsAndDeprecations() { } | |
113 | |
114 protected: | 145 protected: |
115 explicit ScriptDebugServer(v8::Isolate*); | 146 explicit ScriptDebugServer(v8::Isolate*); |
116 virtual ~ScriptDebugServer(); | 147 virtual ~ScriptDebugServer(); |
117 | 148 |
118 virtual ScriptDebugListener* getDebugListenerForContext(v8::Handle<v8::Conte
xt>) = 0; | 149 virtual ScriptDebugListener* getDebugListenerForContext(v8::Handle<v8::Conte
xt>) = 0; |
119 virtual void runMessageLoopOnPause(v8::Handle<v8::Context>) = 0; | 150 virtual void runMessageLoopOnPause(v8::Handle<v8::Context>) = 0; |
120 virtual void quitMessageLoopOnPause() = 0; | 151 virtual void quitMessageLoopOnPause() = 0; |
121 | 152 |
122 static void breakProgramCallback(const v8::FunctionCallbackInfo<v8::Value>&)
; | 153 static void breakProgramCallback(const v8::FunctionCallbackInfo<v8::Value>&)
; |
123 void handleProgramBreak(v8::Handle<v8::Object> executionState, v8::Handle<v8
::Value> exception, v8::Handle<v8::Array> hitBreakpoints); | 154 void handleProgramBreak(v8::Handle<v8::Object> executionState, v8::Handle<v8
::Value> exception, v8::Handle<v8::Array> hitBreakpoints); |
124 void handleProgramBreak(const v8::Debug::EventDetails&, v8::Handle<v8::Value
> exception, v8::Handle<v8::Array> hitBreakpointNumbers); | 155 void handleProgramBreak(const v8::Debug::EventDetails&, v8::Handle<v8::Value
> exception, v8::Handle<v8::Array> hitBreakpointNumbers); |
125 | 156 |
126 static void v8DebugEventCallback(const v8::Debug::EventDetails& eventDetails
); | 157 void handleV8DebugEvent(const v8::Debug::EventDetails&); |
| 158 static void v8DebugEventCallback(const v8::Debug::EventDetails&); |
127 | 159 |
128 void dispatchDidParseSource(ScriptDebugListener* listener, v8::Handle<v8::Ob
ject> sourceObject); | 160 void dispatchDidParseSource(ScriptDebugListener* listener, v8::Handle<v8::Ob
ject> sourceObject); |
129 | 161 |
130 void ensureDebuggerScriptCompiled(); | 162 void ensureDebuggerScriptCompiled(); |
131 | 163 |
132 PauseOnExceptionsState m_pauseOnExceptionsState; | 164 PauseOnExceptionsState m_pauseOnExceptionsState; |
133 ScopedPersistent<v8::Object> m_debuggerScript; | 165 ScopedPersistent<v8::Object> m_debuggerScript; |
134 ScopedPersistent<v8::Object> m_executionState; | 166 ScopedPersistent<v8::Object> m_executionState; |
135 v8::Handle<v8::Context> m_pausedContext; | 167 v8::Handle<v8::Context> m_pausedContext; |
136 bool m_breakpointsActivated; | 168 bool m_breakpointsActivated; |
137 ScopedPersistent<v8::FunctionTemplate> m_breakProgramCallbackTemplate; | 169 ScopedPersistent<v8::FunctionTemplate> m_breakProgramCallbackTemplate; |
138 HashMap<String, OwnPtr<ScopedPersistent<v8::Script> > > m_compiledScripts; | 170 HashMap<String, OwnPtr<ScopedPersistent<v8::Script> > > m_compiledScripts; |
139 v8::Isolate* m_isolate; | 171 v8::Isolate* m_isolate; |
140 | 172 |
141 private: | 173 private: |
142 enum ScopeInfoDetails { | 174 enum ScopeInfoDetails { |
143 AllScopes, | 175 AllScopes, |
144 FastAsyncScopes, | 176 FastAsyncScopes, |
145 NoScopes // Should be the last option. | 177 NoScopes // Should be the last option. |
146 }; | 178 }; |
147 | 179 |
148 ScriptValue currentCallFramesInner(ScopeInfoDetails); | 180 StackTrace currentCallFramesInner(ScopeInfoDetails); |
149 | 181 |
150 void stepCommandWithFrame(const char* functionName, const ScriptValue& frame
); | 182 void stepCommandWithFrame(const char* functionName, const ScriptValue& frame
); |
151 PassRefPtr<JavaScriptCallFrame> wrapCallFrames(v8::Handle<v8::Object> execut
ionState, int maximumLimit, ScopeInfoDetails); | 183 PassRefPtr<JavaScriptCallFrame> wrapCallFrames(v8::Handle<v8::Object> execut
ionState, int maximumLimit, ScopeInfoDetails); |
152 bool executeSkipPauseRequest(ScriptDebugListener::SkipPauseRequest, v8::Hand
le<v8::Object> executionState); | 184 bool executeSkipPauseRequest(ScriptDebugListener::SkipPauseRequest, v8::Hand
le<v8::Object> executionState); |
153 | 185 |
154 bool m_runningNestedMessageLoop; | 186 bool m_runningNestedMessageLoop; |
155 }; | 187 }; |
156 | 188 |
157 } // namespace WebCore | 189 } // namespace WebCore |
158 | 190 |
159 | 191 |
160 #endif // ScriptDebugServer_h | 192 #endif // ScriptDebugServer_h |
OLD | NEW |