ScriptDebugServer.h [plain text]
#pragma once
#include "Debugger.h"
#include "ScriptBreakpoint.h"
#include "ScriptDebugListener.h"
#include <wtf/Function.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/text/WTFString.h>
namespace JSC {
class CallFrame;
class JSGlobalObject;
class VM;
}
namespace Inspector {
class JS_EXPORT_PRIVATE ScriptDebugServer : public JSC::Debugger {
WTF_MAKE_NONCOPYABLE(ScriptDebugServer);
WTF_MAKE_FAST_ALLOCATED;
public:
void setBreakpointActions(JSC::BreakpointID, const ScriptBreakpoint&);
void removeBreakpointActions(JSC::BreakpointID);
void clearBreakpointActions();
const BreakpointActions& getActionsForBreakpoint(JSC::BreakpointID);
void addListener(ScriptDebugListener*);
void removeListener(ScriptDebugListener*, bool isBeingDestroyed);
protected:
ScriptDebugServer(JSC::VM&);
~ScriptDebugServer() override;
virtual void attachDebugger() = 0;
virtual void detachDebugger(bool isBeingDestroyed) = 0;
virtual void didPause(JSC::JSGlobalObject*) = 0;
virtual void didContinue(JSC::JSGlobalObject*) = 0;
virtual void runEventLoopWhilePaused() = 0;
virtual bool isContentScript(JSC::JSGlobalObject*) const = 0;
virtual void reportException(JSC::JSGlobalObject*, JSC::Exception*) const = 0;
bool evaluateBreakpointAction(const ScriptBreakpointAction&);
bool canDispatchFunctionToListeners() const;
void dispatchFunctionToListeners(Function<void(ScriptDebugListener&)> callback);
bool m_doneProcessingDebuggerEvents { true };
private:
typedef HashMap<JSC::BreakpointID, BreakpointActions> BreakpointIDToActionsMap;
void sourceParsed(JSC::JSGlobalObject*, JSC::SourceProvider*, int errorLine, const String& errorMsg) final;
void willRunMicrotask() final;
void didRunMicrotask() final;
void handleBreakpointHit(JSC::JSGlobalObject*, const JSC::Breakpoint&) final;
void handleExceptionInBreakpointCondition(JSC::JSGlobalObject*, JSC::Exception*) const final;
void handlePause(JSC::JSGlobalObject*, JSC::Debugger::ReasonForPause) final;
void notifyDoneProcessingDebuggerEvents() final;
JSC::JSValue exceptionOrCaughtValue(JSC::JSGlobalObject*);
BreakpointIDToActionsMap m_breakpointIDToActions;
HashSet<ScriptDebugListener*> m_listeners;
bool m_callingListeners { false };
unsigned m_nextProbeSampleId { 1 };
unsigned m_currentProbeBatchId { 0 };
};
}