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

Side by Side Diff: src/inspector/v8-console-message.cc

Issue 2784713002: [inspector] console get all information from inspector when needed (Closed)
Patch Set: fixed last test Created 3 years, 8 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 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-message.h" 5 #include "src/inspector/v8-console-message.h"
6 6
7 #include "src/debug/debug-interface.h" 7 #include "src/debug/debug-interface.h"
8 #include "src/inspector/inspected-context.h" 8 #include "src/inspector/inspected-context.h"
9 #include "src/inspector/protocol/Protocol.h" 9 #include "src/inspector/protocol/Protocol.h"
10 #include "src/inspector/string-util.h" 10 #include "src/inspector/string-util.h"
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 m_arguments[0]->Get(isolate), "console", 346 m_arguments[0]->Get(isolate), "console",
347 generatePreview); 347 generatePreview);
348 } 348 }
349 349
350 V8MessageOrigin V8ConsoleMessage::origin() const { return m_origin; } 350 V8MessageOrigin V8ConsoleMessage::origin() const { return m_origin; }
351 351
352 ConsoleAPIType V8ConsoleMessage::type() const { return m_type; } 352 ConsoleAPIType V8ConsoleMessage::type() const { return m_type; }
353 353
354 // static 354 // static
355 std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI( 355 std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(
356 double timestamp, ConsoleAPIType type, 356 v8::Local<v8::Context> v8Context, int contextId, int groupId,
357 V8InspectorImpl* inspector, double timestamp, ConsoleAPIType type,
357 const std::vector<v8::Local<v8::Value>>& arguments, 358 const std::vector<v8::Local<v8::Value>>& arguments,
358 std::unique_ptr<V8StackTraceImpl> stackTrace, 359 std::unique_ptr<V8StackTraceImpl> stackTrace) {
359 InspectedContext* inspectedContext) { 360 v8::Isolate* isolate = v8Context->GetIsolate();
360 v8::Isolate* isolate = inspectedContext->isolate();
361 int contextId = inspectedContext->contextId();
362 int contextGroupId = inspectedContext->contextGroupId();
363 V8InspectorImpl* inspector = inspectedContext->inspector();
364 v8::Local<v8::Context> context = inspectedContext->context();
365 361
366 std::unique_ptr<V8ConsoleMessage> message( 362 std::unique_ptr<V8ConsoleMessage> message(
367 new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16())); 363 new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16()));
368 if (stackTrace && !stackTrace->isEmpty()) { 364 if (stackTrace && !stackTrace->isEmpty()) {
369 message->m_url = toString16(stackTrace->topSourceURL()); 365 message->m_url = toString16(stackTrace->topSourceURL());
370 message->m_lineNumber = stackTrace->topLineNumber(); 366 message->m_lineNumber = stackTrace->topLineNumber();
371 message->m_columnNumber = stackTrace->topColumnNumber(); 367 message->m_columnNumber = stackTrace->topColumnNumber();
372 } 368 }
373 message->m_stackTrace = std::move(stackTrace); 369 message->m_stackTrace = std::move(stackTrace);
374 message->m_type = type; 370 message->m_type = type;
375 message->m_contextId = contextId; 371 message->m_contextId = contextId;
376 for (size_t i = 0; i < arguments.size(); ++i) { 372 for (size_t i = 0; i < arguments.size(); ++i) {
377 message->m_arguments.push_back(std::unique_ptr<v8::Global<v8::Value>>( 373 message->m_arguments.push_back(std::unique_ptr<v8::Global<v8::Value>>(
378 new v8::Global<v8::Value>(isolate, arguments.at(i)))); 374 new v8::Global<v8::Value>(isolate, arguments.at(i))));
379 message->m_v8Size += 375 message->m_v8Size +=
380 v8::debug::EstimatedValueSize(isolate, arguments.at(i)); 376 v8::debug::EstimatedValueSize(isolate, arguments.at(i));
381 } 377 }
382 if (arguments.size()) 378 if (arguments.size())
383 message->m_message = V8ValueStringBuilder::toString(arguments[0], context); 379 message->m_message =
380 V8ValueStringBuilder::toString(arguments[0], v8Context);
384 381
385 v8::Isolate::MessageErrorLevel clientLevel = v8::Isolate::kMessageInfo; 382 v8::Isolate::MessageErrorLevel clientLevel = v8::Isolate::kMessageInfo;
386 if (type == ConsoleAPIType::kDebug || type == ConsoleAPIType::kCount || 383 if (type == ConsoleAPIType::kDebug || type == ConsoleAPIType::kCount ||
387 type == ConsoleAPIType::kTimeEnd) { 384 type == ConsoleAPIType::kTimeEnd) {
388 clientLevel = v8::Isolate::kMessageDebug; 385 clientLevel = v8::Isolate::kMessageDebug;
389 } else if (type == ConsoleAPIType::kError || 386 } else if (type == ConsoleAPIType::kError ||
390 type == ConsoleAPIType::kAssert) { 387 type == ConsoleAPIType::kAssert) {
391 clientLevel = v8::Isolate::kMessageError; 388 clientLevel = v8::Isolate::kMessageError;
392 } else if (type == ConsoleAPIType::kWarning) { 389 } else if (type == ConsoleAPIType::kWarning) {
393 clientLevel = v8::Isolate::kMessageWarning; 390 clientLevel = v8::Isolate::kMessageWarning;
394 } else if (type == ConsoleAPIType::kInfo || type == ConsoleAPIType::kLog) { 391 } else if (type == ConsoleAPIType::kInfo || type == ConsoleAPIType::kLog) {
395 clientLevel = v8::Isolate::kMessageInfo; 392 clientLevel = v8::Isolate::kMessageInfo;
396 } 393 }
397 394
398 if (type != ConsoleAPIType::kClear) { 395 if (type != ConsoleAPIType::kClear) {
399 inspector->client()->consoleAPIMessage( 396 inspector->client()->consoleAPIMessage(
400 contextGroupId, clientLevel, toStringView(message->m_message), 397 groupId, clientLevel, toStringView(message->m_message),
401 toStringView(message->m_url), message->m_lineNumber, 398 toStringView(message->m_url), message->m_lineNumber,
402 message->m_columnNumber, message->m_stackTrace.get()); 399 message->m_columnNumber, message->m_stackTrace.get());
403 } 400 }
404 401
405 return message; 402 return message;
406 } 403 }
407 404
408 // static 405 // static
409 std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException( 406 std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException(
410 double timestamp, const String16& detailedMessage, const String16& url, 407 double timestamp, const String16& detailedMessage, const String16& url,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 480 }
484 481
485 m_messages.push_back(std::move(message)); 482 m_messages.push_back(std::move(message));
486 m_estimatedSize += m_messages.back()->estimatedSize(); 483 m_estimatedSize += m_messages.back()->estimatedSize();
487 } 484 }
488 485
489 void V8ConsoleMessageStorage::clear() { 486 void V8ConsoleMessageStorage::clear() {
490 m_messages.clear(); 487 m_messages.clear();
491 m_estimatedSize = 0; 488 m_estimatedSize = 0;
492 if (V8InspectorSessionImpl* session = 489 if (V8InspectorSessionImpl* session =
493 m_inspector->sessionForContextGroup(m_contextGroupId)) 490 m_inspector->sessionForContextGroup(m_contextGroupId)) {
494 session->releaseObjectGroup("console"); 491 session->releaseObjectGroup("console");
492 }
493 m_data.clear();
494 }
495
496 bool V8ConsoleMessageStorage::shouldReportDeprecationMessage(
497 int contextId, const String16& method) {
498 std::set<String16>& reportedDeprecationMessages =
499 m_data[contextId].m_reportedDeprecationMessages;
500 auto it = reportedDeprecationMessages.find(method);
501 if (it != reportedDeprecationMessages.end()) return false;
502 reportedDeprecationMessages.insert(it, method);
503 return true;
504 }
505
506 int V8ConsoleMessageStorage::count(int contextId, const String16& id) {
507 return ++m_data[contextId].m_count[id];
508 }
509
510 void V8ConsoleMessageStorage::time(int contextId, const String16& id) {
511 m_data[contextId].m_time[id] = m_inspector->client()->currentTimeMS();
512 }
513
514 double V8ConsoleMessageStorage::timeEnd(int contextId, const String16& id) {
515 std::map<String16, double>& time = m_data[contextId].m_time;
516 auto it = time.find(id);
517 if (it == time.end()) return 0.0;
518 double elapsed = m_inspector->client()->currentTimeMS() - it->second;
519 time.erase(it);
520 return elapsed;
495 } 521 }
496 522
497 void V8ConsoleMessageStorage::contextDestroyed(int contextId) { 523 void V8ConsoleMessageStorage::contextDestroyed(int contextId) {
498 m_estimatedSize = 0; 524 m_estimatedSize = 0;
499 for (size_t i = 0; i < m_messages.size(); ++i) { 525 for (size_t i = 0; i < m_messages.size(); ++i) {
500 m_messages[i]->contextDestroyed(contextId); 526 m_messages[i]->contextDestroyed(contextId);
501 m_estimatedSize += m_messages[i]->estimatedSize(); 527 m_estimatedSize += m_messages[i]->estimatedSize();
502 } 528 }
529 auto it = m_data.find(contextId);
530 if (it != m_data.end()) m_data.erase(contextId);
503 } 531 }
504 532
505 } // namespace v8_inspector 533 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-console-message.h ('k') | test/inspector/console/memory-setter-in-strict-mode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698