Index: Source/bindings/dart/DartScriptDebugServer.h |
diff --git a/Source/bindings/dart/DartScriptDebugServer.h b/Source/bindings/dart/DartScriptDebugServer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c1bc0f65e5f4cc8e78be409a7918310bedd8cc90 |
--- /dev/null |
+++ b/Source/bindings/dart/DartScriptDebugServer.h |
@@ -0,0 +1,318 @@ |
+/* |
+ * Copyright (C) 2014 Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#ifndef DartScriptDebugServer_h |
+#define DartScriptDebugServer_h |
+ |
+#include "bindings/v8/PageScriptDebugServer.h" |
+#include "bindings/v8/ScopedPersistent.h" |
+#include "bindings/v8/ScriptDebugServer.h" |
+#include "bindings/v8/ScriptPreprocessor.h" |
+#include "wtf/Forward.h" |
+#include "wtf/HashSet.h" |
+#include "wtf/RefCounted.h" |
+#include <dart_api.h> |
+#include <dart_debugger_api.h> |
+#include <v8.h> |
+ |
+namespace WebCore { |
+ |
+class Page; |
+ |
+template<typename T> |
+class HandleMap { |
+public: |
+ HandleMap() : m_lastHandle(0) |
+ { |
+ } |
+ |
+ int add(T value) |
+ { |
+ ASSERT(!m_valueToHandleMap.contains(value)); |
+ int handle = ++m_lastHandle; |
+ m_handleToValueMap.set(handle, value); |
+ m_valueToHandleMap.set(value, handle); |
+ return handle; |
+ } |
+ |
+ T get(int handle) |
+ { |
+ return m_handleToValueMap.get(handle); |
+ } |
+ |
+ bool containsValue(T value) |
+ { |
+ return m_valueToHandleMap.contains(value); |
+ } |
+ |
+ int getByValue(T value) |
+ { |
+ ASSERT(m_valueToHandleMap.contains(value)); |
+ return m_valueToHandleMap.get(value); |
+ } |
+ |
+ T remove(int handle) |
+ { |
+ T value = m_handleToValueMap.take(handle); |
+ m_valueToHandleMap.remove(value); |
+ return value; |
+ } |
+ |
+ int removeByValue(T value) |
+ { |
+ int handle = m_valueToHandleMap.take(value); |
+ m_handleToValueMap.remove(handle); |
+ return handle; |
+ } |
+ |
+ void copyValues(Vector<T>& values) |
+ { |
+ copyKeysToVector(m_valueToHandleMap, values); |
+ } |
+ |
+private: |
+ int m_lastHandle; |
+ HashMap<int, T> m_handleToValueMap; |
+ HashMap<T, int> m_valueToHandleMap; |
+}; |
+ |
+struct DartBreakpoint { |
+ DartBreakpoint(intptr_t breakpointId, Dart_Isolate); |
+ |
+ intptr_t m_breakpointId; |
+ Dart_Isolate m_isolate; |
+}; |
+ |
+ |
+struct DartBreakpointInfo { |
+ DartBreakpointInfo(const String& scriptUrl, const ScriptBreakpoint&); |
+ String m_scriptUrl; |
+ ScriptBreakpoint m_scriptBreakpoint; |
+ Vector<DartBreakpoint> m_breakpoints; |
+}; |
+ |
+class DartPageDebug { |
+public: |
+ DartPageDebug(Page*, size_t pageId); |
+ ~DartPageDebug(); |
+ |
+ String setBreakpoint(const String& sourceID, const ScriptBreakpoint&, int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation); |
+ |
+ void registerIsolate(Dart_Isolate); |
+ void unregisterIsolate(Dart_Isolate); |
+ |
+ intptr_t setBreakpointHelper(DartBreakpointInfo*, const String& breakpointIdString, Dart_Isolate, Dart_Handle& exception); |
+ |
+ void removeBreakpoint(const String& breakpointId); |
+ void removeBreakpointHelper(DartBreakpointInfo*); |
+ void clearBreakpointsForIsolate(Dart_Isolate); |
+ void clearBreakpoints(); |
+ void isolateLoaded(); |
+ void addListener(ScriptDebugListener*); |
+ void removeListener(); |
+ ScriptDebugListener* listener() { return m_listener; } |
+ String getScriptId(const String& url); |
+ String lookupBreakpointId(intptr_t dartBreakpointId); |
+ |
+ Vector<Dart_Isolate> isolates(); |
+ bool containsIsolate(Dart_Isolate isolate) { return m_isolateMap.containsValue(isolate); } |
+ Page* page() { return m_page; } |
+private: |
+ void registerIsolateScripts(Dart_Isolate); |
+ void dispatchDidParseSource(intptr_t libraryId, Dart_Handle scriptURL, Dart_Isolate); |
+ |
+ HandleMap<Dart_Isolate> m_isolateMap; |
+ |
+ Page* m_page; |
+ ScriptDebugListener* m_listener; |
+ size_t m_pageId; |
+ HashMap<String, String> m_idToScriptUrlMap; |
+ HashMap<String, String> m_scriptUrlToIdMap; |
+ |
+ typedef HashMap<String, DartBreakpointInfo* > BreakpointMap; |
+ BreakpointMap m_breakpoints; |
+ typedef HashMap<intptr_t, String> BreakpointIdMap; |
+ BreakpointIdMap m_breakpointIdMap; |
+ size_t m_nextBreakpointId; |
+ size_t m_nextScriptId; |
+}; |
+ |
+class DartScriptDebugServer : public ScriptDebugServerBase { |
+ WTF_MAKE_NONCOPYABLE(DartScriptDebugServer); |
+public: |
+ static DartScriptDebugServer& shared(); |
+ |
+ void addListener(ScriptDebugListener*, Page*); |
+ void removeListener(ScriptDebugListener*, Page*); |
+ |
+ void setClientMessageLoop(PageScriptDebugServer::ClientMessageLoop*); |
+ |
+ virtual String setBreakpoint(const String& sourceID, const ScriptBreakpoint&, int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation); |
+ virtual void removeBreakpoint(const String& breakpointId); |
+ virtual void clearBreakpoints(); |
+ virtual void setBreakpointsActivated(bool); |
+ |
+ virtual ScriptDebugServer::PauseOnExceptionsState pauseOnExceptionsState(); |
+ virtual void setPauseOnExceptionsState(ScriptDebugServer::PauseOnExceptionsState); |
+ |
+ virtual void setPauseOnNextStatement(bool); |
+ virtual bool canBreakProgram(); |
+ virtual void breakProgram(); |
+ virtual void continueProgram(); |
+ virtual void stepIntoStatement(); |
+ virtual void stepOverStatement(const ActivationFrame&); |
+ virtual void stepOutOfFunction(const ActivationFrame&); |
+ |
+ virtual bool setScriptSource(const String& sourceID, const String& newContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceError>&, StackTrace* newCallFrames, RefPtr<JSONObject>& result); |
+ virtual StackTrace currentCallFrames(); |
+ virtual StackTrace currentCallFramesForAsyncStack(); |
+ |
+ virtual bool isPaused(); |
+ virtual bool runningNestedMessageLoop() { return m_runningNestedMessageLoop; } |
+ |
+ virtual void clearCompiledScripts(); |
+ virtual void setPreprocessorSource(const String&); |
+ virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&); |
+ virtual String preprocessEventListener(LocalFrame*, const String& source, const String& url, const String& functionName); |
+ virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage); |
+ virtual bool canPreprocess(LocalFrame*); |
+ |
+ static void pausedEventHandler(Dart_IsolateId, intptr_t breakpointId, const Dart_CodeLocation&); |
+ static void exceptionHandler(Dart_IsolateId, Dart_Handle, Dart_StackTrace); |
+ void handleException(Dart_IsolateId, Dart_Handle, Dart_StackTrace); |
+ |
+ static void isolateEventHandler(Dart_IsolateId, Dart_IsolateEvent kind); |
+ void handleInterrupted(Dart_IsolateId); |
+ |
+ void registerIsolate(Dart_Isolate, Page*); |
+ void unregisterIsolate(Dart_Isolate, Page*); |
+ void isolateLoaded(); |
+ |
+ bool resolveCodeLocation(const Dart_CodeLocation&, int* line, int* column); |
+ |
+ String getScriptId(const String& url, Dart_Isolate); |
+ |
+ ScriptDebugServer::PauseOnExceptionsState pauseOnExceptionState() { return m_pauseOnExceptionState; } |
+protected: |
+ explicit DartScriptDebugServer(); |
+ virtual ~DartScriptDebugServer(); |
+ |
+ DartPageDebug* lookupPageDebugForId(const String& id); |
+ DartPageDebug* lookupPageDebug(Page*); |
+ DartPageDebug* lookupPageDebugForCurrentIsolate(); |
+ void runMessageLoopOnPause(Dart_Isolate); |
+ void quitMessageLoopOnPause(); |
+ bool executeSkipPauseRequest(ScriptDebugListener::SkipPauseRequest, Dart_StackTrace); |
+ void handleProgramBreak(Dart_Isolate, Dart_StackTrace, intptr_t dartBreakpointId, Dart_Handle exception, const Dart_CodeLocation&); |
+ void handleDartDebugEvent(Dart_IsolateId, intptr_t breakpointId, Dart_Handle exception, const Dart_CodeLocation&); |
+ |
+ void debugBreak(); |
+ void cancelDebugBreak(); |
+ Page* inferPage(Dart_Isolate); |
+ |
+ Vector<Dart_Isolate> isolates(); |
+ Vector<DartPageDebug*> pages(); |
+ |
+ ScriptDebugServer::PauseOnExceptionsState m_pauseOnExceptionState; |
+ bool m_breakpointsActivated; |
+ bool m_runningNestedMessageLoop; |
+ Dart_StackTrace m_executionState; |
+ Page* m_pausedPage; |
+ HashSet<Dart_Isolate> m_interruptCalled; |
+ HashSet<Dart_Isolate> m_interruptCancelled; |
+ |
+ typedef HashMap<size_t, DartPageDebug*> DebugDataMap; |
+ DebugDataMap m_pageIdToDebugDataMap; |
+ typedef HashMap<Page*, size_t> PageToIdMap; |
+ PageToIdMap m_pageToIdMap; |
+ |
+ PageScriptDebugServer::ClientMessageLoop* m_clientMessageLoop; |
+ |
+ size_t m_nextPageId; |
+}; |
+ |
+// FIXMEDART: this is really UnifiedPageScriptDebugServer. For completeness |
+// add a separate UnifiedScriptDebugServer class that lacks methods to add and |
+// remove page listeners. |
+class UnifiedScriptDebugServer : public ScriptDebugServerBase { |
+ WTF_MAKE_NONCOPYABLE(UnifiedScriptDebugServer); |
+public: |
+ UnifiedScriptDebugServer(DartScriptDebugServer*, PageScriptDebugServer*); |
+ |
+ static UnifiedScriptDebugServer& shared(); |
+ |
+ virtual String setBreakpoint(const String& sourceID, const ScriptBreakpoint&, int* actualLineNumber, int* actualColumnNumber, bool interstatementLocation); |
+ virtual void removeBreakpoint(const String& breakpointId); |
+ virtual void clearBreakpoints(); |
+ virtual void setBreakpointsActivated(bool); |
+ |
+ virtual ScriptDebugServer::PauseOnExceptionsState pauseOnExceptionsState(); |
+ virtual void setPauseOnExceptionsState(ScriptDebugServer::PauseOnExceptionsState); |
+ |
+ virtual void setPauseOnNextStatement(bool); |
+ virtual bool canBreakProgram(); |
+ virtual void breakProgram(); |
+ virtual void continueProgram(); |
+ virtual void stepIntoStatement(); |
+ virtual void stepOverStatement(const ActivationFrame&); |
+ virtual void stepOutOfFunction(const ActivationFrame&); |
+ |
+ virtual bool setScriptSource(const String& sourceID, const String& newContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceError>&, StackTrace* newCallFrames, RefPtr<JSONObject>& result); |
+ virtual StackTrace currentCallFrames(); |
+ virtual StackTrace currentCallFramesForAsyncStack(); |
+ |
+ virtual bool isPaused(); |
+ virtual bool runningNestedMessageLoop(); |
+ |
+ virtual void clearCompiledScripts(); |
+ virtual void setPreprocessorSource(const String&); |
+ |
+ // FIXMEDART: this signature is v8 specific. |
+ virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&); |
+ virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&); |
+ virtual String preprocessEventListener(LocalFrame*, const String& source, const String& url, const String& functionName); |
+ virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage); |
+ |
+ void addListener(ScriptDebugListener*, Page*); |
+ void removeListener(ScriptDebugListener*, Page*); |
+ |
+ DartScriptDebugServer& dart() { return *m_dart; } |
+ PageScriptDebugServer& v8() { return *m_v8; } |
+private: |
+ |
+ bool isDartSourceID(const String& sourceID); |
+ bool isDartBreakpointId(const String& breakpointId); |
+ DartScriptDebugServer* m_dart; |
+ PageScriptDebugServer* m_v8; |
+}; |
+ |
+} |
+ |
+#endif // DartScriptDebugServer_h |