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 class ConsoleHelper { |
27 public: | 27 public: |
28 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info) | 28 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info, |
| 29 V8InspectorImpl* inspector) |
29 : m_info(info), | 30 : m_info(info), |
30 m_isolate(info.GetIsolate()), | 31 m_isolate(info.GetIsolate()), |
31 m_context(info.GetIsolate()->GetCurrentContext()), | 32 m_context(info.GetIsolate()->GetCurrentContext()), |
32 m_contextId(InspectedContext::contextId(m_context)) { | 33 m_inspector(inspector), |
33 m_inspector = static_cast<V8InspectorImpl*>( | 34 m_contextId(InspectedContext::contextId(m_context)), |
34 m_info.Data().As<v8::External>()->Value()); | 35 m_groupId(m_inspector->contextGroupId(m_contextId)) {} |
35 m_groupId = m_inspector->contextGroupId(m_contextId); | |
36 } | |
37 | |
38 V8InspectorImpl* inspector() { return m_inspector; } | |
39 | 36 |
40 int contextId() const { return m_contextId; } | 37 int contextId() const { return m_contextId; } |
41 int groupId() const { return m_groupId; } | 38 int groupId() const { return m_groupId; } |
42 | 39 |
43 InjectedScript* injectedScript() { | 40 InjectedScript* injectedScript() { |
44 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId); | 41 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId); |
45 if (!context) return nullptr; | 42 if (!context) return nullptr; |
46 return context->getInjectedScript(); | 43 return context->getInjectedScript(); |
47 } | 44 } |
48 | 45 |
49 V8ConsoleMessageStorage* consoleMessageStorage() { | 46 V8ConsoleMessageStorage* consoleMessageStorage() { |
50 return inspector()->ensureConsoleMessageStorage(m_groupId); | 47 return m_inspector->ensureConsoleMessageStorage(m_groupId); |
51 } | 48 } |
52 | 49 |
53 void reportCall(ConsoleAPIType type) { | 50 void reportCall(ConsoleAPIType type) { |
54 if (!m_info.Length()) return; | 51 if (!m_info.Length()) return; |
55 std::vector<v8::Local<v8::Value>> arguments; | 52 std::vector<v8::Local<v8::Value>> arguments; |
56 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); | 53 for (int i = 0; i < m_info.Length(); ++i) arguments.push_back(m_info[i]); |
57 reportCall(type, arguments); | 54 reportCall(type, arguments); |
58 } | 55 } |
59 | 56 |
60 void reportCallWithDefaultArgument(ConsoleAPIType type, | 57 void reportCallWithDefaultArgument(ConsoleAPIType type, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 141 } |
145 | 142 |
146 V8InspectorSessionImpl* currentSession() { | 143 V8InspectorSessionImpl* currentSession() { |
147 return m_inspector->sessionForContextGroup(m_groupId); | 144 return m_inspector->sessionForContextGroup(m_groupId); |
148 } | 145 } |
149 | 146 |
150 private: | 147 private: |
151 const v8::FunctionCallbackInfo<v8::Value>& m_info; | 148 const v8::FunctionCallbackInfo<v8::Value>& m_info; |
152 v8::Isolate* m_isolate; | 149 v8::Isolate* m_isolate; |
153 v8::Local<v8::Context> m_context; | 150 v8::Local<v8::Context> m_context; |
154 v8::Local<v8::Object> m_console; | |
155 V8InspectorImpl* m_inspector = nullptr; | 151 V8InspectorImpl* m_inspector = nullptr; |
156 int m_contextId; | 152 int m_contextId; |
157 int m_groupId; | 153 int m_groupId; |
158 | 154 |
159 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper); | 155 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper); |
160 }; | 156 }; |
161 | 157 |
162 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 158 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
163 info.GetReturnValue().Set(info.Data()); | 159 info.GetReturnValue().Set(info.Data()); |
164 } | 160 } |
(...skipping 20 matching lines...) Expand all Loading... |
185 .ToLocal(&toStringFunction)) | 181 .ToLocal(&toStringFunction)) |
186 createDataProperty(context, func, toV8StringInternalized( | 182 createDataProperty(context, func, toV8StringInternalized( |
187 context->GetIsolate(), "toString"), | 183 context->GetIsolate(), "toString"), |
188 toStringFunction); | 184 toStringFunction); |
189 } | 185 } |
190 createDataProperty(context, console, funcName, func); | 186 createDataProperty(context, console, funcName, func); |
191 } | 187 } |
192 | 188 |
193 } // namespace | 189 } // namespace |
194 | 190 |
| 191 V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {} |
| 192 |
195 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 193 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
196 ConsoleHelper(info).reportCall(ConsoleAPIType::kDebug); | 194 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug); |
197 } | 195 } |
198 | 196 |
199 void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 197 void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
200 ConsoleHelper(info).reportCall(ConsoleAPIType::kError); | 198 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError); |
201 } | 199 } |
202 | 200 |
203 void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 201 void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
204 ConsoleHelper(info).reportCall(ConsoleAPIType::kInfo); | 202 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo); |
205 } | 203 } |
206 | 204 |
207 void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 205 void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
208 ConsoleHelper(info).reportCall(ConsoleAPIType::kLog); | 206 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog); |
209 } | 207 } |
210 | 208 |
211 void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 209 void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
212 ConsoleHelper(info).reportCall(ConsoleAPIType::kWarning); | 210 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning); |
213 } | 211 } |
214 | 212 |
215 void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 213 void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
216 ConsoleHelper(info).reportCall(ConsoleAPIType::kDir); | 214 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir); |
217 } | 215 } |
218 | 216 |
219 void V8Console::dirxmlCallback( | 217 void V8Console::dirxmlCallback( |
220 const v8::FunctionCallbackInfo<v8::Value>& info) { | 218 const v8::FunctionCallbackInfo<v8::Value>& info) { |
221 ConsoleHelper(info).reportCall(ConsoleAPIType::kDirXML); | 219 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML); |
222 } | 220 } |
223 | 221 |
224 void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 222 void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
225 ConsoleHelper(info).reportCall(ConsoleAPIType::kTable); | 223 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable); |
226 } | 224 } |
227 | 225 |
228 void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 226 void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
229 ConsoleHelper(info).reportCallWithDefaultArgument(ConsoleAPIType::kTrace, | 227 ConsoleHelper(info, m_inspector) |
230 String16("console.trace")); | 228 .reportCallWithDefaultArgument(ConsoleAPIType::kTrace, |
| 229 String16("console.trace")); |
231 } | 230 } |
232 | 231 |
233 void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 232 void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
234 ConsoleHelper(info).reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup, | 233 ConsoleHelper(info, m_inspector) |
235 String16("console.group")); | 234 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup, |
| 235 String16("console.group")); |
236 } | 236 } |
237 | 237 |
238 void V8Console::groupCollapsedCallback( | 238 void V8Console::groupCollapsedCallback( |
239 const v8::FunctionCallbackInfo<v8::Value>& info) { | 239 const v8::FunctionCallbackInfo<v8::Value>& info) { |
240 ConsoleHelper(info).reportCallWithDefaultArgument( | 240 ConsoleHelper(info, m_inspector) |
241 ConsoleAPIType::kStartGroupCollapsed, String16("console.groupCollapsed")); | 241 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed, |
| 242 String16("console.groupCollapsed")); |
242 } | 243 } |
243 | 244 |
244 void V8Console::groupEndCallback( | 245 void V8Console::groupEndCallback( |
245 const v8::FunctionCallbackInfo<v8::Value>& info) { | 246 const v8::FunctionCallbackInfo<v8::Value>& info) { |
246 ConsoleHelper(info).reportCallWithDefaultArgument( | 247 ConsoleHelper(info, m_inspector) |
247 ConsoleAPIType::kEndGroup, String16("console.groupEnd")); | 248 .reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup, |
| 249 String16("console.groupEnd")); |
248 } | 250 } |
249 | 251 |
250 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 252 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
251 ConsoleHelper helper(info); | 253 ConsoleHelper helper(info, m_inspector); |
252 if (!helper.groupId()) return; | 254 if (!helper.groupId()) return; |
253 helper.inspector()->client()->consoleClear(helper.groupId()); | 255 m_inspector->client()->consoleClear(helper.groupId()); |
254 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear, | 256 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear, |
255 String16("console.clear")); | 257 String16("console.clear")); |
256 } | 258 } |
257 | 259 |
258 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 260 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
259 ConsoleHelper helper(info); | 261 ConsoleHelper helper(info, m_inspector); |
260 String16 title = helper.firstArgToString(String16()); | 262 String16 title = helper.firstArgToString(String16()); |
261 String16 identifier; | 263 String16 identifier; |
262 if (title.isEmpty()) { | 264 if (title.isEmpty()) { |
263 std::unique_ptr<V8StackTraceImpl> stackTrace = | 265 std::unique_ptr<V8StackTraceImpl> stackTrace = |
264 V8StackTraceImpl::capture(helper.inspector()->debugger(), 0, 1); | 266 V8StackTraceImpl::capture(m_inspector->debugger(), 0, 1); |
265 if (stackTrace && !stackTrace->isEmpty()) { | 267 if (stackTrace && !stackTrace->isEmpty()) { |
266 identifier = toString16(stackTrace->topSourceURL()) + ":" + | 268 identifier = toString16(stackTrace->topSourceURL()) + ":" + |
267 String16::fromInteger(stackTrace->topLineNumber()); | 269 String16::fromInteger(stackTrace->topLineNumber()); |
268 } | 270 } |
269 } else { | 271 } else { |
270 identifier = title + "@"; | 272 identifier = title + "@"; |
271 } | 273 } |
272 | 274 |
273 int count = | 275 int count = |
274 helper.consoleMessageStorage()->count(helper.contextId(), identifier); | 276 helper.consoleMessageStorage()->count(helper.contextId(), identifier); |
275 String16 countString = String16::fromInteger(count); | 277 String16 countString = String16::fromInteger(count); |
276 helper.reportCallWithArgument( | 278 helper.reportCallWithArgument( |
277 ConsoleAPIType::kCount, | 279 ConsoleAPIType::kCount, |
278 title.isEmpty() ? countString : (title + ": " + countString)); | 280 title.isEmpty() ? countString : (title + ": " + countString)); |
279 } | 281 } |
280 | 282 |
281 void V8Console::assertCallback( | 283 void V8Console::assertCallback( |
282 const v8::FunctionCallbackInfo<v8::Value>& info) { | 284 const v8::FunctionCallbackInfo<v8::Value>& info) { |
283 ConsoleHelper helper(info); | 285 ConsoleHelper helper(info, m_inspector); |
284 if (helper.firstArgToBoolean(false)) return; | 286 if (helper.firstArgToBoolean(false)) return; |
285 | 287 |
286 std::vector<v8::Local<v8::Value>> arguments; | 288 std::vector<v8::Local<v8::Value>> arguments; |
287 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]); | 289 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]); |
288 if (info.Length() < 2) | 290 if (info.Length() < 2) |
289 arguments.push_back( | 291 arguments.push_back( |
290 toV8String(info.GetIsolate(), String16("console.assert"))); | 292 toV8String(info.GetIsolate(), String16("console.assert"))); |
291 helper.reportCall(ConsoleAPIType::kAssert, arguments); | 293 helper.reportCall(ConsoleAPIType::kAssert, arguments); |
292 | 294 |
293 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent()) | 295 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent()) |
294 debuggerAgent->breakProgramOnException( | 296 debuggerAgent->breakProgramOnException( |
295 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr); | 297 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr); |
296 } | 298 } |
297 | 299 |
298 void V8Console::markTimelineCallback( | 300 void V8Console::markTimelineCallback( |
299 const v8::FunctionCallbackInfo<v8::Value>& info) { | 301 const v8::FunctionCallbackInfo<v8::Value>& info) { |
300 ConsoleHelper(info).reportDeprecatedCall("V8Console#markTimelineDeprecated", | 302 ConsoleHelper(info, m_inspector) |
301 "'console.markTimeline' is " | 303 .reportDeprecatedCall("V8Console#markTimelineDeprecated", |
302 "deprecated. Please use " | 304 "'console.markTimeline' is " |
303 "'console.timeStamp' instead."); | 305 "deprecated. Please use " |
| 306 "'console.timeStamp' instead."); |
304 timeStampCallback(info); | 307 timeStampCallback(info); |
305 } | 308 } |
306 | 309 |
307 void V8Console::profileCallback( | 310 void V8Console::profileCallback( |
308 const v8::FunctionCallbackInfo<v8::Value>& info) { | 311 const v8::FunctionCallbackInfo<v8::Value>& info) { |
309 ConsoleHelper helper(info); | 312 ConsoleHelper helper(info, m_inspector); |
310 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) | 313 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) |
311 profilerAgent->consoleProfile(helper.firstArgToString(String16())); | 314 profilerAgent->consoleProfile(helper.firstArgToString(String16())); |
312 } | 315 } |
313 | 316 |
314 void V8Console::profileEndCallback( | 317 void V8Console::profileEndCallback( |
315 const v8::FunctionCallbackInfo<v8::Value>& info) { | 318 const v8::FunctionCallbackInfo<v8::Value>& info) { |
316 ConsoleHelper helper(info); | 319 ConsoleHelper helper(info, m_inspector); |
317 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) | 320 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) |
318 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16())); | 321 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16())); |
319 } | 322 } |
320 | 323 |
321 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info, | 324 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info, |
322 bool timelinePrefix) { | 325 bool timelinePrefix, V8InspectorImpl* inspector) { |
323 ConsoleHelper helper(info); | 326 ConsoleHelper helper(info, inspector); |
324 V8InspectorClient* client = helper.inspector()->client(); | |
325 String16 protocolTitle = helper.firstArgToString("default"); | 327 String16 protocolTitle = helper.firstArgToString("default"); |
326 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; | 328 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; |
327 client->consoleTime(toStringView(protocolTitle)); | 329 inspector->client()->consoleTime(toStringView(protocolTitle)); |
328 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle); | 330 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle); |
329 } | 331 } |
330 | 332 |
331 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info, | 333 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info, |
332 bool timelinePrefix) { | 334 bool timelinePrefix, V8InspectorImpl* inspector) { |
333 ConsoleHelper helper(info); | 335 ConsoleHelper helper(info, inspector); |
334 V8InspectorClient* client = helper.inspector()->client(); | |
335 String16 protocolTitle = helper.firstArgToString("default"); | 336 String16 protocolTitle = helper.firstArgToString("default"); |
336 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; | 337 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; |
337 client->consoleTimeEnd(toStringView(protocolTitle)); | 338 inspector->client()->consoleTimeEnd(toStringView(protocolTitle)); |
338 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(), | 339 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(), |
339 protocolTitle); | 340 protocolTitle); |
340 String16 message = | 341 String16 message = |
341 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms"; | 342 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms"; |
342 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); | 343 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); |
343 } | 344 } |
344 | 345 |
345 void V8Console::timelineCallback( | 346 void V8Console::timelineCallback( |
346 const v8::FunctionCallbackInfo<v8::Value>& info) { | 347 const v8::FunctionCallbackInfo<v8::Value>& info) { |
347 ConsoleHelper(info).reportDeprecatedCall( | 348 ConsoleHelper(info, m_inspector) |
348 "V8Console#timeline", | 349 .reportDeprecatedCall("V8Console#timeline", |
349 "'console.timeline' is deprecated. Please use 'console.time' instead."); | 350 "'console.timeline' is deprecated. Please use " |
350 timeFunction(info, true); | 351 "'console.time' instead."); |
| 352 timeFunction(info, true, m_inspector); |
351 } | 353 } |
352 | 354 |
353 void V8Console::timelineEndCallback( | 355 void V8Console::timelineEndCallback( |
354 const v8::FunctionCallbackInfo<v8::Value>& info) { | 356 const v8::FunctionCallbackInfo<v8::Value>& info) { |
355 ConsoleHelper(info).reportDeprecatedCall("V8Console#timelineEnd", | 357 ConsoleHelper(info, m_inspector) |
356 "'console.timelineEnd' is " | 358 .reportDeprecatedCall("V8Console#timelineEnd", |
357 "deprecated. Please use " | 359 "'console.timelineEnd' is " |
358 "'console.timeEnd' instead."); | 360 "deprecated. Please use " |
359 timeEndFunction(info, true); | 361 "'console.timeEnd' instead."); |
| 362 timeEndFunction(info, true, m_inspector); |
360 } | 363 } |
361 | 364 |
362 void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 365 void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
363 timeFunction(info, false); | 366 timeFunction(info, false, m_inspector); |
364 } | 367 } |
365 | 368 |
366 void V8Console::timeEndCallback( | 369 void V8Console::timeEndCallback( |
367 const v8::FunctionCallbackInfo<v8::Value>& info) { | 370 const v8::FunctionCallbackInfo<v8::Value>& info) { |
368 timeEndFunction(info, false); | 371 timeEndFunction(info, false, m_inspector); |
369 } | 372 } |
370 | 373 |
371 void V8Console::timeStampCallback( | 374 void V8Console::timeStampCallback( |
372 const v8::FunctionCallbackInfo<v8::Value>& info) { | 375 const v8::FunctionCallbackInfo<v8::Value>& info) { |
373 ConsoleHelper helper(info); | 376 ConsoleHelper helper(info, m_inspector); |
374 String16 title = helper.firstArgToString(String16()); | 377 String16 title = helper.firstArgToString(String16()); |
375 helper.inspector()->client()->consoleTimeStamp(toStringView(title)); | 378 m_inspector->client()->consoleTimeStamp(toStringView(title)); |
376 } | 379 } |
377 | 380 |
378 void V8Console::memoryGetterCallback( | 381 void V8Console::memoryGetterCallback( |
379 const v8::FunctionCallbackInfo<v8::Value>& info) { | 382 const v8::FunctionCallbackInfo<v8::Value>& info) { |
380 V8InspectorClient* client = ConsoleHelper(info).inspector()->client(); | |
381 v8::Local<v8::Value> memoryValue; | 383 v8::Local<v8::Value> memoryValue; |
382 if (!client | 384 if (!m_inspector->client() |
383 ->memoryInfo(info.GetIsolate(), | 385 ->memoryInfo(info.GetIsolate(), |
384 info.GetIsolate()->GetCurrentContext()) | 386 info.GetIsolate()->GetCurrentContext()) |
385 .ToLocal(&memoryValue)) | 387 .ToLocal(&memoryValue)) |
386 return; | 388 return; |
387 info.GetReturnValue().Set(memoryValue); | 389 info.GetReturnValue().Set(memoryValue); |
388 } | 390 } |
389 | 391 |
390 void V8Console::memorySetterCallback( | 392 void V8Console::memorySetterCallback( |
391 const v8::FunctionCallbackInfo<v8::Value>& info) { | 393 const v8::FunctionCallbackInfo<v8::Value>& info) { |
392 // We can't make the attribute readonly as it breaks existing code that relies | 394 // We can't make the attribute readonly as it breaks existing code that relies |
393 // on being able to assign to console.memory in strict mode. Instead, the | 395 // on being able to assign to console.memory in strict mode. Instead, the |
394 // setter just ignores the passed value. http://crbug.com/468611 | 396 // setter just ignores the passed value. http://crbug.com/468611 |
395 } | 397 } |
396 | 398 |
397 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 399 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
398 v8::Isolate* isolate = info.GetIsolate(); | 400 v8::Isolate* isolate = info.GetIsolate(); |
399 info.GetReturnValue().Set(v8::Array::New(isolate)); | 401 info.GetReturnValue().Set(v8::Array::New(isolate)); |
400 | 402 |
401 ConsoleHelper helper(info); | 403 ConsoleHelper helper(info, m_inspector); |
402 v8::Local<v8::Object> obj; | 404 v8::Local<v8::Object> obj; |
403 if (!helper.firstArgAsObject().ToLocal(&obj)) return; | 405 if (!helper.firstArgAsObject().ToLocal(&obj)) return; |
404 v8::Local<v8::Array> names; | 406 v8::Local<v8::Array> names; |
405 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names)) | 407 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names)) |
406 return; | 408 return; |
407 info.GetReturnValue().Set(names); | 409 info.GetReturnValue().Set(names); |
408 } | 410 } |
409 | 411 |
410 void V8Console::valuesCallback( | 412 void V8Console::valuesCallback( |
411 const v8::FunctionCallbackInfo<v8::Value>& info) { | 413 const v8::FunctionCallbackInfo<v8::Value>& info) { |
412 v8::Isolate* isolate = info.GetIsolate(); | 414 v8::Isolate* isolate = info.GetIsolate(); |
413 info.GetReturnValue().Set(v8::Array::New(isolate)); | 415 info.GetReturnValue().Set(v8::Array::New(isolate)); |
414 | 416 |
415 ConsoleHelper helper(info); | 417 ConsoleHelper helper(info, m_inspector); |
416 v8::Local<v8::Object> obj; | 418 v8::Local<v8::Object> obj; |
417 if (!helper.firstArgAsObject().ToLocal(&obj)) return; | 419 if (!helper.firstArgAsObject().ToLocal(&obj)) return; |
418 v8::Local<v8::Array> names; | 420 v8::Local<v8::Array> names; |
419 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 421 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
420 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return; | 422 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return; |
421 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length()); | 423 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length()); |
422 for (uint32_t i = 0; i < names->Length(); ++i) { | 424 for (uint32_t i = 0; i < names->Length(); ++i) { |
423 v8::Local<v8::Value> key; | 425 v8::Local<v8::Value> key; |
424 if (!names->Get(context, i).ToLocal(&key)) continue; | 426 if (!names->Get(context, i).ToLocal(&key)) continue; |
425 v8::Local<v8::Value> value; | 427 v8::Local<v8::Value> value; |
(...skipping 18 matching lines...) Expand all Loading... |
444 if (enable) | 446 if (enable) |
445 debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source, | 447 debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source, |
446 condition); | 448 condition); |
447 else | 449 else |
448 debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber, | 450 debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber, |
449 source); | 451 source); |
450 } | 452 } |
451 | 453 |
452 void V8Console::debugFunctionCallback( | 454 void V8Console::debugFunctionCallback( |
453 const v8::FunctionCallbackInfo<v8::Value>& info) { | 455 const v8::FunctionCallbackInfo<v8::Value>& info) { |
454 ConsoleHelper helper(info); | 456 ConsoleHelper helper(info, m_inspector); |
455 v8::Local<v8::Function> function; | 457 v8::Local<v8::Function> function; |
456 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 458 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
457 setFunctionBreakpoint(helper, function, | 459 setFunctionBreakpoint(helper, function, |
458 V8DebuggerAgentImpl::DebugCommandBreakpointSource, | 460 V8DebuggerAgentImpl::DebugCommandBreakpointSource, |
459 String16(), true); | 461 String16(), true); |
460 } | 462 } |
461 | 463 |
462 void V8Console::undebugFunctionCallback( | 464 void V8Console::undebugFunctionCallback( |
463 const v8::FunctionCallbackInfo<v8::Value>& info) { | 465 const v8::FunctionCallbackInfo<v8::Value>& info) { |
464 ConsoleHelper helper(info); | 466 ConsoleHelper helper(info, m_inspector); |
465 v8::Local<v8::Function> function; | 467 v8::Local<v8::Function> function; |
466 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 468 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
467 setFunctionBreakpoint(helper, function, | 469 setFunctionBreakpoint(helper, function, |
468 V8DebuggerAgentImpl::DebugCommandBreakpointSource, | 470 V8DebuggerAgentImpl::DebugCommandBreakpointSource, |
469 String16(), false); | 471 String16(), false); |
470 } | 472 } |
471 | 473 |
472 void V8Console::monitorFunctionCallback( | 474 void V8Console::monitorFunctionCallback( |
473 const v8::FunctionCallbackInfo<v8::Value>& info) { | 475 const v8::FunctionCallbackInfo<v8::Value>& info) { |
474 ConsoleHelper helper(info); | 476 ConsoleHelper helper(info, m_inspector); |
475 v8::Local<v8::Function> function; | 477 v8::Local<v8::Function> function; |
476 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 478 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
477 v8::Local<v8::Value> name = function->GetName(); | 479 v8::Local<v8::Value> name = function->GetName(); |
478 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) | 480 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) |
479 name = function->GetInferredName(); | 481 name = function->GetInferredName(); |
480 String16 functionName = toProtocolStringWithTypeCheck(name); | 482 String16 functionName = toProtocolStringWithTypeCheck(name); |
481 String16Builder builder; | 483 String16Builder builder; |
482 builder.append("console.log(\"function "); | 484 builder.append("console.log(\"function "); |
483 if (functionName.isEmpty()) | 485 if (functionName.isEmpty()) |
484 builder.append("(anonymous function)"); | 486 builder.append("(anonymous function)"); |
485 else | 487 else |
486 builder.append(functionName); | 488 builder.append(functionName); |
487 builder.append( | 489 builder.append( |
488 " called\" + (arguments.length > 0 ? \" with arguments: \" + " | 490 " called\" + (arguments.length > 0 ? \" with arguments: \" + " |
489 "Array.prototype.join.call(arguments, \", \") : \"\")) && false"); | 491 "Array.prototype.join.call(arguments, \", \") : \"\")) && false"); |
490 setFunctionBreakpoint(helper, function, | 492 setFunctionBreakpoint(helper, function, |
491 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, | 493 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, |
492 builder.toString(), true); | 494 builder.toString(), true); |
493 } | 495 } |
494 | 496 |
495 void V8Console::unmonitorFunctionCallback( | 497 void V8Console::unmonitorFunctionCallback( |
496 const v8::FunctionCallbackInfo<v8::Value>& info) { | 498 const v8::FunctionCallbackInfo<v8::Value>& info) { |
497 ConsoleHelper helper(info); | 499 ConsoleHelper helper(info, m_inspector); |
498 v8::Local<v8::Function> function; | 500 v8::Local<v8::Function> function; |
499 if (!helper.firstArgAsFunction().ToLocal(&function)) return; | 501 if (!helper.firstArgAsFunction().ToLocal(&function)) return; |
500 setFunctionBreakpoint(helper, function, | 502 setFunctionBreakpoint(helper, function, |
501 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, | 503 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, |
502 String16(), false); | 504 String16(), false); |
503 } | 505 } |
504 | 506 |
505 void V8Console::lastEvaluationResultCallback( | 507 void V8Console::lastEvaluationResultCallback( |
506 const v8::FunctionCallbackInfo<v8::Value>& info) { | 508 const v8::FunctionCallbackInfo<v8::Value>& info) { |
507 ConsoleHelper helper(info); | 509 ConsoleHelper helper(info, m_inspector); |
508 InjectedScript* injectedScript = helper.injectedScript(); | 510 InjectedScript* injectedScript = helper.injectedScript(); |
509 if (!injectedScript) return; | 511 if (!injectedScript) return; |
510 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); | 512 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); |
511 } | 513 } |
512 | 514 |
513 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, | 515 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, |
514 bool copyToClipboard) { | 516 bool copyToClipboard, V8InspectorImpl* inspector) { |
515 if (info.Length() < 1) return; | 517 if (info.Length() < 1) return; |
516 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); | 518 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); |
517 | 519 |
518 ConsoleHelper helper(info); | 520 ConsoleHelper helper(info, inspector); |
519 InjectedScript* injectedScript = helper.injectedScript(); | 521 InjectedScript* injectedScript = helper.injectedScript(); |
520 if (!injectedScript) return; | 522 if (!injectedScript) return; |
521 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; | 523 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; |
522 protocol::Response response = | 524 protocol::Response response = |
523 injectedScript->wrapObject(info[0], "", false /** forceValueType */, | 525 injectedScript->wrapObject(info[0], "", false /** forceValueType */, |
524 false /** generatePreview */, &wrappedObject); | 526 false /** generatePreview */, &wrappedObject); |
525 if (!response.isSuccess()) return; | 527 if (!response.isSuccess()) return; |
526 | 528 |
527 std::unique_ptr<protocol::DictionaryValue> hints = | 529 std::unique_ptr<protocol::DictionaryValue> hints = |
528 protocol::DictionaryValue::create(); | 530 protocol::DictionaryValue::create(); |
529 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); | 531 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); |
530 if (V8InspectorSessionImpl* session = helper.currentSession()) { | 532 if (V8InspectorSessionImpl* session = helper.currentSession()) { |
531 session->runtimeAgent()->inspect(std::move(wrappedObject), | 533 session->runtimeAgent()->inspect(std::move(wrappedObject), |
532 std::move(hints)); | 534 std::move(hints)); |
533 } | 535 } |
534 } | 536 } |
535 | 537 |
536 void V8Console::inspectCallback( | 538 void V8Console::inspectCallback( |
537 const v8::FunctionCallbackInfo<v8::Value>& info) { | 539 const v8::FunctionCallbackInfo<v8::Value>& info) { |
538 inspectImpl(info, false); | 540 inspectImpl(info, false, m_inspector); |
539 } | 541 } |
540 | 542 |
541 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 543 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
542 inspectImpl(info, true); | 544 inspectImpl(info, true, m_inspector); |
543 } | 545 } |
544 | 546 |
545 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, | 547 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, |
546 unsigned num) { | 548 unsigned num) { |
547 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize); | 549 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize); |
548 ConsoleHelper helper(info); | 550 ConsoleHelper helper(info, m_inspector); |
549 if (V8InspectorSessionImpl* session = helper.currentSession()) { | 551 if (V8InspectorSessionImpl* session = helper.currentSession()) { |
550 V8InspectorSession::Inspectable* object = session->inspectedObject(num); | 552 V8InspectorSession::Inspectable* object = session->inspectedObject(num); |
551 v8::Isolate* isolate = info.GetIsolate(); | 553 v8::Isolate* isolate = info.GetIsolate(); |
552 if (object) | 554 if (object) |
553 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); | 555 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); |
554 else | 556 else |
555 info.GetReturnValue().Set(v8::Undefined(isolate)); | 557 info.GetReturnValue().Set(v8::Undefined(isolate)); |
556 } | 558 } |
557 } | 559 } |
558 | 560 |
559 v8::Local<v8::Object> V8Console::createConsole( | 561 v8::Local<v8::Object> V8Console::createConsole(v8::Local<v8::Context> context) { |
560 InspectedContext* inspectedContext) { | |
561 v8::Local<v8::Context> context = inspectedContext->context(); | |
562 v8::Context::Scope contextScope(context); | 562 v8::Context::Scope contextScope(context); |
563 v8::Isolate* isolate = context->GetIsolate(); | 563 v8::Isolate* isolate = context->GetIsolate(); |
564 v8::MicrotasksScope microtasksScope(isolate, | 564 v8::MicrotasksScope microtasksScope(isolate, |
565 v8::MicrotasksScope::kDoNotRunMicrotasks); | 565 v8::MicrotasksScope::kDoNotRunMicrotasks); |
566 | 566 |
567 v8::Local<v8::Object> console = v8::Object::New(isolate); | 567 v8::Local<v8::Object> console = v8::Object::New(isolate); |
568 bool success = | 568 bool success = |
569 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false); | 569 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false); |
570 DCHECK(success); | 570 DCHECK(success); |
571 USE(success); | 571 USE(success); |
572 | 572 |
573 v8::Local<v8::External> data = | 573 v8::Local<v8::External> data = v8::External::New(isolate, this); |
574 v8::External::New(isolate, inspectedContext->inspector()); | |
575 createBoundFunctionProperty(context, console, data, "debug", | 574 createBoundFunctionProperty(context, console, data, "debug", |
576 V8Console::debugCallback); | 575 &V8Console::call<&V8Console::debugCallback>); |
577 createBoundFunctionProperty(context, console, data, "error", | 576 createBoundFunctionProperty(context, console, data, "error", |
578 V8Console::errorCallback); | 577 &V8Console::call<&V8Console::errorCallback>); |
579 createBoundFunctionProperty(context, console, data, "info", | 578 createBoundFunctionProperty(context, console, data, "info", |
580 V8Console::infoCallback); | 579 &V8Console::call<&V8Console::infoCallback>); |
581 createBoundFunctionProperty(context, console, data, "log", | 580 createBoundFunctionProperty(context, console, data, "log", |
582 V8Console::logCallback); | 581 &V8Console::call<&V8Console::logCallback>); |
583 createBoundFunctionProperty(context, console, data, "warn", | 582 createBoundFunctionProperty(context, console, data, "warn", |
584 V8Console::warnCallback); | 583 &V8Console::call<&V8Console::warnCallback>); |
585 createBoundFunctionProperty(context, console, data, "dir", | 584 createBoundFunctionProperty(context, console, data, "dir", |
586 V8Console::dirCallback); | 585 &V8Console::call<&V8Console::dirCallback>); |
587 createBoundFunctionProperty(context, console, data, "dirxml", | 586 createBoundFunctionProperty(context, console, data, "dirxml", |
588 V8Console::dirxmlCallback); | 587 &V8Console::call<&V8Console::dirxmlCallback>); |
589 createBoundFunctionProperty(context, console, data, "table", | 588 createBoundFunctionProperty(context, console, data, "table", |
590 V8Console::tableCallback); | 589 &V8Console::call<&V8Console::tableCallback>); |
591 createBoundFunctionProperty(context, console, data, "trace", | 590 createBoundFunctionProperty(context, console, data, "trace", |
592 V8Console::traceCallback); | 591 &V8Console::call<&V8Console::traceCallback>); |
593 createBoundFunctionProperty(context, console, data, "group", | 592 createBoundFunctionProperty(context, console, data, "group", |
594 V8Console::groupCallback); | 593 &V8Console::call<&V8Console::groupCallback>); |
595 createBoundFunctionProperty(context, console, data, "groupCollapsed", | 594 createBoundFunctionProperty( |
596 V8Console::groupCollapsedCallback); | 595 context, console, data, "groupCollapsed", |
| 596 &V8Console::call<&V8Console::groupCollapsedCallback>); |
597 createBoundFunctionProperty(context, console, data, "groupEnd", | 597 createBoundFunctionProperty(context, console, data, "groupEnd", |
598 V8Console::groupEndCallback); | 598 &V8Console::call<&V8Console::groupEndCallback>); |
599 createBoundFunctionProperty(context, console, data, "clear", | 599 createBoundFunctionProperty(context, console, data, "clear", |
600 V8Console::clearCallback); | 600 &V8Console::call<&V8Console::clearCallback>); |
601 createBoundFunctionProperty(context, console, data, "count", | 601 createBoundFunctionProperty(context, console, data, "count", |
602 V8Console::countCallback); | 602 &V8Console::call<&V8Console::countCallback>); |
603 createBoundFunctionProperty(context, console, data, "assert", | 603 createBoundFunctionProperty(context, console, data, "assert", |
604 V8Console::assertCallback); | 604 &V8Console::call<&V8Console::assertCallback>); |
605 createBoundFunctionProperty(context, console, data, "markTimeline", | 605 createBoundFunctionProperty( |
606 V8Console::markTimelineCallback); | 606 context, console, data, "markTimeline", |
| 607 &V8Console::call<&V8Console::markTimelineCallback>); |
607 createBoundFunctionProperty(context, console, data, "profile", | 608 createBoundFunctionProperty(context, console, data, "profile", |
608 V8Console::profileCallback); | 609 &V8Console::call<&V8Console::profileCallback>); |
609 createBoundFunctionProperty(context, console, data, "profileEnd", | 610 createBoundFunctionProperty(context, console, data, "profileEnd", |
610 V8Console::profileEndCallback); | 611 &V8Console::call<&V8Console::profileEndCallback>); |
611 createBoundFunctionProperty(context, console, data, "timeline", | 612 createBoundFunctionProperty(context, console, data, "timeline", |
612 V8Console::timelineCallback); | 613 &V8Console::call<&V8Console::timelineCallback>); |
613 createBoundFunctionProperty(context, console, data, "timelineEnd", | 614 createBoundFunctionProperty( |
614 V8Console::timelineEndCallback); | 615 context, console, data, "timelineEnd", |
| 616 &V8Console::call<&V8Console::timelineEndCallback>); |
615 createBoundFunctionProperty(context, console, data, "time", | 617 createBoundFunctionProperty(context, console, data, "time", |
616 V8Console::timeCallback); | 618 &V8Console::call<&V8Console::timeCallback>); |
617 createBoundFunctionProperty(context, console, data, "timeEnd", | 619 createBoundFunctionProperty(context, console, data, "timeEnd", |
618 V8Console::timeEndCallback); | 620 &V8Console::call<&V8Console::timeEndCallback>); |
619 createBoundFunctionProperty(context, console, data, "timeStamp", | 621 createBoundFunctionProperty(context, console, data, "timeStamp", |
620 V8Console::timeStampCallback); | 622 &V8Console::call<&V8Console::timeStampCallback>); |
621 return console; | 623 return console; |
622 } | 624 } |
623 | 625 |
624 void V8Console::installMemoryGetter(V8InspectorImpl* inspector, | 626 void V8Console::installMemoryGetter(v8::Local<v8::Context> context, |
625 v8::Local<v8::Context> context, | |
626 v8::Local<v8::Object> console) { | 627 v8::Local<v8::Object> console) { |
627 v8::Local<v8::External> data = | 628 v8::Isolate* isolate = context->GetIsolate(); |
628 v8::External::New(inspector->isolate(), inspector); | 629 v8::Local<v8::External> data = v8::External::New(isolate, this); |
629 console->SetAccessorProperty( | 630 console->SetAccessorProperty( |
630 toV8StringInternalized(inspector->isolate(), "memory"), | 631 toV8StringInternalized(isolate, "memory"), |
631 v8::Function::New(context, V8Console::memoryGetterCallback, data, 0, | 632 v8::Function::New(context, |
632 v8::ConstructorBehavior::kThrow) | 633 &V8Console::call<&V8Console::memoryGetterCallback>, |
| 634 data, 0, v8::ConstructorBehavior::kThrow) |
633 .ToLocalChecked(), | 635 .ToLocalChecked(), |
634 v8::Function::New(context, V8Console::memorySetterCallback, data, 0, | 636 v8::Function::New(context, |
635 v8::ConstructorBehavior::kThrow) | 637 &V8Console::call<&V8Console::memorySetterCallback>, |
| 638 data, 0, v8::ConstructorBehavior::kThrow) |
636 .ToLocalChecked(), | 639 .ToLocalChecked(), |
637 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); | 640 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); |
638 } | 641 } |
639 | 642 |
640 v8::Local<v8::Object> V8Console::createCommandLineAPI( | 643 v8::Local<v8::Object> V8Console::createCommandLineAPI( |
641 InspectedContext* inspectedContext) { | 644 v8::Local<v8::Context> context) { |
642 v8::Local<v8::Context> context = inspectedContext->context(); | |
643 v8::Isolate* isolate = context->GetIsolate(); | 645 v8::Isolate* isolate = context->GetIsolate(); |
644 v8::MicrotasksScope microtasksScope(isolate, | 646 v8::MicrotasksScope microtasksScope(isolate, |
645 v8::MicrotasksScope::kDoNotRunMicrotasks); | 647 v8::MicrotasksScope::kDoNotRunMicrotasks); |
646 | 648 |
647 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); | 649 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); |
648 bool success = | 650 bool success = |
649 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); | 651 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); |
650 DCHECK(success); | 652 DCHECK(success); |
651 USE(success); | 653 USE(success); |
652 | 654 |
653 v8::Local<v8::External> data = | 655 v8::Local<v8::External> data = v8::External::New(isolate, this); |
654 v8::External::New(isolate, inspectedContext->inspector()); | |
655 createBoundFunctionProperty(context, commandLineAPI, data, "dir", | 656 createBoundFunctionProperty(context, commandLineAPI, data, "dir", |
656 V8Console::dirCallback, | 657 &V8Console::call<&V8Console::dirCallback>, |
657 "function dir(value) { [Command Line API] }"); | 658 "function dir(value) { [Command Line API] }"); |
658 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml", | 659 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml", |
659 V8Console::dirxmlCallback, | 660 &V8Console::call<&V8Console::dirxmlCallback>, |
660 "function dirxml(value) { [Command Line API] }"); | 661 "function dirxml(value) { [Command Line API] }"); |
661 createBoundFunctionProperty(context, commandLineAPI, data, "profile", | 662 createBoundFunctionProperty(context, commandLineAPI, data, "profile", |
662 V8Console::profileCallback, | 663 &V8Console::call<&V8Console::profileCallback>, |
663 "function profile(title) { [Command Line API] }"); | 664 "function profile(title) { [Command Line API] }"); |
664 createBoundFunctionProperty( | 665 createBoundFunctionProperty( |
665 context, commandLineAPI, data, "profileEnd", | 666 context, commandLineAPI, data, "profileEnd", |
666 V8Console::profileEndCallback, | 667 &V8Console::call<&V8Console::profileEndCallback>, |
667 "function profileEnd(title) { [Command Line API] }"); | 668 "function profileEnd(title) { [Command Line API] }"); |
668 createBoundFunctionProperty(context, commandLineAPI, data, "clear", | 669 createBoundFunctionProperty(context, commandLineAPI, data, "clear", |
669 V8Console::clearCallback, | 670 &V8Console::call<&V8Console::clearCallback>, |
670 "function clear() { [Command Line API] }"); | 671 "function clear() { [Command Line API] }"); |
671 createBoundFunctionProperty( | 672 createBoundFunctionProperty( |
672 context, commandLineAPI, data, "table", V8Console::tableCallback, | 673 context, commandLineAPI, data, "table", |
| 674 &V8Console::call<&V8Console::tableCallback>, |
673 "function table(data, [columns]) { [Command Line API] }"); | 675 "function table(data, [columns]) { [Command Line API] }"); |
674 | 676 |
675 createBoundFunctionProperty(context, commandLineAPI, data, "keys", | 677 createBoundFunctionProperty(context, commandLineAPI, data, "keys", |
676 V8Console::keysCallback, | 678 &V8Console::call<&V8Console::keysCallback>, |
677 "function keys(object) { [Command Line API] }"); | 679 "function keys(object) { [Command Line API] }"); |
678 createBoundFunctionProperty(context, commandLineAPI, data, "values", | 680 createBoundFunctionProperty(context, commandLineAPI, data, "values", |
679 V8Console::valuesCallback, | 681 &V8Console::call<&V8Console::valuesCallback>, |
680 "function values(object) { [Command Line API] }"); | 682 "function values(object) { [Command Line API] }"); |
681 createBoundFunctionProperty( | 683 createBoundFunctionProperty( |
682 context, commandLineAPI, data, "debug", V8Console::debugFunctionCallback, | 684 context, commandLineAPI, data, "debug", |
| 685 &V8Console::call<&V8Console::debugFunctionCallback>, |
683 "function debug(function) { [Command Line API] }"); | 686 "function debug(function) { [Command Line API] }"); |
684 createBoundFunctionProperty( | 687 createBoundFunctionProperty( |
685 context, commandLineAPI, data, "undebug", | 688 context, commandLineAPI, data, "undebug", |
686 V8Console::undebugFunctionCallback, | 689 &V8Console::call<&V8Console::undebugFunctionCallback>, |
687 "function undebug(function) { [Command Line API] }"); | 690 "function undebug(function) { [Command Line API] }"); |
688 createBoundFunctionProperty( | 691 createBoundFunctionProperty( |
689 context, commandLineAPI, data, "monitor", | 692 context, commandLineAPI, data, "monitor", |
690 V8Console::monitorFunctionCallback, | 693 &V8Console::call<&V8Console::monitorFunctionCallback>, |
691 "function monitor(function) { [Command Line API] }"); | 694 "function monitor(function) { [Command Line API] }"); |
692 createBoundFunctionProperty( | 695 createBoundFunctionProperty( |
693 context, commandLineAPI, data, "unmonitor", | 696 context, commandLineAPI, data, "unmonitor", |
694 V8Console::unmonitorFunctionCallback, | 697 &V8Console::call<&V8Console::unmonitorFunctionCallback>, |
695 "function unmonitor(function) { [Command Line API] }"); | 698 "function unmonitor(function) { [Command Line API] }"); |
696 createBoundFunctionProperty( | 699 createBoundFunctionProperty( |
697 context, commandLineAPI, data, "inspect", V8Console::inspectCallback, | 700 context, commandLineAPI, data, "inspect", |
| 701 &V8Console::call<&V8Console::inspectCallback>, |
698 "function inspect(object) { [Command Line API] }"); | 702 "function inspect(object) { [Command Line API] }"); |
699 createBoundFunctionProperty(context, commandLineAPI, data, "copy", | 703 createBoundFunctionProperty(context, commandLineAPI, data, "copy", |
700 V8Console::copyCallback, | 704 &V8Console::call<&V8Console::copyCallback>, |
701 "function copy(value) { [Command Line API] }"); | 705 "function copy(value) { [Command Line API] }"); |
702 createBoundFunctionProperty(context, commandLineAPI, data, "$_", | 706 createBoundFunctionProperty( |
703 V8Console::lastEvaluationResultCallback); | 707 context, commandLineAPI, data, "$_", |
| 708 &V8Console::call<&V8Console::lastEvaluationResultCallback>); |
704 createBoundFunctionProperty(context, commandLineAPI, data, "$0", | 709 createBoundFunctionProperty(context, commandLineAPI, data, "$0", |
705 V8Console::inspectedObject0); | 710 &V8Console::call<&V8Console::inspectedObject0>); |
706 createBoundFunctionProperty(context, commandLineAPI, data, "$1", | 711 createBoundFunctionProperty(context, commandLineAPI, data, "$1", |
707 V8Console::inspectedObject1); | 712 &V8Console::call<&V8Console::inspectedObject1>); |
708 createBoundFunctionProperty(context, commandLineAPI, data, "$2", | 713 createBoundFunctionProperty(context, commandLineAPI, data, "$2", |
709 V8Console::inspectedObject2); | 714 &V8Console::call<&V8Console::inspectedObject2>); |
710 createBoundFunctionProperty(context, commandLineAPI, data, "$3", | 715 createBoundFunctionProperty(context, commandLineAPI, data, "$3", |
711 V8Console::inspectedObject3); | 716 &V8Console::call<&V8Console::inspectedObject3>); |
712 createBoundFunctionProperty(context, commandLineAPI, data, "$4", | 717 createBoundFunctionProperty(context, commandLineAPI, data, "$4", |
713 V8Console::inspectedObject4); | 718 &V8Console::call<&V8Console::inspectedObject4>); |
714 | 719 |
715 inspectedContext->inspector()->client()->installAdditionalCommandLineAPI( | 720 m_inspector->client()->installAdditionalCommandLineAPI(context, |
716 context, commandLineAPI); | 721 commandLineAPI); |
717 return commandLineAPI; | 722 return commandLineAPI; |
718 } | 723 } |
719 | 724 |
720 static bool isCommandLineAPIGetter(const String16& name) { | 725 static bool isCommandLineAPIGetter(const String16& name) { |
721 if (name.length() != 2) return false; | 726 if (name.length() != 2) return false; |
722 // $0 ... $4, $_ | 727 // $0 ... $4, $_ |
723 return name[0] == '$' && | 728 return name[0] == '$' && |
724 ((name[1] >= '0' && name[1] <= '4') || name[1] == '_'); | 729 ((name[1] >= '0' && name[1] <= '4') || name[1] == '_'); |
725 } | 730 } |
726 | 731 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 ->GetOwnPropertyDescriptor( | 818 ->GetOwnPropertyDescriptor( |
814 m_context, v8::Local<v8::String>::Cast(name)) | 819 m_context, v8::Local<v8::String>::Cast(name)) |
815 .ToLocal(&descriptor); | 820 .ToLocal(&descriptor); |
816 DCHECK(success); | 821 DCHECK(success); |
817 USE(success); | 822 USE(success); |
818 } | 823 } |
819 } | 824 } |
820 } | 825 } |
821 | 826 |
822 } // namespace v8_inspector | 827 } // namespace v8_inspector |
OLD | NEW |