~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/bindings/js/ScriptDebugServer.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Apple Inc. All rights reserved.
 
3
 * Copyright (C) 2010-2011 Google Inc. All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 *
 
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 Computer, 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.
 
17
 *
 
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.
 
28
 */
 
29
 
 
30
#ifndef ScriptDebugServer_h
 
31
#define ScriptDebugServer_h
 
32
 
 
33
#if ENABLE(JAVASCRIPT_DEBUGGER)
 
34
 
 
35
#include "ScriptDebugListener.h"
 
36
#include "ScriptBreakpoint.h"
 
37
#include "Timer.h"
 
38
#include <debugger/Debugger.h>
 
39
#include <wtf/HashMap.h>
 
40
#include <wtf/HashSet.h>
 
41
#include <wtf/RefPtr.h>
 
42
#include <wtf/Vector.h>
 
43
#include <wtf/text/TextPosition.h>
 
44
#include <wtf/text/WTFString.h>
 
45
 
 
46
namespace JSC {
 
47
class DebuggerCallFrame;
 
48
class JSGlobalObject;
 
49
class ExecState;
 
50
}
 
51
namespace WebCore {
 
52
 
 
53
class JavaScriptCallFrame;
 
54
class ScriptDebugListener;
 
55
class ScriptObject;
 
56
class ScriptValue;
 
57
 
 
58
class ScriptDebugServer : protected JSC::Debugger {
 
59
    WTF_MAKE_NONCOPYABLE(ScriptDebugServer); WTF_MAKE_FAST_ALLOCATED;
 
60
public:
 
61
    String setBreakpoint(const String& sourceID, const ScriptBreakpoint&, int* actualLineNumber, int* actualColumnNumber);
 
62
    void removeBreakpoint(const String& breakpointId);
 
63
    void clearBreakpoints();
 
64
    void setBreakpointsActivated(bool activated);
 
65
    void activateBreakpoints() { setBreakpointsActivated(true); }
 
66
    void deactivateBreakpoints() { setBreakpointsActivated(false); }
 
67
 
 
68
    enum PauseOnExceptionsState {
 
69
        DontPauseOnExceptions,
 
70
        PauseOnAllExceptions,
 
71
        PauseOnUncaughtExceptions
 
72
    };
 
73
    PauseOnExceptionsState pauseOnExceptionsState() const { return m_pauseOnExceptionsState; }
 
74
    void setPauseOnExceptionsState(PauseOnExceptionsState);
 
75
 
 
76
    void setPauseOnNextStatement(bool pause);
 
77
    void breakProgram();
 
78
    void continueProgram();
 
79
    void stepIntoStatement();
 
80
    void stepOverStatement();
 
81
    void stepOutOfFunction();
 
82
 
 
83
    bool canSetScriptSource();
 
84
    bool setScriptSource(const String& sourceID, const String& newContent, bool preview, String* error, ScriptValue* newCallFrames, ScriptObject* result);
 
85
    void updateCallStack(ScriptValue* callFrame);
 
86
 
 
87
    bool causesRecompilation() { return true; }
 
88
    bool supportsSeparateScriptCompilationAndExecution() { return false; }
 
89
 
 
90
    void recompileAllJSFunctionsSoon();
 
91
    virtual void recompileAllJSFunctions(Timer<ScriptDebugServer>* = 0) = 0;
 
92
 
 
93
    bool isPaused() { return m_paused; }
 
94
 
 
95
    void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionMessage);
 
96
    void clearCompiledScripts();
 
97
    void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage);
 
98
 
 
99
    class Task {
 
100
        WTF_MAKE_FAST_ALLOCATED;
 
101
    public:
 
102
        virtual ~Task() { }
 
103
        virtual void run() = 0;
 
104
    };
 
105
 
 
106
protected:
 
107
    typedef HashSet<ScriptDebugListener*> ListenerSet;
 
108
    typedef void (ScriptDebugServer::*JavaScriptExecutionCallback)(ScriptDebugListener*);
 
109
 
 
110
    ScriptDebugServer();
 
111
    ~ScriptDebugServer();
 
112
 
 
113
    virtual ListenerSet* getListenersForGlobalObject(JSC::JSGlobalObject*) = 0;
 
114
    virtual void didPause(JSC::JSGlobalObject*) = 0;
 
115
    virtual void didContinue(JSC::JSGlobalObject*) = 0;
 
116
 
 
117
    virtual void runEventLoopWhilePaused() = 0;
 
118
 
 
119
    virtual bool isContentScript(JSC::ExecState*);
 
120
 
 
121
    bool hasBreakpoint(intptr_t sourceID, const TextPosition&) const;
 
122
 
 
123
    void dispatchFunctionToListeners(JavaScriptExecutionCallback, JSC::JSGlobalObject*);
 
124
    void dispatchFunctionToListeners(const ListenerSet& listeners, JavaScriptExecutionCallback callback);
 
125
    void dispatchDidPause(ScriptDebugListener*);
 
126
    void dispatchDidContinue(ScriptDebugListener*);
 
127
    void dispatchDidParseSource(const ListenerSet& listeners, JSC::SourceProvider*, bool isContentScript);
 
128
    void dispatchFailedToParseSource(const ListenerSet& listeners, JSC::SourceProvider*, int errorLine, const String& errorMessage);
 
129
 
 
130
    void createCallFrame(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, int columnNumber);
 
131
    void updateCallFrameAndPauseIfNeeded(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, int columnNumber);
 
132
    void pauseIfNeeded(JSC::JSGlobalObject* dynamicGlobalObject);
 
133
 
 
134
    virtual void detach(JSC::JSGlobalObject*);
 
135
 
 
136
    virtual void sourceParsed(JSC::ExecState*, JSC::SourceProvider*, int errorLine, const String& errorMsg);
 
137
    virtual void callEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, int columnNumber);
 
138
    virtual void atStatement(const JSC::DebuggerCallFrame&, intptr_t sourceID, int firstLine, int columnNumber);
 
139
    virtual void returnEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, int columnNumber);
 
140
    virtual void exception(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, int columnNumber, bool hasHandler);
 
141
    virtual void willExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno, int columnNumber);
 
142
    virtual void didExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno, int columnNumber);
 
143
    virtual void didReachBreakpoint(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno, int columnNumber);
 
144
 
 
145
    typedef Vector<ScriptBreakpoint> BreakpointsInLine;
 
146
    typedef HashMap<long, BreakpointsInLine> LineToBreakpointMap;
 
147
    typedef HashMap<intptr_t, LineToBreakpointMap> SourceIdToBreakpointsMap;
 
148
 
 
149
    bool m_callingListeners;
 
150
    PauseOnExceptionsState m_pauseOnExceptionsState;
 
151
    bool m_pauseOnNextStatement;
 
152
    bool m_paused;
 
153
    bool m_doneProcessingDebuggerEvents;
 
154
    bool m_breakpointsActivated;
 
155
    JavaScriptCallFrame* m_pauseOnCallFrame;
 
156
    RefPtr<JavaScriptCallFrame> m_currentCallFrame;
 
157
    SourceIdToBreakpointsMap m_sourceIdToBreakpoints;
 
158
    Timer<ScriptDebugServer> m_recompileTimer;
 
159
 
 
160
    int m_lastExecutedLine;
 
161
    intptr_t m_lastExecutedSourceId;
 
162
};
 
163
 
 
164
} // namespace WebCore
 
165
 
 
166
#endif // ENABLE(JAVASCRIPT_DEBUGGER)
 
167
 
 
168
#endif // ScriptDebugServer_h