V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
v8-inspector-impl.h
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 <unordered_map>
37 
38 #include "src/base/macros.h"
39 #include "src/base/platform/mutex.h"
40 #include "src/inspector/protocol/Protocol.h"
41 
42 #include "include/v8-inspector.h"
43 
44 namespace v8_inspector {
45 
46 class InspectedContext;
47 class V8Console;
48 class V8ConsoleMessageStorage;
49 class V8Debugger;
50 class V8DebuggerAgentImpl;
51 class V8InspectorSessionImpl;
52 class V8ProfilerAgentImpl;
53 class V8RuntimeAgentImpl;
54 class V8StackTraceImpl;
55 
56 class V8InspectorImpl : public V8Inspector {
57  public:
58  V8InspectorImpl(v8::Isolate*, V8InspectorClient*);
59  ~V8InspectorImpl() override;
60 
61  v8::Isolate* isolate() const { return m_isolate; }
62  V8InspectorClient* client() { return m_client; }
63  V8Debugger* debugger() { return m_debugger.get(); }
64  int contextGroupId(v8::Local<v8::Context>) const;
65  int contextGroupId(int contextId) const;
66  uint64_t isolateId() const { return m_isolateId; }
67 
68  v8::MaybeLocal<v8::Value> compileAndRunInternalScript(v8::Local<v8::Context>,
71  const String16& code,
72  const String16& fileName);
73  v8::Local<v8::Context> regexContext();
74 
75  // V8Inspector implementation.
76  std::unique_ptr<V8InspectorSession> connect(int contextGroupId,
78  const StringView& state) override;
79  void contextCreated(const V8ContextInfo&) override;
80  void contextDestroyed(v8::Local<v8::Context>) override;
81  v8::MaybeLocal<v8::Context> contextById(int groupId,
82  v8::Maybe<int> contextId) override;
83  void contextCollected(int contextGroupId, int contextId);
84  void resetContextGroup(int contextGroupId) override;
85  void idleStarted() override;
86  void idleFinished() override;
87  unsigned exceptionThrown(v8::Local<v8::Context>, const StringView& message,
88  v8::Local<v8::Value> exception,
89  const StringView& detailedMessage,
90  const StringView& url, unsigned lineNumber,
91  unsigned columnNumber, std::unique_ptr<V8StackTrace>,
92  int scriptId) override;
93  void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
94  const StringView& message) override;
95  std::unique_ptr<V8StackTrace> createStackTrace(
96  v8::Local<v8::StackTrace>) override;
97  std::unique_ptr<V8StackTrace> captureStackTrace(bool fullStack) override;
98  void asyncTaskScheduled(const StringView& taskName, void* task,
99  bool recurring) override;
100  void asyncTaskCanceled(void* task) override;
101  void asyncTaskStarted(void* task) override;
102  void asyncTaskFinished(void* task) override;
103  void allAsyncTasksCanceled() override;
104 
105  V8StackTraceId storeCurrentStackTrace(const StringView& description) override;
106  void externalAsyncTaskStarted(const V8StackTraceId& parent) override;
107  void externalAsyncTaskFinished(const V8StackTraceId& parent) override;
108 
109  unsigned nextExceptionId() { return ++m_lastExceptionId; }
110  void enableStackCapturingIfNeeded();
111  void disableStackCapturingIfNeeded();
112  void muteExceptions(int contextGroupId);
113  void unmuteExceptions(int contextGroupId);
114  V8ConsoleMessageStorage* ensureConsoleMessageStorage(int contextGroupId);
115  bool hasConsoleMessageStorage(int contextGroupId);
116  void discardInspectedContext(int contextGroupId, int contextId);
117  void disconnect(V8InspectorSessionImpl*);
118  V8InspectorSessionImpl* sessionById(int contextGroupId, int sessionId);
119  InspectedContext* getContext(int groupId, int contextId) const;
120  InspectedContext* getContext(int contextId) const;
121  V8Console* console();
122  void forEachContext(int contextGroupId,
123  const std::function<void(InspectedContext*)>& callback);
124  void forEachSession(
125  int contextGroupId,
126  const std::function<void(V8InspectorSessionImpl*)>& callback);
127 
129  public:
130  explicit EvaluateScope(v8::Isolate* isolate);
131  ~EvaluateScope();
132 
133  protocol::Response setTimeout(double timeout);
134 
135  private:
136  v8::Isolate* m_isolate;
137  class TerminateTask;
138  struct CancelToken;
139  std::shared_ptr<CancelToken> m_cancelToken;
140  v8::Isolate::SafeForTerminationScope m_safeForTerminationScope;
141  };
142 
143  private:
144  v8::Isolate* m_isolate;
145  V8InspectorClient* m_client;
146  std::unique_ptr<V8Debugger> m_debugger;
147  v8::Global<v8::Context> m_regexContext;
148  int m_capturingStackTracesCount;
149  unsigned m_lastExceptionId;
150  int m_lastContextId;
151  int m_lastSessionId = 0;
152  uint64_t m_isolateId;
153 
154  using MuteExceptionsMap = std::unordered_map<int, int>;
155  MuteExceptionsMap m_muteExceptionsMap;
156 
157  using ContextByIdMap =
158  std::unordered_map<int, std::unique_ptr<InspectedContext>>;
159  using ContextsByGroupMap =
160  std::unordered_map<int, std::unique_ptr<ContextByIdMap>>;
161  ContextsByGroupMap m_contexts;
162 
163  // contextGroupId -> sessionId -> session
164  std::unordered_map<int, std::map<int, V8InspectorSessionImpl*>> m_sessions;
165 
166  using ConsoleStorageMap =
167  std::unordered_map<int, std::unique_ptr<V8ConsoleMessageStorage>>;
168  ConsoleStorageMap m_consoleStorageMap;
169 
170  std::unordered_map<int, int> m_contextIdToGroupIdMap;
171 
172  std::unique_ptr<V8Console> m_console;
173 
174  DISALLOW_COPY_AND_ASSIGN(V8InspectorImpl);
175 };
176 
177 } // namespace v8_inspector
178 
179 #endif // V8_INSPECTOR_V8_INSPECTOR_IMPL_H_
Definition: v8.h:56