Line data Source code
1 : /*
2 : * Copyright (c) 2010, Google Inc. All rights reserved.
3 : *
4 : * Redistribution and use in source and binary forms, with or without
5 : * modification, are permitted provided that the following conditions are
6 : * met:
7 : *
8 : * * Redistributions of source code must retain the above copyright
9 : * notice, this list of conditions and the following disclaimer.
10 : * * Redistributions in binary form must reproduce the above
11 : * copyright notice, this list of conditions and the following disclaimer
12 : * in the documentation and/or other materials provided with the
13 : * distribution.
14 : * * Neither the name of Google Inc. nor the names of its
15 : * contributors may be used to endorse or promote products derived from
16 : * this software without specific prior written permission.
17 : *
18 : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 : * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 : * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 : * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 : * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 : */
30 :
31 : #ifndef V8_INSPECTOR_V8INSPECTORIMPL_H_
32 : #define V8_INSPECTOR_V8INSPECTORIMPL_H_
33 :
34 : #include <functional>
35 : #include <map>
36 :
37 : #include "src/base/macros.h"
38 : #include "src/inspector/protocol/Protocol.h"
39 :
40 : #include "include/v8-inspector.h"
41 :
42 : namespace v8_inspector {
43 :
44 : class InspectedContext;
45 : class V8Console;
46 : class V8ConsoleMessageStorage;
47 : class V8Debugger;
48 : class V8DebuggerAgentImpl;
49 : class V8InspectorSessionImpl;
50 : class V8ProfilerAgentImpl;
51 : class V8RuntimeAgentImpl;
52 : class V8StackTraceImpl;
53 :
54 : class V8InspectorImpl : public V8Inspector {
55 : public:
56 : V8InspectorImpl(v8::Isolate*, V8InspectorClient*);
57 : ~V8InspectorImpl() override;
58 :
59 : v8::Isolate* isolate() const { return m_isolate; }
60 : V8InspectorClient* client() { return m_client; }
61 : V8Debugger* debugger() { return m_debugger.get(); }
62 : int contextGroupId(v8::Local<v8::Context>) const;
63 : int contextGroupId(int contextId) const;
64 :
65 : v8::MaybeLocal<v8::Value> compileAndRunInternalScript(v8::Local<v8::Context>,
66 : v8::Local<v8::String>);
67 : v8::MaybeLocal<v8::Script> compileScript(v8::Local<v8::Context>,
68 : const String16& code,
69 : const String16& fileName);
70 : v8::Local<v8::Context> regexContext();
71 :
72 : // V8Inspector implementation.
73 : std::unique_ptr<V8InspectorSession> connect(int contextGroupId,
74 : V8Inspector::Channel*,
75 : const StringView& state) override;
76 : void contextCreated(const V8ContextInfo&) override;
77 : void contextDestroyed(v8::Local<v8::Context>) override;
78 : void contextCollected(int contextGroupId, int contextId);
79 : void resetContextGroup(int contextGroupId) override;
80 : void idleStarted() override;
81 : void idleFinished() override;
82 : unsigned exceptionThrown(v8::Local<v8::Context>, const StringView& message,
83 : v8::Local<v8::Value> exception,
84 : const StringView& detailedMessage,
85 : const StringView& url, unsigned lineNumber,
86 : unsigned columnNumber, std::unique_ptr<V8StackTrace>,
87 : int scriptId) override;
88 : void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
89 : const StringView& message) override;
90 : std::unique_ptr<V8StackTrace> createStackTrace(
91 : v8::Local<v8::StackTrace>) override;
92 : std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) override;
93 : void asyncTaskScheduled(const StringView& taskName, void* task,
94 : bool recurring) override;
95 : void asyncTaskCanceled(void* task) override;
96 : void asyncTaskStarted(void* task) override;
97 : void asyncTaskFinished(void* task) override;
98 : void allAsyncTasksCanceled() override;
99 :
100 1292 : unsigned nextExceptionId() { return ++m_lastExceptionId; }
101 : void enableStackCapturingIfNeeded();
102 : void disableStackCapturingIfNeeded();
103 : void muteExceptions(int contextGroupId);
104 : void unmuteExceptions(int contextGroupId);
105 : V8ConsoleMessageStorage* ensureConsoleMessageStorage(int contextGroupId);
106 : bool hasConsoleMessageStorage(int contextGroupId);
107 : void discardInspectedContext(int contextGroupId, int contextId);
108 : void disconnect(V8InspectorSessionImpl*);
109 : V8InspectorSessionImpl* sessionById(int contextGroupId, int sessionId);
110 : InspectedContext* getContext(int groupId, int contextId) const;
111 : InspectedContext* getContext(int contextId) const;
112 : V8Console* console();
113 : void forEachContext(int contextGroupId,
114 : std::function<void(InspectedContext*)> callback);
115 : void forEachSession(int contextGroupId,
116 : std::function<void(V8InspectorSessionImpl*)> callback);
117 :
118 : private:
119 : v8::Isolate* m_isolate;
120 : V8InspectorClient* m_client;
121 : std::unique_ptr<V8Debugger> m_debugger;
122 : v8::Global<v8::Context> m_regexContext;
123 : int m_capturingStackTracesCount;
124 : unsigned m_lastExceptionId;
125 : int m_lastContextId;
126 : int m_lastSessionId = 0;
127 :
128 : using MuteExceptionsMap = protocol::HashMap<int, int>;
129 : MuteExceptionsMap m_muteExceptionsMap;
130 :
131 : using ContextByIdMap =
132 : protocol::HashMap<int, std::unique_ptr<InspectedContext>>;
133 : using ContextsByGroupMap =
134 : protocol::HashMap<int, std::unique_ptr<ContextByIdMap>>;
135 : ContextsByGroupMap m_contexts;
136 :
137 : // contextGroupId -> sessionId -> session
138 : protocol::HashMap<int, std::map<int, V8InspectorSessionImpl*>> m_sessions;
139 :
140 : using ConsoleStorageMap =
141 : protocol::HashMap<int, std::unique_ptr<V8ConsoleMessageStorage>>;
142 : ConsoleStorageMap m_consoleStorageMap;
143 :
144 : protocol::HashMap<int, int> m_contextIdToGroupIdMap;
145 :
146 : std::unique_ptr<V8Console> m_console;
147 :
148 : DISALLOW_COPY_AND_ASSIGN(V8InspectorImpl);
149 : };
150 :
151 : } // namespace v8_inspector
152 :
153 : #endif // V8_INSPECTOR_V8INSPECTORIMPL_H_
|