v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8-console.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_INSPECTOR_V8_CONSOLE_H_
6#define V8_INSPECTOR_V8_CONSOLE_H_
7
8#include <map>
9
11#include "include/v8-external.h"
13#include "src/base/macros.h"
15
16namespace v8 {
17class ObjectTemplate;
18class Set;
19} // namespace v8
20
21namespace v8_inspector {
22
23class InspectedContext;
24class TaskInfo;
25class V8InspectorImpl;
26
27// Console API
28// https://console.spec.whatwg.org/#console-namespace
30 public:
32 int sessionId);
34 v8::Local<v8::Object> console);
36 v8::Local<v8::Object> console);
37 void cancelConsoleTask(TaskInfo* taskInfo);
38
39 std::map<void*, std::unique_ptr<TaskInfo>>& AllConsoleTasksForTest() {
40 return m_tasks;
41 }
42
78
79 explicit V8Console(V8InspectorImpl* inspector);
80
81 private:
82 friend class TaskInfo;
83
85 const v8::debug::ConsoleContext& consoleContext) override;
87 const v8::debug::ConsoleContext& consoleContext) override;
89 const v8::debug::ConsoleContext& consoleContext) override;
91 const v8::debug::ConsoleContext& consoleContext) override;
93 const v8::debug::ConsoleContext& consoleContext) override;
95 const v8::debug::ConsoleContext& consoleContext) override;
97 const v8::debug::ConsoleContext& consoleContext) override;
99 const v8::debug::ConsoleContext& consoleContext) override;
101 const v8::debug::ConsoleContext& consoleContext) override;
103 const v8::debug::ConsoleContext& consoleContext) override;
105 const v8::debug::ConsoleContext& consoleContext) override;
107 const v8::debug::ConsoleContext& consoleContext) override;
109 const v8::debug::ConsoleContext& consoleContext) override;
111 const v8::debug::ConsoleContext& consoleContext) override;
113 const v8::debug::ConsoleContext& consoleContext) override;
115 const v8::debug::ConsoleContext& consoleContext) override;
117 const v8::debug::ConsoleContext& consoleContext) override;
119 const v8::debug::ConsoleContext& consoleContext) override;
121 const v8::debug::ConsoleContext& consoleContext) override;
123 const v8::debug::ConsoleContext& consoleContext) override;
125 const v8::debug::ConsoleContext& consoleContext) override;
127 const v8::debug::ConsoleContext& consoleContext) override;
128
129 template <void (V8Console::*func)(const v8::FunctionCallbackInfo<v8::Value>&)>
130 static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
131 V8Console* console =
132 static_cast<V8Console*>(info.Data().As<v8::External>()->Value());
133 (console->*func)(info);
134 }
135 using CommandLineAPIData = std::pair<V8Console*, int>;
136 template <void (V8Console::*func)(const v8::FunctionCallbackInfo<v8::Value>&,
137 int)>
138 static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
139 CommandLineAPIData* data = static_cast<CommandLineAPIData*>(
140 info.Data().As<v8::ArrayBuffer>()->GetBackingStore()->Data());
141 (data->first->*func)(info, data->second);
142 }
143 template <void (V8Console::*func)(const v8::debug::ConsoleCallArguments&,
145 static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
146 CommandLineAPIData* data = static_cast<CommandLineAPIData*>(
147 info.Data().As<v8::ArrayBuffer>()->GetBackingStore()->Data());
149 (data->first->*func)(args, v8::debug::ConsoleContext());
150 }
151
152 // TODO(foolip): There is no spec for the Memory Info API, see blink-dev:
153 // https://groups.google.com/a/chromium.org/d/msg/blink-dev/g5YRCGpC9vs/b4OJz71NmPwJ
156
159
160 // CommandLineAPI
161 void keysCallback(const v8::FunctionCallbackInfo<v8::Value>&, int sessionId);
163 int sessionId);
165 int sessionId);
167 int sessionId);
169 int sessionId);
171 int sessionId);
173 int sessionId);
175 int sessionId);
176 void copyCallback(const v8::FunctionCallbackInfo<v8::Value>&, int sessionId);
178 int sessionId, unsigned num);
180 int sessionId) {
181 inspectedObject(info, sessionId, 0);
182 }
184 int sessionId) {
185 inspectedObject(info, sessionId, 1);
186 }
188 int sessionId) {
189 inspectedObject(info, sessionId, 2);
190 }
192 int sessionId) {
193 inspectedObject(info, sessionId, 3);
194 }
196 int sessionId) {
197 inspectedObject(info, sessionId, 4);
198 }
200 int sessionId);
201
202 // Lazily creates m_taskInfoKey and returns a local handle to it. We can't
203 // initialize m_taskInfoKey in the constructor as it would be part of
204 // Chromium's context snapshot.
206
207 // Lazily creates m_taskTemplate and returns a local handle to it.
208 // Similarly to m_taskInfoKey, we can't create the template upfront as to not
209 // be part of Chromium's context snapshot.
211
213
214 // All currently alive tasks. We mark tasks immediately as weak when created
215 // but we need the finalizer to cancel the task when GC cleans them up.
216 std::map<void*, std::unique_ptr<TaskInfo>> m_tasks;
217
218 // We use a private symbol to stash the `TaskInfo` as an v8::External on the
219 // JS task objects created by `console.createTask`.
221
222 // We cache the task template for the async stack tagging API for faster
223 // instantiation. Use `taskTemplate()` to retrieve the lazily created
224 // template.
226};
227
240class TaskInfo {
241 public:
242 TaskInfo(v8::Isolate* isolate, V8Console* console,
244
245 // For these task IDs we duplicate the ID logic from blink and use even
246 // pointers compared to the odd IDs we use for promises. This guarantees that
247 // we don't have any conflicts between task IDs.
248 void* Id() const {
249 return reinterpret_cast<void*>(reinterpret_cast<intptr_t>(this) << 1);
250 }
251
252 // After calling `Cancel` the `TaskInfo` instance is destroyed.
254
255 private:
258};
259
260} // namespace v8_inspector
261
262#endif // V8_INSPECTOR_V8_CONSOLE_H_
#define Assert(condition)
TaskInfo(v8::Isolate *isolate, V8Console *console, v8::Local< v8::Object > task)
void * Id() const
Definition v8-console.h:248
v8::Global< v8::Object > m_task
Definition v8-console.h:256
v8::Global< v8::ArrayBuffer > m_thisReference
Definition v8-console.h:76
v8::Local< v8::ArrayBuffer > thisReference() const
Definition v8-console.h:67
v8::Local< v8::Object > global() const
Definition v8-console.h:63
v8::Local< v8::Context > context() const
Definition v8-console.h:59
CommandLineAPIScope & operator=(const CommandLineAPIScope &)=delete
v8::Global< v8::PrimitiveArray > m_installedMethods
Definition v8-console.h:75
v8::Local< v8::PrimitiveArray > installedMethods() const
Definition v8-console.h:64
CommandLineAPIScope(const CommandLineAPIScope &)=delete
v8::Local< v8::Object > commandLineAPI() const
Definition v8-console.h:60
v8::Global< v8::Object > m_commandLineAPI
Definition v8-console.h:73
void memoryGetterCallback(const v8::FunctionCallbackInfo< v8::Value > &)
void ProfileEnd(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
v8::Global< v8::ObjectTemplate > m_taskTemplate
Definition v8-console.h:225
void keysCallback(const v8::FunctionCallbackInfo< v8::Value > &, int sessionId)
void Group(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void debugFunctionCallback(const v8::FunctionCallbackInfo< v8::Value > &, int sessionId)
void monitorFunctionCallback(const v8::FunctionCallbackInfo< v8::Value > &, int sessionId)
void Error(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
std::pair< V8Console *, int > CommandLineAPIData
Definition v8-console.h:135
v8::Local< v8::ObjectTemplate > taskTemplate()
void Dir(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void inspectedObject(const v8::FunctionCallbackInfo< v8::Value > &, int sessionId, unsigned num)
void Log(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void inspectedObject4(const v8::FunctionCallbackInfo< v8::Value > &info, int sessionId)
Definition v8-console.h:195
void inspectedObject0(const v8::FunctionCallbackInfo< v8::Value > &info, int sessionId)
Definition v8-console.h:179
v8::Local< v8::Object > createCommandLineAPI(v8::Local< v8::Context > context, int sessionId)
void GroupEnd(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void installMemoryGetter(v8::Local< v8::Context > context, v8::Local< v8::Object > console)
void CountReset(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
V8InspectorImpl * m_inspector
Definition v8-console.h:212
void runTask(const v8::FunctionCallbackInfo< v8::Value > &)
void Clear(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
std::map< void *, std::unique_ptr< TaskInfo > > m_tasks
Definition v8-console.h:216
void undebugFunctionCallback(const v8::FunctionCallbackInfo< v8::Value > &, int sessionId)
void lastEvaluationResultCallback(const v8::FunctionCallbackInfo< v8::Value > &, int sessionId)
void queryObjectsCallback(const v8::FunctionCallbackInfo< v8::Value > &info, int sessionId)
v8::Local< v8::Private > taskInfoKey()
void Table(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void Warn(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void Count(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void Profile(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void installAsyncStackTaggingAPI(v8::Local< v8::Context > context, v8::Local< v8::Object > console)
void Time(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void TimeStamp(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void createTask(const v8::FunctionCallbackInfo< v8::Value > &)
void inspectCallback(const v8::FunctionCallbackInfo< v8::Value > &, int sessionId)
void TimeEnd(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
V8Console(V8InspectorImpl *inspector)
void cancelConsoleTask(TaskInfo *taskInfo)
void Info(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void memorySetterCallback(const v8::FunctionCallbackInfo< v8::Value > &)
void valuesCallback(const v8::FunctionCallbackInfo< v8::Value > &, int sessionId)
v8::Global< v8::Private > m_taskInfoKey
Definition v8-console.h:220
void inspectedObject3(const v8::FunctionCallbackInfo< v8::Value > &info, int sessionId)
Definition v8-console.h:191
std::map< void *, std::unique_ptr< TaskInfo > > & AllConsoleTasksForTest()
Definition v8-console.h:39
void unmonitorFunctionCallback(const v8::FunctionCallbackInfo< v8::Value > &, int sessionId)
void TimeLog(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void inspectedObject1(const v8::FunctionCallbackInfo< v8::Value > &info, int sessionId)
Definition v8-console.h:183
void Trace(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void DirXml(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
static void call(const v8::FunctionCallbackInfo< v8::Value > &info)
Definition v8-console.h:130
void copyCallback(const v8::FunctionCallbackInfo< v8::Value > &, int sessionId)
void Debug(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
void inspectedObject2(const v8::FunctionCallbackInfo< v8::Value > &info, int sessionId)
Definition v8-console.h:187
void GroupCollapsed(const v8::debug::ConsoleCallArguments &, const v8::debug::ConsoleContext &consoleContext) override
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
v8::Local< v8::Context > m_context
v8::Isolate * m_isolate
#define V8_NODISCARD
Definition v8config.h:693