v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8-inspector-impl.h
Go to the documentation of this file.
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_V8_INSPECTOR_IMPL_H_
32#define V8_INSPECTOR_V8_INSPECTOR_IMPL_H_
33
34#include <functional>
35#include <map>
36#include <memory>
37#include <unordered_map>
38
40#include "src/base/macros.h"
42#include "src/inspector/protocol/Protocol.h"
43
44namespace v8_inspector {
45
46class InspectedContext;
47class V8Console;
48class V8ConsoleMessageStorage;
49class V8Debugger;
50class V8DebuggerAgentImpl;
51class V8DebuggerBarrier;
52class V8InspectorSessionImpl;
53class V8ProfilerAgentImpl;
54class V8RuntimeAgentImpl;
55class V8StackTraceImpl;
56
58 public:
60 ~V8InspectorImpl() override;
63
64 v8::Isolate* isolate() const { return m_isolate; }
66 V8Debugger* debugger() { return m_debugger.get(); }
71 int contextGroupId(int contextId) const;
73
77 const String16& code,
78 const String16& fileName);
81
82 // V8Inspector implementation.
83 std::unique_ptr<V8InspectorSession> connect(int contextGroupId,
85 StringView state,
87 SessionPauseState) override;
88 void contextCreated(const V8ContextInfo&) override;
90 v8::MaybeLocal<v8::Context> contextById(int contextId) override;
91 V8DebuggerId uniqueDebuggerId(int contextId) override;
92 uint64_t isolateId() override;
93 void contextCollected(int contextGroupId, int contextId);
94 void resetContextGroup(int contextGroupId) override;
95 void idleStarted() override;
96 void idleFinished() override;
98 v8::Local<v8::Value> exception,
99 StringView detailedMessage, StringView url,
100 unsigned lineNumber, unsigned columnNumber,
101 std::unique_ptr<V8StackTrace>,
102 int scriptId) override;
103 void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
104 StringView message) override;
105 std::unique_ptr<V8StackTrace> createStackTrace(
107 std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) override;
108 void asyncTaskScheduled(StringView taskName, void* task,
109 bool recurring) override;
110 void asyncTaskCanceled(void* task) override;
111 void asyncTaskStarted(void* task) override;
112 void asyncTaskFinished(void* task) override;
113 void allAsyncTasksCanceled() override;
114
116 void externalAsyncTaskStarted(const V8StackTraceId& parent) override;
117 void externalAsyncTaskFinished(const V8StackTraceId& parent) override;
118
122
123 unsigned nextExceptionId() { return ++m_lastExceptionId; }
128 void discardInspectedContext(int contextGroupId, int contextId);
131 InspectedContext* getContext(int groupId, int contextId) const;
132 InspectedContext* getContext(int contextId) const;
135 const std::function<void(InspectedContext*)>& callback);
136 void forEachSession(
137 int contextGroupId,
138 const std::function<void(V8InspectorSessionImpl*)>& callback);
139 int64_t generateUniqueId();
141 v8::Local<v8::Value> exception);
142 std::unique_ptr<protocol::DictionaryValue>
144
146 public:
147 explicit EvaluateScope(const InjectedScript::Scope& scope);
149
150 protocol::Response setTimeout(double timeout);
151
152 private:
153 class TerminateTask;
154 struct CancelToken;
155
158 std::shared_ptr<CancelToken> m_cancelToken;
159 };
160
161 private:
164 std::unique_ptr<V8Debugger> m_debugger;
171
172 using MuteExceptionsMap = std::unordered_map<int, int>;
174
176 std::unordered_map<int, std::unique_ptr<InspectedContext>>;
178 std::unordered_map<int, std::unique_ptr<ContextByIdMap>>;
180
181 // contextGroupId -> sessionId -> session
182 std::unordered_map<int, std::map<int, V8InspectorSessionImpl*>> m_sessions;
183 // contextGroupId -> debugger barrier
184 std::unordered_map<int, std::weak_ptr<V8DebuggerBarrier>> m_debuggerBarriers;
185
187 std::unordered_map<int, std::unique_ptr<V8ConsoleMessageStorage>>;
189
190 std::unordered_map<int, int> m_contextIdToGroupIdMap;
191 std::map<std::pair<int64_t, int64_t>, int> m_uniqueIdToContextId;
192
193 std::unique_ptr<V8Console> m_console;
195};
196
197} // namespace v8_inspector
198
199#endif // V8_INSPECTOR_V8_INSPECTOR_IMPL_H_
std::shared_ptr< CancelToken > m_cancelToken
EvaluateScope(const InjectedScript::Scope &scope)
protocol::Response setTimeout(double timeout)
void externalAsyncTaskFinished(const V8StackTraceId &parent) override
V8_EXPORT_PRIVATE V8InspectorImpl(v8::Isolate *, V8InspectorClient *)
void asyncTaskStarted(void *task) override
V8InspectorImpl & operator=(const V8InspectorImpl &)=delete
std::unique_ptr< V8Console > m_console
V8ConsoleMessageStorage * ensureConsoleMessageStorage(int contextGroupId)
void disconnect(V8InspectorSessionImpl *)
v8::MaybeLocal< v8::Context > contextById(int contextId) override
std::unique_ptr< V8InspectorSession > connect(int contextGroupId, V8Inspector::Channel *, StringView state, ClientTrustLevel, SessionPauseState) override
std::unique_ptr< protocol::DictionaryValue > getAssociatedExceptionDataForProtocol(v8::Local< v8::Value > exception)
v8::MaybeLocal< v8::Value > compileAndRunInternalScript(v8::Local< v8::Context >, v8::Local< v8::String >)
v8::MaybeLocal< v8::Script > compileScript(v8::Local< v8::Context >, const String16 &code, const String16 &fileName)
v8::Isolate * isolate() const
std::unordered_map< int, int > MuteExceptionsMap
V8InspectorImpl(const V8InspectorImpl &)=delete
void contextCollected(int contextGroupId, int contextId)
V8DebuggerId uniqueDebuggerId(int contextId) override
std::unique_ptr< V8StackTrace > createStackTrace(v8::Local< v8::StackTrace >) override
v8::Global< v8::Context > m_regexContext
void asyncTaskScheduled(StringView taskName, void *task, bool recurring) override
v8::MaybeLocal< v8::Context > regexContext()
InspectedContext * getContext(int groupId, int contextId) const
void contextCreated(const V8ContextInfo &) override
V8_EXPORT_PRIVATE bool associateExceptionData(v8::Local< v8::Context >, v8::Local< v8::Value > exception, v8::Local< v8::Name > key, v8::Local< v8::Value > value) override
void discardInspectedContext(int contextGroupId, int contextId)
void unmuteExceptions(int contextGroupId)
bool hasConsoleMessageStorage(int contextGroupId)
V8_EXPORT_PRIVATE V8Console * console()
PromiseHandlerTracker & promiseHandlerTracker()
int resolveUniqueContextId(internal::V8DebuggerId uniqueId) const
std::unordered_map< int, int > m_contextIdToGroupIdMap
v8::Global< v8::debug::EphemeronTable > m_exceptionMetaData
std::unordered_map< int, std::weak_ptr< V8DebuggerBarrier > > m_debuggerBarriers
std::unordered_map< int, std::unique_ptr< V8ConsoleMessageStorage > > ConsoleStorageMap
std::unordered_map< int, std::unique_ptr< ContextByIdMap > > ContextsByGroupMap
V8_EXPORT_PRIVATE v8::MaybeLocal< v8::Object > getAssociatedExceptionData(v8::Local< v8::Value > exception)
PromiseHandlerTracker m_promiseHandlerTracker
void resetContextGroup(int contextGroupId) override
V8StackTraceId storeCurrentStackTrace(StringView description) override
v8::MaybeLocal< v8::Context > exceptionMetaDataContext()
std::unique_ptr< V8StackTrace > captureStackTrace(bool fullStack) override
v8::Global< v8::Context > m_exceptionMetaDataContext
void forEachSession(int contextGroupId, const std::function< void(V8InspectorSessionImpl *)> &callback)
std::map< std::pair< int64_t, int64_t >, int > m_uniqueIdToContextId
void asyncTaskFinished(void *task) override
void exceptionRevoked(v8::Local< v8::Context >, unsigned exceptionId, StringView message) override
void externalAsyncTaskStarted(const V8StackTraceId &parent) override
int contextGroupId(v8::Local< v8::Context >) const
V8InspectorSessionImpl * sessionById(int contextGroupId, int sessionId)
void contextDestroyed(v8::Local< v8::Context >) override
void forEachContext(int contextGroupId, const std::function< void(InspectedContext *)> &callback)
void muteExceptions(int contextGroupId)
unsigned exceptionThrown(v8::Local< v8::Context >, StringView message, v8::Local< v8::Value > exception, StringView detailedMessage, StringView url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr< V8StackTrace >, int scriptId) override
std::unordered_map< int, std::map< int, V8InspectorSessionImpl * > > m_sessions
void asyncTaskCanceled(void *task) override
std::unordered_map< int, std::unique_ptr< InspectedContext > > ContextByIdMap
std::unique_ptr< V8Debugger > m_debugger
TNode< Object > callback
#define V8_EXPORT_PRIVATE
Definition macros.h:460
std::unique_ptr< ValueMirror > key