OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/inspector/v8-console.h" | 5 #include "src/inspector/v8-console.h" |
6 | 6 |
7 #include "src/base/macros.h" | 7 #include "src/base/macros.h" |
8 #include "src/inspector/injected-script.h" | 8 #include "src/inspector/injected-script.h" |
9 #include "src/inspector/inspected-context.h" | 9 #include "src/inspector/inspected-context.h" |
10 #include "src/inspector/string-util.h" | 10 #include "src/inspector/string-util.h" |
11 #include "src/inspector/v8-console-message.h" | 11 #include "src/inspector/v8-console-message.h" |
12 #include "src/inspector/v8-debugger-agent-impl.h" | 12 #include "src/inspector/v8-debugger-agent-impl.h" |
13 #include "src/inspector/v8-inspector-impl.h" | 13 #include "src/inspector/v8-inspector-impl.h" |
14 #include "src/inspector/v8-inspector-session-impl.h" | 14 #include "src/inspector/v8-inspector-session-impl.h" |
15 #include "src/inspector/v8-profiler-agent-impl.h" | 15 #include "src/inspector/v8-profiler-agent-impl.h" |
16 #include "src/inspector/v8-runtime-agent-impl.h" | 16 #include "src/inspector/v8-runtime-agent-impl.h" |
17 #include "src/inspector/v8-stack-trace-impl.h" | 17 #include "src/inspector/v8-stack-trace-impl.h" |
18 #include "src/inspector/v8-value-copier.h" | 18 #include "src/inspector/v8-value-copier.h" |
19 | 19 |
20 #include "include/v8-inspector.h" | 20 #include "include/v8-inspector.h" |
21 | 21 |
22 namespace v8_inspector { | 22 namespace v8_inspector { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 class ConsoleHelper { | 26 v8::MaybeLocal<v8::Function> firstArgAsFunction( |
27 public: | 27 const v8::FunctionCallbackInfo<v8::Value>& info) { |
28 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info, | 28 if (info.Length() < 1 || !info[0]->IsFunction()) |
29 V8InspectorImpl* inspector) | 29 return v8::MaybeLocal<v8::Function>(); |
30 : m_info(info), | 30 v8::Local<v8::Function> func = info[0].As<v8::Function>(); |
31 m_isolate(info.GetIsolate()), | 31 while (func->GetBoundFunction()->IsFunction()) |
32 m_context(info.GetIsolate()->GetCurrentContext()), | 32 func = func->GetBoundFunction().As<v8::Function>(); |
33 m_inspector(inspector), | 33 return func; |
34 m_contextId(InspectedContext::contextId(m_context)), | 34 } |
35 m_groupId(m_inspector->contextGroupId(m_contextId)) {} | |
36 | 35 |
37 int contextId() const { return m_contextId; } | 36 v8::MaybeLocal<v8::Object> firstArgAsObject( |
38 int groupId() const { return m_groupId; } | 37 const v8::FunctionCallbackInfo<v8::Value>& info) { |
39 | 38 if (info.Length() < 1 || !info[0]->IsObject()) |
40 InjectedScript* injectedScript() { | 39 return v8::MaybeLocal<v8::Object>(); |
41 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId); | 40 return info[0].As<v8::Object>(); |
42 if (!context) return nullptr; | 41 } |
43 return context->getInjectedScript(); | |
44 } | |
45 | |
46 V8ConsoleMessageStorage* consoleMessageStorage() { | |
47 return m_inspector->ensureConsoleMessageStorage(m_groupId); | |
48 } | |
49 | |
50 void reportCall(ConsoleAPIType type) { | |
51 if (!m_info.Length()) return; | |
52 std::vector<v8::Local<v8::Value>> arguments; | |
53 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); | |
54 reportCall(type, arguments); | |
55 } | |
56 | |
57 void reportCallWithDefaultArgument(ConsoleAPIType type, | |
58 const String16& message) { | |
59 std::vector<v8::Local<v8::Value>> arguments; | |
60 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); | |
61 if (!m_info.Length()) arguments.push_back(toV8String(m_isolate, message)); | |
62 reportCall(type, arguments); | |
63 } | |
64 | |
65 void reportCallWithArgument(ConsoleAPIType type, const String16& message) { | |
66 std::vector<v8::Local<v8::Value>> arguments(1, | |
67 toV8String(m_isolate, message)); | |
68 reportCall(type, arguments); | |
69 } | |
70 | |
71 void reportCall(ConsoleAPIType type, | |
72 const std::vector<v8::Local<v8::Value>>& arguments) { | |
73 if (!m_groupId) return; | |
74 std::unique_ptr<V8ConsoleMessage> message = | |
75 V8ConsoleMessage::createForConsoleAPI( | |
76 m_context, m_contextId, m_groupId, m_inspector, | |
77 m_inspector->client()->currentTimeMS(), type, arguments, | |
78 m_inspector->debugger()->captureStackTrace(false)); | |
79 consoleMessageStorage()->addMessage(std::move(message)); | |
80 } | |
81 | |
82 void reportDeprecatedCall(const char* id, const String16& message) { | |
83 if (!consoleMessageStorage()->shouldReportDeprecationMessage(m_contextId, | |
84 id)) { | |
85 return; | |
86 } | |
87 std::vector<v8::Local<v8::Value>> arguments(1, | |
88 toV8String(m_isolate, message)); | |
89 reportCall(ConsoleAPIType::kWarning, arguments); | |
90 } | |
91 | |
92 bool firstArgToBoolean(bool defaultValue) { | |
93 if (m_info.Length() < 1) return defaultValue; | |
94 if (m_info[0]->IsBoolean()) return m_info[0].As<v8::Boolean>()->Value(); | |
95 return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue); | |
96 } | |
97 | |
98 String16 firstArgToString(const String16& defaultValue) { | |
99 if (m_info.Length() < 1) return defaultValue; | |
100 v8::Local<v8::String> titleValue; | |
101 if (m_info[0]->IsObject()) { | |
102 if (!m_info[0].As<v8::Object>()->ObjectProtoToString(m_context).ToLocal( | |
103 &titleValue)) | |
104 return defaultValue; | |
105 } else { | |
106 if (!m_info[0]->ToString(m_context).ToLocal(&titleValue)) | |
107 return defaultValue; | |
108 } | |
109 return toProtocolString(titleValue); | |
110 } | |
111 | |
112 v8::MaybeLocal<v8::Object> firstArgAsObject() { | |
113 if (m_info.Length() < 1 || !m_info[0]->IsObject()) | |
114 return v8::MaybeLocal<v8::Object>(); | |
115 return m_info[0].As<v8::Object>(); | |
116 } | |
117 | |
118 v8::MaybeLocal<v8::Function> firstArgAsFunction() { | |
119 if (m_info.Length() < 1 || !m_info[0]->IsFunction()) | |
120 return v8::MaybeLocal<v8::Function>(); | |
121 v8::Local<v8::Function> func = m_info[0].As<v8::Function>(); | |
122 while (func->GetBoundFunction()->IsFunction()) | |
123 func = func->GetBoundFunction().As<v8::Function>(); | |
124 return func; | |
125 } | |
126 | |
127 V8ProfilerAgentImpl* profilerAgent() { | |
128 if (V8InspectorSessionImpl* session = currentSession()) { | |
129 if (session && session->profilerAgent()->enabled()) | |
130 return session->profilerAgent(); | |
131 } | |
132 return nullptr; | |
133 } | |
134 | |
135 V8DebuggerAgentImpl* debuggerAgent() { | |
136 if (V8InspectorSessionImpl* session = currentSession()) { | |
137 if (session && session->debuggerAgent()->enabled()) | |
138 return session->debuggerAgent(); | |
139 } | |
140 return nullptr; | |
141 } | |
142 | |
143 V8InspectorSessionImpl* currentSession() { | |
144 return m_inspector->sessionForContextGroup(m_groupId); | |
145 } | |
146 | |
147 private: | |
148 const v8::FunctionCallbackInfo<v8::Value>& m_info; | |
149 v8::Isolate* m_isolate; | |
150 v8::Local<v8::Context> m_context; | |
151 V8InspectorImpl* m_inspector = nullptr; | |
152 int m_contextId; | |
153 int m_groupId; | |
154 | |
155 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper); | |
156 }; | |
157 | 42 |
158 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 43 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
159 info.GetReturnValue().Set(info.Data()); | 44 info.GetReturnValue().Set(info.Data()); |
160 } | 45 } |
161 | 46 |
162 void createBoundFunctionProperty(v8::Local<v8::Context> context, | 47 void createBoundFunctionProperty(v8::Local<v8::Context> context, |
163 v8::Local<v8::Object> console, | 48 v8::Local<v8::Object> console, |
164 v8::Local<v8::Value> data, const char* name, | 49 v8::Local<v8::Value> data, const char* name, |
165 v8::FunctionCallback callback, | 50 v8::FunctionCallback callback, |
166 const char* description = nullptr) { | 51 const char* description = nullptr) { |
167 v8::Local<v8::String> funcName = | 52 v8::Local<v8::String> funcName = |
168 toV8StringInternalized(context->GetIsolate(), name); | 53 toV8StringInternalized(context->GetIsolate(), name); |
169 v8::Local<v8::Function> func; | 54 v8::Local<v8::Function> func; |
170 if (!v8::Function::New(context, callback, data, 0, | 55 if (!v8::Function::New(context, callback, data, 0, |
171 v8::ConstructorBehavior::kThrow) | 56 v8::ConstructorBehavior::kThrow) |
172 .ToLocal(&func)) | 57 .ToLocal(&func)) |
173 return; | 58 return; |
174 func->SetName(funcName); | 59 func->SetName(funcName); |
175 if (description) { | 60 if (description) { |
176 v8::Local<v8::String> returnValue = | 61 v8::Local<v8::String> returnValue = |
177 toV8String(context->GetIsolate(), description); | 62 toV8String(context->GetIsolate(), description); |
178 v8::Local<v8::Function> toStringFunction; | 63 v8::Local<v8::Function> toStringFunction; |
179 if (v8::Function::New(context, returnDataCallback, returnValue, 0, | 64 if (v8::Function::New(context, returnDataCallback, returnValue, 0, |
180 v8::ConstructorBehavior::kThrow) | 65 v8::ConstructorBehavior::kThrow) |
181 .ToLocal(&toStringFunction)) | 66 .ToLocal(&toStringFunction)) { |
182 createDataProperty(context, func, toV8StringInternalized( | 67 createDataProperty(context, func, toV8StringInternalized( |
183 context->GetIsolate(), "toString"), | 68 context->GetIsolate(), "toString"), |
184 toStringFunction); | 69 toStringFunction); |
| 70 } |
185 } | 71 } |
186 createDataProperty(context, console, funcName, func); | 72 createDataProperty(context, console, funcName, func); |
187 } | 73 } |
188 | 74 |
189 } // namespace | 75 } // namespace |
190 | 76 |
191 V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {} | 77 V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {} |
192 | 78 |
| 79 int V8Console::currentContextId() { |
| 80 return InspectedContext::contextId( |
| 81 m_inspector->isolate()->GetCurrentContext()); |
| 82 } |
| 83 |
| 84 V8InspectorSessionImpl* V8Console::currentSession() { |
| 85 int groupId = m_inspector->contextGroupId(currentContextId()); |
| 86 return groupId ? m_inspector->sessionForContextGroup(groupId) : nullptr; |
| 87 } |
| 88 |
| 89 V8ProfilerAgentImpl* V8Console::profilerAgent() { |
| 90 V8InspectorSessionImpl* session = currentSession(); |
| 91 if (!session) return nullptr; |
| 92 if (!session || !session->profilerAgent()->enabled()) return nullptr; |
| 93 return session->profilerAgent(); |
| 94 } |
| 95 |
| 96 V8DebuggerAgentImpl* V8Console::debuggerAgent() { |
| 97 V8InspectorSessionImpl* session = currentSession(); |
| 98 if (!session) return nullptr; |
| 99 if (!session || !session->debuggerAgent()->enabled()) return nullptr; |
| 100 return session->debuggerAgent(); |
| 101 } |
| 102 |
| 103 V8RuntimeAgentImpl* V8Console::runtimeAgent() { |
| 104 V8InspectorSessionImpl* session = currentSession(); |
| 105 if (!session) return nullptr; |
| 106 if (!session || !session->runtimeAgent()->enabled()) return nullptr; |
| 107 return session->runtimeAgent(); |
| 108 } |
| 109 |
| 110 InjectedScript* V8Console::injectedScript() { |
| 111 int contextId = currentContextId(); |
| 112 int groupId = m_inspector->contextGroupId(contextId); |
| 113 InspectedContext* context = m_inspector->getContext(groupId, contextId); |
| 114 if (!context) return nullptr; |
| 115 return context->getInjectedScript(); |
| 116 } |
| 117 |
| 118 V8ConsoleMessageStorage* V8Console::messageStorage() { |
| 119 int contextId = |
| 120 InspectedContext::contextId(m_inspector->isolate()->GetCurrentContext()); |
| 121 int groupId = m_inspector->contextGroupId(contextId); |
| 122 if (!groupId) return nullptr; |
| 123 return m_inspector->ensureConsoleMessageStorage(groupId); |
| 124 } |
| 125 |
| 126 void V8Console::reportCall(ConsoleAPIType type, |
| 127 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 128 if (!info.Length()) return; |
| 129 std::vector<v8::Local<v8::Value>> arguments; |
| 130 for (int i = 0; i < info.Length(); ++i) arguments.push_back(info[i]); |
| 131 reportCall(type, arguments); |
| 132 } |
| 133 |
| 134 void V8Console::reportCallWithDefaultArgument( |
| 135 ConsoleAPIType type, const v8::FunctionCallbackInfo<v8::Value>& info, |
| 136 const String16& message) { |
| 137 std::vector<v8::Local<v8::Value>> arguments; |
| 138 for (int i = 0; i < info.Length(); ++i) arguments.push_back(info[i]); |
| 139 if (!info.Length()) |
| 140 arguments.push_back(toV8String(m_inspector->isolate(), message)); |
| 141 reportCall(type, arguments); |
| 142 } |
| 143 |
| 144 void V8Console::reportCallWithArgument(ConsoleAPIType type, |
| 145 const String16& message) { |
| 146 std::vector<v8::Local<v8::Value>> arguments( |
| 147 1, toV8String(m_inspector->isolate(), message)); |
| 148 reportCall(type, arguments); |
| 149 } |
| 150 |
| 151 void V8Console::reportDeprecatedCall(const char* id, const String16& message) { |
| 152 V8ConsoleMessageStorage* storage = messageStorage(); |
| 153 if (!storage) return; |
| 154 int contextId = currentContextId(); |
| 155 if (!contextId) return; |
| 156 if (!storage->shouldReportDeprecationMessage(contextId, id)) return; |
| 157 reportCallWithArgument(ConsoleAPIType::kWarning, message); |
| 158 } |
| 159 |
| 160 void V8Console::reportCall(ConsoleAPIType type, |
| 161 const std::vector<v8::Local<v8::Value>>& arguments) { |
| 162 int contextId = currentContextId(); |
| 163 if (!contextId) return; |
| 164 V8ConsoleMessageStorage* storage = messageStorage(); |
| 165 if (!storage) return; |
| 166 int groupId = m_inspector->contextGroupId(contextId); |
| 167 if (!groupId) return; |
| 168 if (type == ConsoleAPIType::kClear) { |
| 169 m_inspector->client()->consoleClear(groupId); |
| 170 } |
| 171 v8::Local<v8::Context> context = m_inspector->isolate()->GetCurrentContext(); |
| 172 std::unique_ptr<V8ConsoleMessage> message = |
| 173 V8ConsoleMessage::createForConsoleAPI( |
| 174 context, contextId, groupId, m_inspector, |
| 175 m_inspector->client()->currentTimeMS(), type, arguments, |
| 176 m_inspector->debugger()->captureStackTrace(false)); |
| 177 storage->addMessage(std::move(message)); |
| 178 } |
| 179 |
| 180 String16 V8Console::firstArgToString( |
| 181 const v8::FunctionCallbackInfo<v8::Value>& info, |
| 182 const String16& defaultValue) { |
| 183 if (info.Length() < 1) return defaultValue; |
| 184 v8::Local<v8::Context> context = m_inspector->isolate()->GetCurrentContext(); |
| 185 v8::Local<v8::String> titleValue; |
| 186 if (info[0]->IsObject()) { |
| 187 if (!info[0].As<v8::Object>()->ObjectProtoToString(context).ToLocal( |
| 188 &titleValue)) |
| 189 return defaultValue; |
| 190 } else { |
| 191 if (!info[0]->ToString(context).ToLocal(&titleValue)) return defaultValue; |
| 192 } |
| 193 return toProtocolString(titleValue); |
| 194 } |
| 195 |
| 196 bool V8Console::firstArgToBoolean( |
| 197 const v8::FunctionCallbackInfo<v8::Value>& info, bool defaultValue) { |
| 198 if (info.Length() < 1) return defaultValue; |
| 199 if (info[0]->IsBoolean()) return info[0].As<v8::Boolean>()->Value(); |
| 200 return info[0] |
| 201 ->BooleanValue(m_inspector->isolate()->GetCurrentContext()) |
| 202 .FromMaybe(defaultValue); |
| 203 } |
| 204 |
193 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 205 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
194 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug); | 206 reportCall(ConsoleAPIType::kDebug, info); |
195 } | 207 } |
196 | 208 |
197 void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 209 void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
198 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError); | 210 reportCall(ConsoleAPIType::kError, info); |
199 } | 211 } |
200 | 212 |
201 void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 213 void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
202 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo); | 214 reportCall(ConsoleAPIType::kInfo, info); |
203 } | 215 } |
204 | 216 |
205 void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 217 void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
206 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog); | 218 reportCall(ConsoleAPIType::kLog, info); |
207 } | 219 } |
208 | 220 |
209 void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 221 void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
210 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning); | 222 reportCall(ConsoleAPIType::kWarning, info); |
211 } | 223 } |
212 | 224 |
213 void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 225 void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
214 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir); | 226 reportCall(ConsoleAPIType::kDir, info); |
215 } | 227 } |
216 | 228 |
217 void V8Console::dirxmlCallback( | 229 void V8Console::dirxmlCallback( |
218 const v8::FunctionCallbackInfo<v8::Value>& info) { | 230 const v8::FunctionCallbackInfo<v8::Value>& info) { |
219 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML); | 231 reportCall(ConsoleAPIType::kDirXML, info); |
220 } | 232 } |
221 | 233 |
222 void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 234 void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
223 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable); | 235 reportCall(ConsoleAPIType::kTable, info); |
224 } | 236 } |
225 | 237 |
226 void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 238 void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
227 ConsoleHelper(info, m_inspector) | 239 reportCallWithDefaultArgument(ConsoleAPIType::kTrace, info, |
228 .reportCallWithDefaultArgument(ConsoleAPIType::kTrace, | 240 String16("console.trace")); |
229 String16("console.trace")); | |
230 } | 241 } |
231 | 242 |
232 void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 243 void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
233 ConsoleHelper(info, m_inspector) | 244 reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup, info, |
234 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup, | 245 String16("console.group")); |
235 String16("console.group")); | |
236 } | 246 } |
237 | 247 |
238 void V8Console::groupCollapsedCallback( | 248 void V8Console::groupCollapsedCallback( |
239 const v8::FunctionCallbackInfo<v8::Value>& info) { | 249 const v8::FunctionCallbackInfo<v8::Value>& info) { |
240 ConsoleHelper(info, m_inspector) | 250 reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed, info, |
241 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed, | 251 String16("console.groupCollapsed")); |
242 String16("console.groupCollapsed")); | |
243 } | 252 } |
244 | 253 |
245 void V8Console::groupEndCallback( | 254 void V8Console::groupEndCallback( |
246 const v8::FunctionCallbackInfo<v8::Value>& info) { | 255 const v8::FunctionCallbackInfo<v8::Value>& info) { |
247 ConsoleHelper(info, m_inspector) | 256 reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup, info, |
248 .reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup, | 257 String16("console.groupEnd")); |
249 String16("console.groupEnd")); | |
250 } | 258 } |
251 | 259 |
252 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 260 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
253 ConsoleHelper helper(info, m_inspector); | 261 reportCallWithDefaultArgument(ConsoleAPIType::kClear, info, |
254 if (!helper.groupId()) return; | 262 String16("console.clear")); |
255 m_inspector->client()->consoleClear(helper.groupId()); | |
256 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear, | |
257 String16("console.clear")); | |
258 } | 263 } |
259 | 264 |
260 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 265 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
261 ConsoleHelper helper(info, m_inspector); | 266 String16 title = firstArgToString(info, String16()); |
262 String16 title = helper.firstArgToString(String16()); | |
263 String16 identifier; | 267 String16 identifier; |
264 if (title.isEmpty()) { | 268 if (title.isEmpty()) { |
265 std::unique_ptr<V8StackTraceImpl> stackTrace = | 269 std::unique_ptr<V8StackTraceImpl> stackTrace = |
266 V8StackTraceImpl::capture(m_inspector->debugger(), 0, 1); | 270 V8StackTraceImpl::capture(m_inspector->debugger(), 0, 1); |
267 if (stackTrace && !stackTrace->isEmpty()) { | 271 if (stackTrace && !stackTrace->isEmpty()) { |
268 identifier = toString16(stackTrace->topSourceURL()) + ":" + | 272 identifier = toString16(stackTrace->topSourceURL()) + ":" + |
269 String16::fromInteger(stackTrace->topLineNumber()); | 273 String16::fromInteger(stackTrace->topLineNumber()); |
270 } | 274 } |
271 } else { | 275 } else { |
272 identifier = title + "@"; | 276 identifier = title + "@"; |
273 } | 277 } |
274 | 278 |
275 int count = | 279 V8ConsoleMessageStorage* storage = messageStorage(); |
276 helper.consoleMessageStorage()->count(helper.contextId(), identifier); | 280 if (!storage) return; |
| 281 int count = storage->count(currentContextId(), identifier); |
277 String16 countString = String16::fromInteger(count); | 282 String16 countString = String16::fromInteger(count); |
278 helper.reportCallWithArgument( | 283 reportCallWithArgument( |
279 ConsoleAPIType::kCount, | 284 ConsoleAPIType::kCount, |
280 title.isEmpty() ? countString : (title + ": " + countString)); | 285 title.isEmpty() ? countString : (title + ": " + countString)); |
281 } | 286 } |
282 | 287 |
283 void V8Console::assertCallback( | 288 void V8Console::assertCallback( |
284 const v8::FunctionCallbackInfo<v8::Value>& info) { | 289 const v8::FunctionCallbackInfo<v8::Value>& info) { |
285 ConsoleHelper helper(info, m_inspector); | 290 if (firstArgToBoolean(info, false)) return; |
286 if (helper.firstArgToBoolean(false)) return; | |
287 | 291 |
288 std::vector<v8::Local<v8::Value>> arguments; | 292 std::vector<v8::Local<v8::Value>> arguments; |
289 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]); | 293 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]); |
290 if (info.Length() < 2) | 294 if (info.Length() < 2) |
291 arguments.push_back( | 295 arguments.push_back( |
292 toV8String(info.GetIsolate(), String16("console.assert"))); | 296 toV8String(m_inspector->isolate(), String16("console.assert"))); |
293 helper.reportCall(ConsoleAPIType::kAssert, arguments); | 297 reportCall(ConsoleAPIType::kAssert, arguments); |
294 | 298 V8DebuggerAgentImpl* agent = debuggerAgent(); |
295 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent()) | 299 if (!agent) return; |
296 debuggerAgent->breakProgramOnException( | 300 agent->breakProgramOnException(protocol::Debugger::Paused::ReasonEnum::Assert, |
297 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr); | 301 nullptr); |
298 } | 302 } |
299 | 303 |
300 void V8Console::markTimelineCallback( | 304 void V8Console::markTimelineCallback( |
301 const v8::FunctionCallbackInfo<v8::Value>& info) { | 305 const v8::FunctionCallbackInfo<v8::Value>& info) { |
302 ConsoleHelper(info, m_inspector) | 306 reportDeprecatedCall("V8Console#markTimelineDeprecated", |
303 .reportDeprecatedCall("V8Console#markTimelineDeprecated", | 307 "'console.markTimeline' is " |
304 "'console.markTimeline' is " | 308 "deprecated. Please use " |
305 "deprecated. Please use " | 309 "'console.timeStamp' instead."); |
306 "'console.timeStamp' instead."); | |
307 timeStampCallback(info); | 310 timeStampCallback(info); |
308 } | 311 } |
309 | 312 |
310 void V8Console::profileCallback( | 313 void V8Console::profileCallback( |
311 const v8::FunctionCallbackInfo<v8::Value>& info) { | 314 const v8::FunctionCallbackInfo<v8::Value>& info) { |
312 ConsoleHelper helper(info, m_inspector); | 315 if (V8ProfilerAgentImpl* agent = profilerAgent()) { |
313 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) | 316 agent->consoleProfile(firstArgToString(info, String16())); |
314 profilerAgent->consoleProfile(helper.firstArgToString(String16())); | 317 } |
315 } | 318 } |
316 | 319 |
317 void V8Console::profileEndCallback( | 320 void V8Console::profileEndCallback( |
318 const v8::FunctionCallbackInfo<v8::Value>& info) { | 321 const v8::FunctionCallbackInfo<v8::Value>& info) { |
319 ConsoleHelper helper(info, m_inspector); | 322 if (V8ProfilerAgentImpl* agent = profilerAgent()) { |
320 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) | 323 agent->consoleProfileEnd(firstArgToString(info, String16())); |
321 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16())); | 324 } |
322 } | 325 } |
323 | 326 |
324 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info, | 327 void V8Console::time(const v8::FunctionCallbackInfo<v8::Value>& info, |
325 bool timelinePrefix, V8InspectorImpl* inspector) { | 328 bool timelinePrefix) { |
326 ConsoleHelper helper(info, inspector); | 329 String16 protocolTitle = firstArgToString(info, "default"); |
327 String16 protocolTitle = helper.firstArgToString("default"); | |
328 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; | 330 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; |
329 inspector->client()->consoleTime(toStringView(protocolTitle)); | 331 m_inspector->client()->consoleTime(toStringView(protocolTitle)); |
330 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle); | 332 if (V8ConsoleMessageStorage* storage = messageStorage()) { |
| 333 storage->time(currentContextId(), protocolTitle); |
| 334 } |
331 } | 335 } |
332 | 336 |
333 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info, | 337 void V8Console::timeEnd(const v8::FunctionCallbackInfo<v8::Value>& info, |
334 bool timelinePrefix, V8InspectorImpl* inspector) { | 338 bool timelinePrefix) { |
335 ConsoleHelper helper(info, inspector); | 339 String16 protocolTitle = firstArgToString(info, "default"); |
336 String16 protocolTitle = helper.firstArgToString("default"); | |
337 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; | 340 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; |
338 inspector->client()->consoleTimeEnd(toStringView(protocolTitle)); | 341 m_inspector->client()->consoleTimeEnd(toStringView(protocolTitle)); |
339 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(), | 342 V8ConsoleMessageStorage* storage = messageStorage(); |
340 protocolTitle); | 343 if (!storage) return; |
| 344 double elapsed = storage->timeEnd(currentContextId(), protocolTitle); |
341 String16 message = | 345 String16 message = |
342 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms"; | 346 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms"; |
343 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); | 347 reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); |
344 } | 348 } |
345 | 349 |
346 void V8Console::timelineCallback( | 350 void V8Console::timelineCallback( |
347 const v8::FunctionCallbackInfo<v8::Value>& info) { | 351 const v8::FunctionCallbackInfo<v8::Value>& info) { |
348 ConsoleHelper(info, m_inspector) | 352 reportDeprecatedCall("V8Console#timeline", |
349 .reportDeprecatedCall("V8Console#timeline", | 353 "'console.timeline' is deprecated. Please use " |
350 "'console.timeline' is deprecated. Please use " | 354 "'console.time' instead."); |
351 "'console.time' instead."); | 355 time(info, true); |
352 timeFunction(info, true, m_inspector); | |
353 } | 356 } |
354 | 357 |
355 void V8Console::timelineEndCallback( | 358 void V8Console::timelineEndCallback( |
356 const v8::FunctionCallbackInfo<v8::Value>& info) { | 359 const v8::FunctionCallbackInfo<v8::Value>& info) { |
357 ConsoleHelper(info, m_inspector) | 360 reportDeprecatedCall("V8Console#timelineEnd", |
358 .reportDeprecatedCall("V8Console#timelineEnd", | 361 "'console.timelineEnd' is " |
359 "'console.timelineEnd' is " | 362 "deprecated. Please use " |
360 "deprecated. Please use " | 363 "'console.timeEnd' instead."); |
361 "'console.timeEnd' instead."); | 364 timeEnd(info, true); |
362 timeEndFunction(info, true, m_inspector); | |
363 } | 365 } |
364 | 366 |
365 void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 367 void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
366 timeFunction(info, false, m_inspector); | 368 time(info, false); |
367 } | 369 } |
368 | 370 |
369 void V8Console::timeEndCallback( | 371 void V8Console::timeEndCallback( |
370 const v8::FunctionCallbackInfo<v8::Value>& info) { | 372 const v8::FunctionCallbackInfo<v8::Value>& info) { |
371 timeEndFunction(info, false, m_inspector); | 373 timeEnd(info, false); |
372 } | 374 } |
373 | 375 |
374 void V8Console::timeStampCallback( | 376 void V8Console::timeStampCallback( |
375 const v8::FunctionCallbackInfo<v8::Value>& info) { | 377 const v8::FunctionCallbackInfo<v8::Value>& info) { |
376 ConsoleHelper helper(info, m_inspector); | 378 String16 title = firstArgToString(info, String16()); |
377 String16 title = helper.firstArgToString(String16()); | |
378 m_inspector->client()->consoleTimeStamp(toStringView(title)); | 379 m_inspector->client()->consoleTimeStamp(toStringView(title)); |
379 } | 380 } |
380 | 381 |
381 void V8Console::memoryGetterCallback( | 382 void V8Console::memoryGetterCallback( |
382 const v8::FunctionCallbackInfo<v8::Value>& info) { | 383 const v8::FunctionCallbackInfo<v8::Value>& info) { |
383 v8::Local<v8::Value> memoryValue; | 384 v8::Local<v8::Value> memoryValue; |
384 if (!m_inspector->client() | 385 if (!m_inspector->client() |
385 ->memoryInfo(info.GetIsolate(), | 386 ->memoryInfo(info.GetIsolate(), |
386 info.GetIsolate()->GetCurrentContext()) | 387 info.GetIsolate()->GetCurrentContext()) |
387 .ToLocal(&memoryValue)) | 388 .ToLocal(&memoryValue)) |
388 return; | 389 return; |
389 info.GetReturnValue().Set(memoryValue); | 390 info.GetReturnValue().Set(memoryValue); |
390 } | 391 } |
391 | 392 |
392 void V8Console::memorySetterCallback( | 393 void V8Console::memorySetterCallback( |
393 const v8::FunctionCallbackInfo<v8::Value>& info) { | 394 const v8::FunctionCallbackInfo<v8::Value>& info) { |
394 // We can't make the attribute readonly as it breaks existing code that relies | 395 // We can't make the attribute readonly as it breaks existing code that relies |
395 // on being able to assign to console.memory in strict mode. Instead, the | 396 // on being able to assign to console.memory in strict mode. Instead, the |
396 // setter just ignores the passed value. http://crbug.com/468611 | 397 // setter just ignores the passed value. http://crbug.com/468611 |
397 } | 398 } |
398 | 399 |
399 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 400 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
400 v8::Isolate* isolate = info.GetIsolate(); | 401 v8::Isolate* isolate = info.GetIsolate(); |
401 info.GetReturnValue().Set(v8::Array::New(isolate)); | 402 info.GetReturnValue().Set(v8::Array::New(isolate)); |
402 | |
403 ConsoleHelper helper(info, m_inspector); | |
404 v8::Local<v8::Object> obj; | 403 v8::Local<v8::Object> obj; |
405 if (!helper.firstArgAsObject().ToLocal(&obj)) return; | 404 if (!firstArgAsObject(info).ToLocal(&obj)) return; |
406 v8::Local<v8::Array> names; | 405 v8::Local<v8::Array> names; |
407 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names)) | 406 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names)) |
408 return; | 407 return; |
409 info.GetReturnValue().Set(names); | 408 info.GetReturnValue().Set(names); |
410 } | 409 } |
411 | 410 |
412 void V8Console::valuesCallback( | 411 void V8Console::valuesCallback( |
413 const v8::FunctionCallbackInfo<v8::Value>& info) { | 412 const v8::FunctionCallbackInfo<v8::Value>& info) { |
414 v8::Isolate* isolate = info.GetIsolate(); | 413 v8::Isolate* isolate = info.GetIsolate(); |
415 info.GetReturnValue().Set(v8::Array::New(isolate)); | 414 info.GetReturnValue().Set(v8::Array::New(isolate)); |
416 | |
417 ConsoleHelper helper(info, m_inspector); | |
418 v8::Local<v8::Object> obj; | 415 v8::Local<v8::Object> obj; |
419 if (!helper.firstArgAsObject().ToLocal(&obj)) return; | 416 if (!firstArgAsObject(info).ToLocal(&obj)) return; |
420 v8::Local<v8::Array> names; | 417 v8::Local<v8::Array> names; |
421 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 418 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
422 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return; | 419 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return; |
423 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length()); | 420 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length()); |
424 for (uint32_t i = 0; i < names->Length(); ++i) { | 421 for (uint32_t i = 0; i < names->Length(); ++i) { |
425 v8::Local<v8::Value> key; | 422 v8::Local<v8::Value> key; |
426 if (!names->Get(context, i).ToLocal(&key)) continue; | 423 if (!names->Get(context, i).ToLocal(&key)) continue; |
427 v8::Local<v8::Value> value; | 424 v8::Local<v8::Value> value; |
428 if (!obj->Get(context, key).ToLocal(&value)) continue; | 425 if (!obj->Get(context, key).ToLocal(&value)) continue; |
429 createDataProperty(context, values, i, value); | 426 createDataProperty(context, values, i, value); |
430 } | 427 } |
431 info.GetReturnValue().Set(values); | 428 info.GetReturnValue().Set(values); |
432 } | 429 } |
433 | 430 |
434 static void setFunctionBreakpoint(ConsoleHelper& helper, | 431 static void setFunctionBreakpoint(V8DebuggerAgentImpl* agent, |
435 v8::Local<v8::Function> function, | 432 v8::Local<v8::Function> function, |
436 V8DebuggerAgentImpl::BreakpointSource source, | 433 V8DebuggerAgentImpl::BreakpointSource source, |
437 const String16& condition, bool enable) { | 434 const String16& condition, bool enable) { |
438 V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent(); | |
439 if (!debuggerAgent) return; | |
440 String16 scriptId = String16::fromInteger(function->ScriptId()); | 435 String16 scriptId = String16::fromInteger(function->ScriptId()); |
441 int lineNumber = function->GetScriptLineNumber(); | 436 int lineNumber = function->GetScriptLineNumber(); |
442 int columnNumber = function->GetScriptColumnNumber(); | 437 int columnNumber = function->GetScriptColumnNumber(); |
443 if (lineNumber == v8::Function::kLineOffsetNotFound || | 438 if (lineNumber == v8::Function::kLineOffsetNotFound || |
444 columnNumber == v8::Function::kLineOffsetNotFound) | 439 columnNumber == v8::Function::kLineOffsetNotFound) |
445 return; | 440 return; |
446 if (enable) | 441 if (enable) |
447 debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source, | 442 agent->setBreakpointAt(scriptId, lineNumber, columnNumber, source, |
448 condition); | 443 condition); |
449 else | 444 else |
450 debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber, | 445 agent->removeBreakpointAt(scriptId, lineNumber, columnNumber, source); |
451 source); | |
452 } | 446 } |
453 | 447 |
454 void V8Console::debugFunctionCallback( | 448 void V8Console::debugFunctionCallback( |
455 const v8::FunctionCallbackInfo<v8::Value>& info) { | 449 const v8::FunctionCallbackInfo<v8::Value>& info) { |
456 ConsoleHelper helper(info, m_inspector); | |
457 v8::Local<v8::Function> function; | 450 v8::Local<v8::Function> function; |
458 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 451 if (!firstArgAsFunction(info).ToLocal(&function)) return; |
459 setFunctionBreakpoint(helper, function, | 452 V8DebuggerAgentImpl* agent = debuggerAgent(); |
| 453 if (!agent) return; |
| 454 setFunctionBreakpoint(agent, function, |
460 V8DebuggerAgentImpl::DebugCommandBreakpointSource, | 455 V8DebuggerAgentImpl::DebugCommandBreakpointSource, |
461 String16(), true); | 456 String16(), true); |
462 } | 457 } |
463 | 458 |
464 void V8Console::undebugFunctionCallback( | 459 void V8Console::undebugFunctionCallback( |
465 const v8::FunctionCallbackInfo<v8::Value>& info) { | 460 const v8::FunctionCallbackInfo<v8::Value>& info) { |
466 ConsoleHelper helper(info, m_inspector); | |
467 v8::Local<v8::Function> function; | 461 v8::Local<v8::Function> function; |
468 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 462 if (!firstArgAsFunction(info).ToLocal(&function)) return; |
469 setFunctionBreakpoint(helper, function, | 463 V8DebuggerAgentImpl* agent = debuggerAgent(); |
| 464 if (!agent) return; |
| 465 setFunctionBreakpoint(agent, function, |
470 V8DebuggerAgentImpl::DebugCommandBreakpointSource, | 466 V8DebuggerAgentImpl::DebugCommandBreakpointSource, |
471 String16(), false); | 467 String16(), false); |
472 } | 468 } |
473 | 469 |
474 void V8Console::monitorFunctionCallback( | 470 void V8Console::monitorFunctionCallback( |
475 const v8::FunctionCallbackInfo<v8::Value>& info) { | 471 const v8::FunctionCallbackInfo<v8::Value>& info) { |
476 ConsoleHelper helper(info, m_inspector); | |
477 v8::Local<v8::Function> function; | 472 v8::Local<v8::Function> function; |
478 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 473 if (!firstArgAsFunction(info).ToLocal(&function)) return; |
| 474 V8DebuggerAgentImpl* agent = debuggerAgent(); |
| 475 if (!agent) return; |
479 v8::Local<v8::Value> name = function->GetName(); | 476 v8::Local<v8::Value> name = function->GetName(); |
480 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) | 477 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) |
481 name = function->GetInferredName(); | 478 name = function->GetInferredName(); |
482 String16 functionName = toProtocolStringWithTypeCheck(name); | 479 String16 functionName = toProtocolStringWithTypeCheck(name); |
483 String16Builder builder; | 480 String16Builder builder; |
484 builder.append("console.log(\"function "); | 481 builder.append("console.log(\"function "); |
485 if (functionName.isEmpty()) | 482 if (functionName.isEmpty()) |
486 builder.append("(anonymous function)"); | 483 builder.append("(anonymous function)"); |
487 else | 484 else |
488 builder.append(functionName); | 485 builder.append(functionName); |
489 builder.append( | 486 builder.append( |
490 " called\" + (arguments.length > 0 ? \" with arguments: \" + " | 487 " called\" + (arguments.length > 0 ? \" with arguments: \" + " |
491 "Array.prototype.join.call(arguments, \", \") : \"\")) && false"); | 488 "Array.prototype.join.call(arguments, \", \") : \"\")) && false"); |
492 setFunctionBreakpoint(helper, function, | 489 setFunctionBreakpoint(agent, function, |
493 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, | 490 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, |
494 builder.toString(), true); | 491 builder.toString(), true); |
495 } | 492 } |
496 | 493 |
497 void V8Console::unmonitorFunctionCallback( | 494 void V8Console::unmonitorFunctionCallback( |
498 const v8::FunctionCallbackInfo<v8::Value>& info) { | 495 const v8::FunctionCallbackInfo<v8::Value>& info) { |
499 ConsoleHelper helper(info, m_inspector); | |
500 v8::Local<v8::Function> function; | 496 v8::Local<v8::Function> function; |
501 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 497 if (!firstArgAsFunction(info).ToLocal(&function)) return; |
502 setFunctionBreakpoint(helper, function, | 498 V8DebuggerAgentImpl* agent = debuggerAgent(); |
| 499 setFunctionBreakpoint(agent, function, |
503 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, | 500 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, |
504 String16(), false); | 501 String16(), false); |
505 } | 502 } |
506 | 503 |
507 void V8Console::lastEvaluationResultCallback( | 504 void V8Console::lastEvaluationResultCallback( |
508 const v8::FunctionCallbackInfo<v8::Value>& info) { | 505 const v8::FunctionCallbackInfo<v8::Value>& info) { |
509 ConsoleHelper helper(info, m_inspector); | 506 InjectedScript* injected = injectedScript(); |
510 InjectedScript* injectedScript = helper.injectedScript(); | 507 if (!injected) return; |
511 if (!injectedScript) return; | 508 info.GetReturnValue().Set(injected->lastEvaluationResult()); |
512 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); | |
513 } | 509 } |
514 | 510 |
515 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, | 511 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, |
516 bool copyToClipboard, V8InspectorImpl* inspector) { | 512 bool copyToClipboard, V8InspectorImpl* inspector, |
517 if (info.Length() < 1) return; | 513 V8RuntimeAgentImpl* agent, |
| 514 InjectedScript* injectedScript) { |
518 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); | 515 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); |
519 | 516 |
520 ConsoleHelper helper(info, inspector); | |
521 InjectedScript* injectedScript = helper.injectedScript(); | |
522 if (!injectedScript) return; | |
523 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; | 517 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; |
524 protocol::Response response = | 518 protocol::Response response = |
525 injectedScript->wrapObject(info[0], "", false /** forceValueType */, | 519 injectedScript->wrapObject(info[0], "", false /** forceValueType */, |
526 false /** generatePreview */, &wrappedObject); | 520 false /** generatePreview */, &wrappedObject); |
527 if (!response.isSuccess()) return; | 521 if (!response.isSuccess()) return; |
528 | 522 |
529 std::unique_ptr<protocol::DictionaryValue> hints = | 523 std::unique_ptr<protocol::DictionaryValue> hints = |
530 protocol::DictionaryValue::create(); | 524 protocol::DictionaryValue::create(); |
531 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); | 525 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); |
532 if (V8InspectorSessionImpl* session = helper.currentSession()) { | 526 agent->inspect(std::move(wrappedObject), std::move(hints)); |
533 session->runtimeAgent()->inspect(std::move(wrappedObject), | |
534 std::move(hints)); | |
535 } | |
536 } | 527 } |
537 | 528 |
538 void V8Console::inspectCallback( | 529 void V8Console::inspectCallback( |
539 const v8::FunctionCallbackInfo<v8::Value>& info) { | 530 const v8::FunctionCallbackInfo<v8::Value>& info) { |
540 inspectImpl(info, false, m_inspector); | 531 if (info.Length() < 1) return; |
| 532 V8RuntimeAgentImpl* agent = runtimeAgent(); |
| 533 if (!agent) return; |
| 534 InjectedScript* injected = injectedScript(); |
| 535 if (!injected) return; |
| 536 inspectImpl(info, false, m_inspector, agent, injected); |
541 } | 537 } |
542 | 538 |
543 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 539 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
544 inspectImpl(info, true, m_inspector); | 540 if (info.Length() < 1) return; |
| 541 V8RuntimeAgentImpl* agent = runtimeAgent(); |
| 542 if (!agent) return; |
| 543 InjectedScript* injected = injectedScript(); |
| 544 if (!injected) return; |
| 545 inspectImpl(info, true, m_inspector, agent, injected); |
545 } | 546 } |
546 | 547 |
547 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, | 548 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, |
548 unsigned num) { | 549 unsigned num) { |
549 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize); | 550 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize); |
550 ConsoleHelper helper(info, m_inspector); | 551 if (V8InspectorSessionImpl* session = currentSession()) { |
551 if (V8InspectorSessionImpl* session = helper.currentSession()) { | |
552 V8InspectorSession::Inspectable* object = session->inspectedObject(num); | 552 V8InspectorSession::Inspectable* object = session->inspectedObject(num); |
553 v8::Isolate* isolate = info.GetIsolate(); | 553 v8::Isolate* isolate = info.GetIsolate(); |
554 if (object) | 554 if (object) |
555 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); | 555 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); |
556 else | 556 else |
557 info.GetReturnValue().Set(v8::Undefined(isolate)); | 557 info.GetReturnValue().Set(v8::Undefined(isolate)); |
558 } | 558 } |
559 } | 559 } |
560 | 560 |
561 v8::Local<v8::Object> V8Console::createConsole(v8::Local<v8::Context> context) { | 561 v8::Local<v8::Object> V8Console::createConsole(v8::Local<v8::Context> context) { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 ->GetOwnPropertyDescriptor( | 818 ->GetOwnPropertyDescriptor( |
819 m_context, v8::Local<v8::String>::Cast(name)) | 819 m_context, v8::Local<v8::String>::Cast(name)) |
820 .ToLocal(&descriptor); | 820 .ToLocal(&descriptor); |
821 DCHECK(success); | 821 DCHECK(success); |
822 USE(success); | 822 USE(success); |
823 } | 823 } |
824 } | 824 } |
825 } | 825 } |
826 | 826 |
827 } // namespace v8_inspector | 827 } // namespace v8_inspector |
OLD | NEW |