Line data Source code
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 "src/base/macros.h"
9 :
10 : #include "include/v8.h"
11 : #include "src/debug/interface-types.h"
12 :
13 : namespace v8_inspector {
14 :
15 : class InspectedContext;
16 : class V8InspectorImpl;
17 :
18 : // Console API
19 : // https://console.spec.whatwg.org/#console-namespace
20 7370 : class V8Console : public v8::debug::ConsoleDelegate {
21 : public:
22 : v8::Local<v8::Object> createCommandLineAPI(v8::Local<v8::Context> context,
23 : int sessionId);
24 : void installMemoryGetter(v8::Local<v8::Context> context,
25 : v8::Local<v8::Object> console);
26 :
27 : class CommandLineAPIScope {
28 : public:
29 : CommandLineAPIScope(v8::Local<v8::Context>,
30 : v8::Local<v8::Object> commandLineAPI,
31 : v8::Local<v8::Object> global);
32 : ~CommandLineAPIScope();
33 :
34 : private:
35 : static void accessorGetterCallback(
36 : v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>&);
37 : static void accessorSetterCallback(v8::Local<v8::Name>,
38 : v8::Local<v8::Value>,
39 : const v8::PropertyCallbackInfo<void>&);
40 :
41 : v8::Local<v8::Context> m_context;
42 : v8::Local<v8::Object> m_commandLineAPI;
43 : v8::Local<v8::Object> m_global;
44 : v8::Local<v8::Set> m_installedMethods;
45 : bool m_cleanup;
46 :
47 : DISALLOW_COPY_AND_ASSIGN(CommandLineAPIScope);
48 : };
49 :
50 : explicit V8Console(V8InspectorImpl* inspector);
51 :
52 : private:
53 : void Debug(const v8::debug::ConsoleCallArguments&,
54 : const v8::debug::ConsoleContext& consoleContext) override;
55 : void Error(const v8::debug::ConsoleCallArguments&,
56 : const v8::debug::ConsoleContext& consoleContext) override;
57 : void Info(const v8::debug::ConsoleCallArguments&,
58 : const v8::debug::ConsoleContext& consoleContext) override;
59 : void Log(const v8::debug::ConsoleCallArguments&,
60 : const v8::debug::ConsoleContext& consoleContext) override;
61 : void Warn(const v8::debug::ConsoleCallArguments&,
62 : const v8::debug::ConsoleContext& consoleContext) override;
63 : void Dir(const v8::debug::ConsoleCallArguments&,
64 : const v8::debug::ConsoleContext& consoleContext) override;
65 : void DirXml(const v8::debug::ConsoleCallArguments&,
66 : const v8::debug::ConsoleContext& consoleContext) override;
67 : void Table(const v8::debug::ConsoleCallArguments&,
68 : const v8::debug::ConsoleContext& consoleContext) override;
69 : void Trace(const v8::debug::ConsoleCallArguments&,
70 : const v8::debug::ConsoleContext& consoleContext) override;
71 : void Group(const v8::debug::ConsoleCallArguments&,
72 : const v8::debug::ConsoleContext& consoleContext) override;
73 : void GroupCollapsed(const v8::debug::ConsoleCallArguments&,
74 : const v8::debug::ConsoleContext& consoleContext) override;
75 : void GroupEnd(const v8::debug::ConsoleCallArguments&,
76 : const v8::debug::ConsoleContext& consoleContext) override;
77 : void Clear(const v8::debug::ConsoleCallArguments&,
78 : const v8::debug::ConsoleContext& consoleContext) override;
79 : void Count(const v8::debug::ConsoleCallArguments&,
80 : const v8::debug::ConsoleContext& consoleContext) override;
81 : void CountReset(const v8::debug::ConsoleCallArguments&,
82 : const v8::debug::ConsoleContext& consoleContext) override;
83 : void Assert(const v8::debug::ConsoleCallArguments&,
84 : const v8::debug::ConsoleContext& consoleContext) override;
85 : void Profile(const v8::debug::ConsoleCallArguments&,
86 : const v8::debug::ConsoleContext& consoleContext) override;
87 : void ProfileEnd(const v8::debug::ConsoleCallArguments&,
88 : const v8::debug::ConsoleContext& consoleContext) override;
89 : void Time(const v8::debug::ConsoleCallArguments&,
90 : const v8::debug::ConsoleContext& consoleContext) override;
91 : void TimeLog(const v8::debug::ConsoleCallArguments&,
92 : const v8::debug::ConsoleContext& consoleContext) override;
93 : void TimeEnd(const v8::debug::ConsoleCallArguments&,
94 : const v8::debug::ConsoleContext& consoleContext) override;
95 : void TimeStamp(const v8::debug::ConsoleCallArguments&,
96 : const v8::debug::ConsoleContext& consoleContext) override;
97 :
98 : template <void (V8Console::*func)(const v8::FunctionCallbackInfo<v8::Value>&)>
99 30 : static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
100 : V8Console* console =
101 30 : static_cast<V8Console*>(info.Data().As<v8::External>()->Value());
102 20 : (console->*func)(info);
103 30 : }
104 : using CommandLineAPIData = std::pair<V8Console*, int>;
105 : template <void (V8Console::*func)(const v8::FunctionCallbackInfo<v8::Value>&,
106 : int)>
107 360 : static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
108 : CommandLineAPIData* data = static_cast<CommandLineAPIData*>(
109 360 : info.Data().As<v8::ArrayBuffer>()->GetContents().Data());
110 360 : (data->first->*func)(info, data->second);
111 360 : }
112 : template <void (V8Console::*func)(const v8::debug::ConsoleCallArguments&,
113 : const v8::debug::ConsoleContext&)>
114 65 : static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
115 : CommandLineAPIData* data = static_cast<CommandLineAPIData*>(
116 65 : info.Data().As<v8::ArrayBuffer>()->GetContents().Data());
117 65 : v8::debug::ConsoleCallArguments args(info);
118 130 : (data->first->*func)(args, v8::debug::ConsoleContext());
119 65 : }
120 :
121 : // TODO(foolip): There is no spec for the Memory Info API, see blink-dev:
122 : // https://groups.google.com/a/chromium.org/d/msg/blink-dev/g5YRCGpC9vs/b4OJz71NmPwJ
123 : void memoryGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
124 : void memorySetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
125 :
126 : // CommandLineAPI
127 : void keysCallback(const v8::FunctionCallbackInfo<v8::Value>&, int sessionId);
128 : void valuesCallback(const v8::FunctionCallbackInfo<v8::Value>&,
129 : int sessionId);
130 : void debugFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>&,
131 : int sessionId);
132 : void undebugFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>&,
133 : int sessionId);
134 : void monitorFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>&,
135 : int sessionId);
136 : void unmonitorFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>&,
137 : int sessionId);
138 : void lastEvaluationResultCallback(const v8::FunctionCallbackInfo<v8::Value>&,
139 : int sessionId);
140 : void inspectCallback(const v8::FunctionCallbackInfo<v8::Value>&,
141 : int sessionId);
142 : void copyCallback(const v8::FunctionCallbackInfo<v8::Value>&, int sessionId);
143 : void inspectedObject(const v8::FunctionCallbackInfo<v8::Value>&,
144 : int sessionId, unsigned num);
145 : void inspectedObject0(const v8::FunctionCallbackInfo<v8::Value>& info,
146 : int sessionId) {
147 30 : inspectedObject(info, sessionId, 0);
148 : }
149 : void inspectedObject1(const v8::FunctionCallbackInfo<v8::Value>& info,
150 : int sessionId) {
151 0 : inspectedObject(info, sessionId, 1);
152 : }
153 : void inspectedObject2(const v8::FunctionCallbackInfo<v8::Value>& info,
154 : int sessionId) {
155 0 : inspectedObject(info, sessionId, 2);
156 : }
157 : void inspectedObject3(const v8::FunctionCallbackInfo<v8::Value>& info,
158 : int sessionId) {
159 0 : inspectedObject(info, sessionId, 3);
160 : }
161 : void inspectedObject4(const v8::FunctionCallbackInfo<v8::Value>& info,
162 : int sessionId) {
163 0 : inspectedObject(info, sessionId, 4);
164 : }
165 : void queryObjectsCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
166 : int sessionId);
167 :
168 : V8InspectorImpl* m_inspector;
169 : };
170 :
171 : } // namespace v8_inspector
172 :
173 : #endif // V8_INSPECTOR_V8_CONSOLE_H_
|