2  * Copyright (C) 2008, 2013, 2014 Apple Inc. All rights reserved. 
   3  * Copyright (C) 2010-2011 Google Inc. All rights reserved. 
   5  * Redistribution and use in source and binary forms, with or without 
   6  * modification, are permitted provided that the following conditions 
   9  * 1.  Redistributions of source code must retain the above copyright 
  10  *     notice, this list of conditions and the following disclaimer. 
  11  * 2.  Redistributions in binary form must reproduce the above copyright 
  12  *     notice, this list of conditions and the following disclaimer in the 
  13  *     documentation and/or other materials provided with the distribution. 
  14  * 3.  Neither the name of Apple Inc. ("Apple") nor the names of 
  15  *     its contributors may be used to endorse or promote products derived 
  16  *     from this software without specific prior written permission. 
  18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 
  19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
  21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 
  22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
  24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
  25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
  26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
  27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  30 #ifndef ScriptDebugServer_h 
  31 #define ScriptDebugServer_h 
  33 #include "ScriptBreakpoint.h" 
  34 #include "ScriptDebugListener.h" 
  35 #include "bindings/ScriptObject.h" 
  36 #include "debugger/Debugger.h" 
  37 #include <wtf/HashMap.h> 
  38 #include <wtf/HashSet.h> 
  39 #include <wtf/RefPtr.h> 
  40 #include <wtf/Vector.h> 
  41 #include <wtf/text/TextPosition.h> 
  42 #include <wtf/text/WTFString.h> 
  51 class JS_EXPORT_PRIVATE ScriptDebugServer 
: public JSC::Debugger 
{ 
  52     WTF_MAKE_NONCOPYABLE(ScriptDebugServer
); 
  53     WTF_MAKE_FAST_ALLOCATED
; 
  55     JSC::BreakpointID 
setBreakpoint(JSC::SourceID
, const ScriptBreakpoint
&, unsigned* actualLineNumber
, unsigned* actualColumnNumber
); 
  56     void removeBreakpoint(JSC::BreakpointID
); 
  57     void clearBreakpoints(); 
  59     virtual void recompileAllJSFunctions() = 0; 
  61     const BreakpointActions
& getActionsForBreakpoint(JSC::BreakpointID
); 
  64         WTF_MAKE_FAST_ALLOCATED
; 
  67         virtual void run() = 0; 
  71     typedef HashSet
<ScriptDebugListener
*> ListenerSet
; 
  72     typedef void (ScriptDebugServer::*JavaScriptExecutionCallback
)(ScriptDebugListener
*); 
  74     ScriptDebugServer(bool isInWorkerThread 
= false); 
  77     virtual ListenerSet
* getListenersForGlobalObject(JSC::JSGlobalObject
*) = 0; 
  78     virtual void didPause(JSC::JSGlobalObject
*) = 0; 
  79     virtual void didContinue(JSC::JSGlobalObject
*) = 0; 
  80     virtual void runEventLoopWhilePaused() = 0; 
  81     virtual bool isContentScript(JSC::ExecState
*) const = 0; 
  82     virtual void reportException(JSC::ExecState
*, JSC::JSValue
) const = 0; 
  84     bool evaluateBreakpointAction(const ScriptBreakpointAction
&); 
  86     void dispatchFunctionToListeners(JavaScriptExecutionCallback
, JSC::JSGlobalObject
*); 
  87     void dispatchFunctionToListeners(const ListenerSet
& listeners
, JavaScriptExecutionCallback
); 
  88     void dispatchDidPause(ScriptDebugListener
*); 
  89     void dispatchDidContinue(ScriptDebugListener
*); 
  90     void dispatchDidParseSource(const ListenerSet
& listeners
, JSC::SourceProvider
*, bool isContentScript
); 
  91     void dispatchFailedToParseSource(const ListenerSet
& listeners
, JSC::SourceProvider
*, int errorLine
, const String
& errorMessage
); 
  92     void dispatchBreakpointActionLog(JSC::ExecState
*, const String
&); 
  93     void dispatchBreakpointActionSound(JSC::ExecState
*, int breakpointActionIdentifier
); 
  94     void dispatchBreakpointActionProbe(JSC::ExecState
*, const ScriptBreakpointAction
&, const Deprecated::ScriptValue
& sample
); 
  96     bool m_doneProcessingDebuggerEvents
; 
  99     typedef HashMap
<JSC::BreakpointID
, BreakpointActions
> BreakpointIDToActionsMap
; 
 101     virtual void sourceParsed(JSC::ExecState
*, JSC::SourceProvider
*, int errorLine
, const String
& errorMsg
) override final
; 
 102     virtual bool needPauseHandling(JSC::JSGlobalObject
*) override final
; 
 103     virtual void handleBreakpointHit(const JSC::Breakpoint
&) override final
; 
 104     virtual void handleExceptionInBreakpointCondition(JSC::ExecState
*, JSC::JSValue exception
) const override final
; 
 105     virtual void handlePause(JSC::Debugger::ReasonForPause
, JSC::JSGlobalObject
*) override final
; 
 106     virtual void notifyDoneProcessingDebuggerEvents() override final
; 
 109     bool m_callingListeners
; 
 110     BreakpointIDToActionsMap m_breakpointIDToActions
; 
 113 } // namespace Inspector 
 115 #endif // ScriptDebugServer_h