v8  6.7.288(node10.6.0)
V8 is Google's open source JavaScript engine
v8-inspector.h
Go to the documentation of this file.
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_V8_INSPECTOR_H_
6 #define V8_V8_INSPECTOR_H_
7 
8 #include <stdint.h>
9 #include <cctype>
10 
11 #include <memory>
12 
13 #include "v8.h" // NOLINT(build/include)
14 
15 namespace v8_inspector {
16 
17 namespace protocol {
18 namespace Debugger {
19 namespace API {
20 class SearchMatch;
21 }
22 }
23 namespace Runtime {
24 namespace API {
25 class RemoteObject;
26 class StackTrace;
27 }
28 }
29 namespace Schema {
30 namespace API {
31 class Domain;
32 }
33 }
34 } // namespace protocol
35 
37  public:
38  StringView() : m_is8Bit(true), m_length(0), m_characters8(nullptr) {}
39 
40  StringView(const uint8_t* characters, size_t length)
41  : m_is8Bit(true), m_length(length), m_characters8(characters) {}
42 
43  StringView(const uint16_t* characters, size_t length)
44  : m_is8Bit(false), m_length(length), m_characters16(characters) {}
45 
46  bool is8Bit() const { return m_is8Bit; }
47  size_t length() const { return m_length; }
48 
49  // TODO(dgozman): add DCHECK(m_is8Bit) to accessors once platform can be used
50  // here.
51  const uint8_t* characters8() const { return m_characters8; }
52  const uint16_t* characters16() const { return m_characters16; }
53 
54  private:
55  bool m_is8Bit;
56  size_t m_length;
57  union {
58  const uint8_t* m_characters8;
59  const uint16_t* m_characters16;
60  };
61 };
62 
64  public:
65  virtual ~StringBuffer() {}
66  virtual const StringView& string() = 0;
67  // This method copies contents.
68  static std::unique_ptr<StringBuffer> create(const StringView&);
69 };
70 
72  public:
73  V8ContextInfo(v8::Local<v8::Context> context, int contextGroupId,
74  const StringView& humanReadableName)
75  : context(context),
76  contextGroupId(contextGroupId),
78  hasMemoryOnConsole(false) {}
79 
80  v8::Local<v8::Context> context;
81  // Each v8::Context is a part of a group. The group id must be non-zero.
87 
88  static int executionContextId(v8::Local<v8::Context> context);
89 
90  private:
91  // Disallow copying and allocating this one.
92  enum NotNullTagEnum { NotNullLiteral };
93  void* operator new(size_t) = delete;
94  void* operator new(size_t, NotNullTagEnum, void*) = delete;
95  void* operator new(size_t, void*) = delete;
96  V8ContextInfo(const V8ContextInfo&) = delete;
97  V8ContextInfo& operator=(const V8ContextInfo&) = delete;
98 };
99 
101  public:
102  virtual bool isEmpty() const = 0;
103  virtual StringView topSourceURL() const = 0;
104  virtual int topLineNumber() const = 0;
105  virtual int topColumnNumber() const = 0;
106  virtual StringView topScriptId() const = 0;
107  virtual StringView topFunctionName() const = 0;
108 
109  virtual ~V8StackTrace() {}
111  buildInspectorObject() const = 0;
112  virtual std::unique_ptr<StringBuffer> toString() const = 0;
113 
114  // Safe to pass between threads, drops async chain.
115  virtual std::unique_ptr<V8StackTrace> clone() = 0;
116 };
117 
119  public:
120  virtual ~V8InspectorSession() {}
121 
122  // Cross-context inspectable values (DOM nodes in different worlds, etc.).
124  public:
125  virtual v8::Local<v8::Value> get(v8::Local<v8::Context>) = 0;
126  virtual ~Inspectable() {}
127  };
128  virtual void addInspectedObject(std::unique_ptr<Inspectable>) = 0;
129 
130  // Dispatching protocol messages.
131  static bool canDispatchMethod(const StringView& method);
132  virtual void dispatchProtocolMessage(const StringView& message) = 0;
133  virtual std::unique_ptr<StringBuffer> stateJSON() = 0;
135  supportedDomains() = 0;
136 
137  // Debugger actions.
138  virtual void schedulePauseOnNextStatement(const StringView& breakReason,
139  const StringView& breakDetails) = 0;
140  virtual void cancelPauseOnNextStatement() = 0;
141  virtual void breakProgram(const StringView& breakReason,
142  const StringView& breakDetails) = 0;
143  virtual void setSkipAllPauses(bool) = 0;
144  virtual void resume() = 0;
145  virtual void stepOver() = 0;
148  bool caseSensitive, bool isRegex) = 0;
149 
150  // Remote objects.
153  bool generatePreview) = 0;
154 
155  virtual bool unwrapObject(std::unique_ptr<StringBuffer>* error,
156  const StringView& objectId, v8::Local<v8::Value>*,
157  v8::Local<v8::Context>*,
159  virtual void releaseObjectGroup(const StringView&) = 0;
160 };
161 
163  public:
164  virtual ~V8InspectorClient() {}
165 
166  virtual void runMessageLoopOnPause(int contextGroupId) {}
167  virtual void quitMessageLoopOnPause() {}
168  virtual void runIfWaitingForDebugger(int contextGroupId) {}
169 
170  virtual void muteMetrics(int contextGroupId) {}
171  virtual void unmuteMetrics(int contextGroupId) {}
172 
173  virtual void beginUserGesture() {}
174  virtual void endUserGesture() {}
175 
177  return nullptr;
178  }
180  return false;
181  }
182  virtual bool isInspectableHeapObject(v8::Local<v8::Object>) { return true; }
183 
185  int contextGroupId) {
186  return v8::Local<v8::Context>();
187  }
190 
192  v8::Local<v8::Object>) {}
195  const StringView& message,
196  const StringView& url, unsigned lineNumber,
197  unsigned columnNumber, V8StackTrace*) {}
199  v8::Local<v8::Context>) {
200  return v8::MaybeLocal<v8::Value>();
201  }
202 
203  virtual void consoleTime(const StringView& title) {}
204  virtual void consoleTimeEnd(const StringView& title) {}
205  virtual void consoleTimeStamp(const StringView& title) {}
206  virtual void consoleClear(int contextGroupId) {}
207  virtual double currentTimeMS() { return 0; }
208  typedef void (*TimerCallback)(void*);
209  virtual void startRepeatingTimer(double, TimerCallback, void* data) {}
210  virtual void cancelTimer(void* data) {}
211 
212  // TODO(dgozman): this was added to support service worker shadow page. We
213  // should not connect at all.
214  virtual bool canExecuteScripts(int contextGroupId) { return true; }
215 
216  virtual void maxAsyncCallStackDepthChanged(int depth) {}
217 };
218 
219 // These stack trace ids are intended to be passed between debuggers and be
220 // resolved later. This allows to track cross-debugger calls and step between
221 // them if a single client connects to multiple debuggers.
223  uintptr_t id;
224  std::pair<int64_t, int64_t> debugger_id;
225 
226  V8StackTraceId();
227  V8StackTraceId(uintptr_t id, const std::pair<int64_t, int64_t> debugger_id);
228  ~V8StackTraceId() = default;
229 
230  bool IsInvalid() const;
231 };
232 
234  public:
236  virtual ~V8Inspector() {}
237 
238  // Contexts instrumentation.
239  virtual void contextCreated(const V8ContextInfo&) = 0;
240  virtual void contextDestroyed(v8::Local<v8::Context>) = 0;
241  virtual void resetContextGroup(int contextGroupId) = 0;
242 
243  // Various instrumentation.
244  virtual void idleStarted() = 0;
245  virtual void idleFinished() = 0;
246 
247  // Async stack traces instrumentation.
248  virtual void asyncTaskScheduled(const StringView& taskName, void* task,
249  bool recurring) = 0;
250  virtual void asyncTaskCanceled(void* task) = 0;
251  virtual void asyncTaskStarted(void* task) = 0;
252  virtual void asyncTaskFinished(void* task) = 0;
253  virtual void allAsyncTasksCanceled() = 0;
254 
256  const StringView& description) = 0;
257  virtual void externalAsyncTaskStarted(const V8StackTraceId& parent) = 0;
258  virtual void externalAsyncTaskFinished(const V8StackTraceId& parent) = 0;
259 
260  // Exceptions instrumentation.
261  virtual unsigned exceptionThrown(
262  v8::Local<v8::Context>, const StringView& message,
263  v8::Local<v8::Value> exception, const StringView& detailedMessage,
264  const StringView& url, unsigned lineNumber, unsigned columnNumber,
265  std::unique_ptr<V8StackTrace>, int scriptId) = 0;
266  virtual void exceptionRevoked(v8::Local<v8::Context>, unsigned exceptionId,
267  const StringView& message) = 0;
268 
269  // Connection.
271  public:
272  virtual ~Channel() {}
273  virtual void sendResponse(int callId,
275  virtual void sendNotification(std::unique_ptr<StringBuffer> message) = 0;
276  virtual void flushProtocolNotifications() = 0;
277  };
279  int contextGroupId, Channel*, const StringView& state) = 0;
280 
281  // API methods.
283  v8::Local<v8::StackTrace>) = 0;
285 };
286 
287 } // namespace v8_inspector
288 
289 #endif // V8_V8_INSPECTOR_H_
virtual std::unique_ptr< V8StackTrace > captureStackTrace(bool fullStack)=0
virtual void idleFinished()=0
virtual void releaseObjectGroup(const StringView &)=0
virtual bool unwrapObject(std::unique_ptr< StringBuffer > *error, const StringView &objectId, v8::Local< v8::Value > *, v8::Local< v8::Context > *, std::unique_ptr< StringBuffer > *objectGroup)=0
virtual void setSkipAllPauses(bool)=0
virtual unsigned exceptionThrown(v8::Local< v8::Context >, const StringView &message, v8::Local< v8::Value > exception, const StringView &detailedMessage, const StringView &url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr< V8StackTrace >, int scriptId)=0
static bool canDispatchMethod(const StringView &method)
virtual const StringView & string()=0
size_t length() const
Definition: v8-inspector.h:47
virtual void externalAsyncTaskFinished(const V8StackTraceId &parent)=0
Definition: v8.h:2105
virtual StringView topFunctionName() const =0
virtual void cancelTimer(void *data)
Definition: v8-inspector.h:210
virtual void runMessageLoopOnPause(int contextGroupId)
Definition: v8-inspector.h:166
virtual void cancelPauseOnNextStatement()=0
virtual void contextCreated(const V8ContextInfo &)=0
StringView(const uint16_t *characters, size_t length)
Definition: v8-inspector.h:43
V8StackTraceId(uintptr_t id, const std::pair< int64_t, int64_t > debugger_id)
std::pair< int64_t, int64_t > debugger_id
Definition: v8-inspector.h:224
virtual StringView topSourceURL() const =0
virtual void schedulePauseOnNextStatement(const StringView &breakReason, const StringView &breakDetails)=0
virtual void maxAsyncCallStackDepthChanged(int depth)
Definition: v8-inspector.h:216
virtual bool canExecuteScripts(int contextGroupId)
Definition: v8-inspector.h:214
virtual void asyncTaskFinished(void *task)=0
virtual int topColumnNumber() const =0
virtual void runIfWaitingForDebugger(int contextGroupId)
Definition: v8-inspector.h:168
v8::Local< v8::Context > context
Definition: v8-inspector.h:80
virtual void exceptionRevoked(v8::Local< v8::Context >, unsigned exceptionId, const StringView &message)=0
virtual void idleStarted()=0
virtual std::unique_ptr< V8StackTrace > clone()=0
virtual void allAsyncTasksCanceled()=0
virtual void dispatchProtocolMessage(const StringView &message)=0
V8ContextInfo(v8::Local< v8::Context > context, int contextGroupId, const StringView &humanReadableName)
Definition: v8-inspector.h:73
virtual void contextDestroyed(v8::Local< v8::Context >)=0
virtual int topLineNumber() const =0
virtual void resetContextGroup(int contextGroupId)=0
virtual std::unique_ptr< protocol::Runtime::API::RemoteObject > wrapObject(v8::Local< v8::Context >, v8::Local< v8::Value >, const StringView &groupName, bool generatePreview)=0
virtual void externalAsyncTaskStarted(const V8StackTraceId &parent)=0
virtual v8::Local< v8::Value > get(v8::Local< v8::Context >)=0
virtual void sendNotification(std::unique_ptr< StringBuffer > message)=0
StringView(const uint8_t *characters, size_t length)
Definition: v8-inspector.h:40
virtual void asyncTaskScheduled(const StringView &taskName, void *task, bool recurring)=0
const uint16_t * characters16() const
Definition: v8-inspector.h:52
virtual V8StackTraceId storeCurrentStackTrace(const StringView &description)=0
static int executionContextId(v8::Local< v8::Context > context)
virtual void unmuteMetrics(int contextGroupId)
Definition: v8-inspector.h:171
constexpr uint32_t CurrentValueSerializerFormatVersion()
const uint8_t * characters8() const
Definition: v8-inspector.h:51
virtual void breakProgram(const StringView &breakReason, const StringView &breakDetails)=0
virtual void flushProtocolNotifications()=0
virtual void sendResponse(int callId, std::unique_ptr< StringBuffer > message)=0
virtual bool isEmpty() const =0
virtual void asyncTaskCanceled(void *task)=0
static std::unique_ptr< StringBuffer > create(const StringView &)
virtual void asyncTaskStarted(void *task)=0
virtual void quitMessageLoopOnPause()
Definition: v8-inspector.h:167
#define V8_EXPORT
Definition: v8.h:56
virtual void muteMetrics(int contextGroupId)
Definition: v8-inspector.h:170
virtual StringView topScriptId() const =0
virtual void startRepeatingTimer(double, TimerCallback, void *data)
Definition: v8-inspector.h:209
virtual void addInspectedObject(std::unique_ptr< Inspectable >)=0