Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8Console.cpp

Issue 2139363003: [DevTools] Cleanup v8_inspector API part 1. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium 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 "platform/v8_inspector/V8Console.h" 5 #include "platform/v8_inspector/V8Console.h"
6 6
7 #include "platform/inspector_protocol/Platform.h" 7 #include "platform/inspector_protocol/Platform.h"
8 #include "platform/inspector_protocol/String16.h" 8 #include "platform/inspector_protocol/String16.h"
9 #include "platform/v8_inspector/InjectedScript.h" 9 #include "platform/v8_inspector/InjectedScript.h"
10 #include "platform/v8_inspector/InspectedContext.h" 10 #include "platform/v8_inspector/InspectedContext.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 { 69 {
70 if (m_debuggerClient) 70 if (m_debuggerClient)
71 return m_debuggerClient; 71 return m_debuggerClient;
72 InspectedContext* inspectedContext = ensureInspectedContext(); 72 InspectedContext* inspectedContext = ensureInspectedContext();
73 if (!inspectedContext) 73 if (!inspectedContext)
74 return nullptr; 74 return nullptr;
75 m_debuggerClient = inspectedContext->debugger()->client(); 75 m_debuggerClient = inspectedContext->debugger()->client();
76 return m_debuggerClient; 76 return m_debuggerClient;
77 } 77 }
78 78
79 void reportMessageToConsole(v8::Local<v8::Context> context, MessageType type , MessageLevel level, const String16& message, const v8::FunctionCallbackInfo<v8 ::Value>* arguments, unsigned skipArgumentCount) 79 void reportMessageToConsole(v8::Local<v8::Context> context, ConsoleAPIType t ype, MessageLevel level, const String16& message, const v8::FunctionCallbackInfo <v8::Value>* arguments, unsigned skipArgumentCount)
80 { 80 {
81 InspectedContext* inspectedContext = ensureInspectedContext(); 81 InspectedContext* inspectedContext = ensureInspectedContext();
82 if (!inspectedContext) 82 if (!inspectedContext)
83 return; 83 return;
84 V8DebuggerImpl* debugger = inspectedContext->debugger(); 84 V8DebuggerImpl* debugger = inspectedContext->debugger();
85 85
86 std::unique_ptr<V8ConsoleMessage> consoleMessage = nullptr; 86 std::unique_ptr<V8ConsoleMessage> consoleMessage = nullptr;
87 if (arguments) { 87 if (arguments) {
88 std::vector<v8::Local<v8::Value>> messageArguments; 88 std::vector<v8::Local<v8::Value>> messageArguments;
89 for (int i = skipArgumentCount; i < arguments->Length(); ++i) 89 for (int i = skipArgumentCount; i < arguments->Length(); ++i)
90 messageArguments.push_back((*arguments)[i]); 90 messageArguments.push_back((*arguments)[i]);
91 consoleMessage = V8ConsoleMessage::createForConsoleAPI(debugger->cli ent()->currentTimeMS(), type, level, message, &messageArguments, debugger->captu reStackTrace(false), inspectedContext); 91 consoleMessage = V8ConsoleMessage::createForConsoleAPI(debugger->cli ent()->currentTimeMS(), type, level, message, &messageArguments, debugger->captu reStackTrace(false), inspectedContext);
92 } else { 92 } else {
93 consoleMessage = V8ConsoleMessage::createForConsoleAPI(debugger->cli ent()->currentTimeMS(), type, level, message, nullptr, debugger->captureStackTra ce(false), inspectedContext); 93 consoleMessage = V8ConsoleMessage::createForConsoleAPI(debugger->cli ent()->currentTimeMS(), type, level, message, nullptr, debugger->captureStackTra ce(false), inspectedContext);
94 } 94 }
95 debugger->ensureConsoleMessageStorage(inspectedContext->contextGroupId() )->addMessage(std::move(consoleMessage)); 95 debugger->ensureConsoleMessageStorage(inspectedContext->contextGroupId() )->addMessage(std::move(consoleMessage));
96 } 96 }
97 97
98 void addMessage(MessageType type, MessageLevel level, String16 emptyText, in t skipArgumentCount) 98 void addMessage(ConsoleAPIType type, MessageLevel level, String16 emptyText, int skipArgumentCount)
99 { 99 {
100 if (emptyText.isEmpty() && !m_info.Length()) 100 if (emptyText.isEmpty() && !m_info.Length())
101 return; 101 return;
102 reportMessageToConsole(m_context, type, level, m_info.Length() <= skipAr gumentCount ? emptyText : String16(), &m_info, skipArgumentCount); 102 reportMessageToConsole(m_context, type, level, m_info.Length() <= skipAr gumentCount ? emptyText : String16(), &m_info, skipArgumentCount);
103 } 103 }
104 104
105 void addMessage(MessageType type, MessageLevel level, const String16& messag e) 105 void addMessage(ConsoleAPIType type, MessageLevel level, const String16& mes sage)
106 { 106 {
107 reportMessageToConsole(m_context, type, level, message, nullptr, 0 /* sk ipArgumentsCount */); 107 reportMessageToConsole(m_context, type, level, message, nullptr, 0 /* sk ipArgumentsCount */);
108 } 108 }
109 109
110 void addDeprecationMessage(const char* id, const String16& message) 110 void addDeprecationMessage(const char* id, const String16& message)
111 { 111 {
112 if (checkAndSetPrivateFlagOnConsole(id, false)) 112 if (checkAndSetPrivateFlagOnConsole(id, false))
113 return; 113 return;
114 reportMessageToConsole(m_context, LogMessageType, WarningMessageLevel, m essage, nullptr, 0 /* skipArgumentsCount */); 114 reportMessageToConsole(m_context, ConsoleAPIType::kLog, WarningMessageLe vel, message, nullptr, 0 /* skipArgumentsCount */);
115 } 115 }
116 116
117 bool firstArgToBoolean(bool defaultValue) 117 bool firstArgToBoolean(bool defaultValue)
118 { 118 {
119 if (m_info.Length() < 1) 119 if (m_info.Length() < 1)
120 return defaultValue; 120 return defaultValue;
121 if (m_info[0]->IsBoolean()) 121 if (m_info[0]->IsBoolean())
122 return m_info[0].As<v8::Boolean>()->Value(); 122 return m_info[0].As<v8::Boolean>()->Value();
123 return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue); 123 return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue);
124 } 124 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 func->Set(toV8StringInternalized(context->GetIsolate(), "toString"), toStringFunction); 275 func->Set(toV8StringInternalized(context->GetIsolate(), "toString"), toStringFunction);
276 } 276 }
277 if (!console->Set(context, funcName, func).FromMaybe(false)) 277 if (!console->Set(context, funcName, func).FromMaybe(false))
278 return; 278 return;
279 } 279 }
280 280
281 } // namespace 281 } // namespace
282 282
283 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 283 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
284 { 284 {
285 ConsoleHelper(info).addMessage(LogMessageType, DebugMessageLevel, String16() , 0); 285 ConsoleHelper(info).addMessage(ConsoleAPIType::kLog, DebugMessageLevel, Stri ng16(), 0);
286 } 286 }
287 287
288 void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 288 void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
289 { 289 {
290 ConsoleHelper(info).addMessage(LogMessageType, ErrorMessageLevel, String16() , 0); 290 ConsoleHelper(info).addMessage(ConsoleAPIType::kLog, ErrorMessageLevel, Stri ng16(), 0);
291 } 291 }
292 292
293 void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 293 void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
294 { 294 {
295 ConsoleHelper(info).addMessage(LogMessageType, InfoMessageLevel, String16(), 0); 295 ConsoleHelper(info).addMessage(ConsoleAPIType::kLog, InfoMessageLevel, Strin g16(), 0);
296 } 296 }
297 297
298 void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 298 void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
299 { 299 {
300 ConsoleHelper(info).addMessage(LogMessageType, LogMessageLevel, String16(), 0); 300 ConsoleHelper(info).addMessage(ConsoleAPIType::kLog, LogMessageLevel, String 16(), 0);
301 } 301 }
302 302
303 void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 303 void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
304 { 304 {
305 ConsoleHelper(info).addMessage(LogMessageType, WarningMessageLevel, String16 (), 0); 305 ConsoleHelper(info).addMessage(ConsoleAPIType::kLog, WarningMessageLevel, St ring16(), 0);
306 } 306 }
307 307
308 void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 308 void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
309 { 309 {
310 ConsoleHelper(info).addMessage(DirMessageType, LogMessageLevel, String16(), 0); 310 ConsoleHelper(info).addMessage(ConsoleAPIType::kDir, LogMessageLevel, String 16(), 0);
311 } 311 }
312 312
313 void V8Console::dirxmlCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 313 void V8Console::dirxmlCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
314 { 314 {
315 ConsoleHelper(info).addMessage(DirXMLMessageType, LogMessageLevel, String16( ), 0); 315 ConsoleHelper(info).addMessage(ConsoleAPIType::kDirXML, LogMessageLevel, Str ing16(), 0);
316 } 316 }
317 317
318 void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 318 void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
319 { 319 {
320 ConsoleHelper(info).addMessage(TableMessageType, LogMessageLevel, String16() , 0); 320 ConsoleHelper(info).addMessage(ConsoleAPIType::kTable, LogMessageLevel, Stri ng16(), 0);
321 } 321 }
322 322
323 void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 323 void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
324 { 324 {
325 ConsoleHelper(info).addMessage(TraceMessageType, LogMessageLevel, String16(" console.trace"), 0); 325 ConsoleHelper(info).addMessage(ConsoleAPIType::kTrace, LogMessageLevel, Stri ng16("console.trace"), 0);
326 } 326 }
327 327
328 void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 328 void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
329 { 329 {
330 ConsoleHelper(info).addMessage(StartGroupMessageType, LogMessageLevel, Strin g16("console.group"), 0); 330 ConsoleHelper(info).addMessage(ConsoleAPIType::kStartGroup, LogMessageLevel, String16("console.group"), 0);
331 } 331 }
332 332
333 void V8Console::groupCollapsedCallback(const v8::FunctionCallbackInfo<v8::Value> & info) 333 void V8Console::groupCollapsedCallback(const v8::FunctionCallbackInfo<v8::Value> & info)
334 { 334 {
335 ConsoleHelper(info).addMessage(StartGroupCollapsedMessageType, LogMessageLev el, String16("console.groupCollapsed"), 0); 335 ConsoleHelper(info).addMessage(ConsoleAPIType::kStartGroupCollapsed, LogMess ageLevel, String16("console.groupCollapsed"), 0);
336 } 336 }
337 337
338 void V8Console::groupEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info ) 338 void V8Console::groupEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info )
339 { 339 {
340 ConsoleHelper(info).addMessage(EndGroupMessageType, LogMessageLevel, String1 6("console.groupEnd"), 0); 340 ConsoleHelper(info).addMessage(ConsoleAPIType::kEndGroup, LogMessageLevel, S tring16("console.groupEnd"), 0);
341 } 341 }
342 342
343 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 343 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
344 { 344 {
345 ConsoleHelper(info).addMessage(ClearMessageType, LogMessageLevel, String16(" console.clear"), 0); 345 ConsoleHelper(info).addMessage(ConsoleAPIType::kClear, LogMessageLevel, Stri ng16("console.clear"), 0);
346 } 346 }
347 347
348 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 348 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
349 { 349 {
350 ConsoleHelper helper(info); 350 ConsoleHelper helper(info);
351 351
352 String16 title = helper.firstArgToString(String16()); 352 String16 title = helper.firstArgToString(String16());
353 String16 identifier; 353 String16 identifier;
354 if (title.isEmpty()) { 354 if (title.isEmpty()) {
355 std::unique_ptr<V8StackTraceImpl> stackTrace = V8StackTraceImpl::capture (nullptr, 0, 1); 355 std::unique_ptr<V8StackTraceImpl> stackTrace = V8StackTraceImpl::capture (nullptr, 0, 1);
356 if (stackTrace) 356 if (stackTrace)
357 identifier = stackTrace->topSourceURL() + ":" + String16::number(sta ckTrace->topLineNumber()); 357 identifier = stackTrace->topSourceURL() + ":" + String16::number(sta ckTrace->topLineNumber());
358 } else { 358 } else {
359 identifier = title + "@"; 359 identifier = title + "@";
360 } 360 }
361 361
362 v8::Local<v8::Map> countMap; 362 v8::Local<v8::Map> countMap;
363 if (!helper.privateMap("V8Console#countMap").ToLocal(&countMap)) 363 if (!helper.privateMap("V8Console#countMap").ToLocal(&countMap))
364 return; 364 return;
365 int64_t count = helper.getIntFromMap(countMap, identifier, 0) + 1; 365 int64_t count = helper.getIntFromMap(countMap, identifier, 0) + 1;
366 helper.setIntOnMap(countMap, identifier, count); 366 helper.setIntOnMap(countMap, identifier, count);
367 helper.addMessage(CountMessageType, DebugMessageLevel, title + ": " + String 16::number(count)); 367 helper.addMessage(ConsoleAPIType::kCount, DebugMessageLevel, title + ": " + String16::number(count));
368 } 368 }
369 369
370 void V8Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 370 void V8Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
371 { 371 {
372 ConsoleHelper helper(info); 372 ConsoleHelper helper(info);
373 if (helper.firstArgToBoolean(false)) 373 if (helper.firstArgToBoolean(false))
374 return; 374 return;
375 helper.addMessage(AssertMessageType, ErrorMessageLevel, String16("console.as sert"), 1); 375 helper.addMessage(ConsoleAPIType::kAssert, ErrorMessageLevel, String16("cons ole.assert"), 1);
376 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent()) 376 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent())
377 debuggerAgent->breakProgramOnException(protocol::Debugger::Paused::Reaso nEnum::Assert, nullptr); 377 debuggerAgent->breakProgramOnException(protocol::Debugger::Paused::Reaso nEnum::Assert, nullptr);
378 } 378 }
379 379
380 void V8Console::markTimelineCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 380 void V8Console::markTimelineCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
381 { 381 {
382 ConsoleHelper(info).addDeprecationMessage("V8Console#markTimelineDeprecated" , "'console.markTimeline' is deprecated. Please use 'console.timeStamp' instead. "); 382 ConsoleHelper(info).addDeprecationMessage("V8Console#markTimelineDeprecated" , "'console.markTimeline' is deprecated. Please use 'console.timeStamp' instead. ");
383 timeStampCallback(info); 383 timeStampCallback(info);
384 } 384 }
385 385
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 String16 protocolTitle = helper.firstArgToString("default"); 420 String16 protocolTitle = helper.firstArgToString("default");
421 if (timelinePrefix) 421 if (timelinePrefix)
422 protocolTitle = "Timeline '" + protocolTitle + "'"; 422 protocolTitle = "Timeline '" + protocolTitle + "'";
423 client->consoleTimeEnd(protocolTitle); 423 client->consoleTimeEnd(protocolTitle);
424 424
425 v8::Local<v8::Map> timeMap; 425 v8::Local<v8::Map> timeMap;
426 if (!helper.privateMap("V8Console#timeMap").ToLocal(&timeMap)) 426 if (!helper.privateMap("V8Console#timeMap").ToLocal(&timeMap))
427 return; 427 return;
428 double elapsed = client->currentTimeMS() - helper.getDoubleFromMap(timeM ap, protocolTitle, 0.0); 428 double elapsed = client->currentTimeMS() - helper.getDoubleFromMap(timeM ap, protocolTitle, 0.0);
429 String16 message = protocolTitle + ": " + String16::fromDoubleFixedPreci sion(elapsed, 3) + "ms"; 429 String16 message = protocolTitle + ": " + String16::fromDoubleFixedPreci sion(elapsed, 3) + "ms";
430 helper.addMessage(TimeEndMessageType, DebugMessageLevel, message); 430 helper.addMessage(ConsoleAPIType::kTimeEnd, DebugMessageLevel, message);
431 } 431 }
432 } 432 }
433 433
434 void V8Console::timelineCallback(const v8::FunctionCallbackInfo<v8::Value>& info ) 434 void V8Console::timelineCallback(const v8::FunctionCallbackInfo<v8::Value>& info )
435 { 435 {
436 ConsoleHelper(info).addDeprecationMessage("V8Console#timeline", "'console.ti meline' is deprecated. Please use 'console.time' instead."); 436 ConsoleHelper(info).addDeprecationMessage("V8Console#timeline", "'console.ti meline' is deprecated. Please use 'console.time' instead.");
437 timeFunction(info, true); 437 timeFunction(info, true);
438 } 438 }
439 439
440 void V8Console::timelineEndCallback(const v8::FunctionCallbackInfo<v8::Value>& i nfo) 440 void V8Console::timelineEndCallback(const v8::FunctionCallbackInfo<v8::Value>& i nfo)
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 continue; 809 continue;
810 if (name->IsString()) { 810 if (name->IsString()) {
811 v8::Local<v8::Value> descriptor; 811 v8::Local<v8::Value> descriptor;
812 bool success = m_global->GetOwnPropertyDescriptor(m_context, v8::Loc al<v8::String>::Cast(name)).ToLocal(&descriptor); 812 bool success = m_global->GetOwnPropertyDescriptor(m_context, v8::Loc al<v8::String>::Cast(name)).ToLocal(&descriptor);
813 DCHECK(success); 813 DCHECK(success);
814 } 814 }
815 } 815 }
816 } 816 }
817 817
818 } // namespace blink 818 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698