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

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

Issue 2778743007: Revert of [inspector] console get all information from inspector when needed (Closed)
Patch Set: 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 v8::Local<v8::Context> v8Context, int contextId, int groupId, 356 double timestamp, ConsoleAPIType type,
357 V8InspectorImpl* inspector, double timestamp, ConsoleAPIType type,
358 const std::vector<v8::Local<v8::Value>>& arguments, 357 const std::vector<v8::Local<v8::Value>>& arguments,
359 std::unique_ptr<V8StackTraceImpl> stackTrace) { 358 std::unique_ptr<V8StackTraceImpl> stackTrace,
360 v8::Isolate* isolate = v8Context->GetIsolate(); 359 InspectedContext* inspectedContext) {
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();
361 365
362 std::unique_ptr<V8ConsoleMessage> message( 366 std::unique_ptr<V8ConsoleMessage> message(
363 new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16())); 367 new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16()));
364 if (stackTrace && !stackTrace->isEmpty()) { 368 if (stackTrace && !stackTrace->isEmpty()) {
365 message->m_url = toString16(stackTrace->topSourceURL()); 369 message->m_url = toString16(stackTrace->topSourceURL());
366 message->m_lineNumber = stackTrace->topLineNumber(); 370 message->m_lineNumber = stackTrace->topLineNumber();
367 message->m_columnNumber = stackTrace->topColumnNumber(); 371 message->m_columnNumber = stackTrace->topColumnNumber();
368 } 372 }
369 message->m_stackTrace = std::move(stackTrace); 373 message->m_stackTrace = std::move(stackTrace);
370 message->m_type = type; 374 message->m_type = type;
371 message->m_contextId = contextId; 375 message->m_contextId = contextId;
372 for (size_t i = 0; i < arguments.size(); ++i) { 376 for (size_t i = 0; i < arguments.size(); ++i) {
373 message->m_arguments.push_back(std::unique_ptr<v8::Global<v8::Value>>( 377 message->m_arguments.push_back(std::unique_ptr<v8::Global<v8::Value>>(
374 new v8::Global<v8::Value>(isolate, arguments.at(i)))); 378 new v8::Global<v8::Value>(isolate, arguments.at(i))));
375 message->m_v8Size += 379 message->m_v8Size +=
376 v8::debug::EstimatedValueSize(isolate, arguments.at(i)); 380 v8::debug::EstimatedValueSize(isolate, arguments.at(i));
377 } 381 }
378 if (arguments.size()) 382 if (arguments.size())
379 message->m_message = 383 message->m_message = V8ValueStringBuilder::toString(arguments[0], context);
380 V8ValueStringBuilder::toString(arguments[0], v8Context);
381 384
382 v8::Isolate::MessageErrorLevel clientLevel = v8::Isolate::kMessageInfo; 385 v8::Isolate::MessageErrorLevel clientLevel = v8::Isolate::kMessageInfo;
383 if (type == ConsoleAPIType::kDebug || type == ConsoleAPIType::kCount || 386 if (type == ConsoleAPIType::kDebug || type == ConsoleAPIType::kCount ||
384 type == ConsoleAPIType::kTimeEnd) { 387 type == ConsoleAPIType::kTimeEnd) {
385 clientLevel = v8::Isolate::kMessageDebug; 388 clientLevel = v8::Isolate::kMessageDebug;
386 } else if (type == ConsoleAPIType::kError || 389 } else if (type == ConsoleAPIType::kError ||
387 type == ConsoleAPIType::kAssert) { 390 type == ConsoleAPIType::kAssert) {
388 clientLevel = v8::Isolate::kMessageError; 391 clientLevel = v8::Isolate::kMessageError;
389 } else if (type == ConsoleAPIType::kWarning) { 392 } else if (type == ConsoleAPIType::kWarning) {
390 clientLevel = v8::Isolate::kMessageWarning; 393 clientLevel = v8::Isolate::kMessageWarning;
391 } else if (type == ConsoleAPIType::kInfo || type == ConsoleAPIType::kLog) { 394 } else if (type == ConsoleAPIType::kInfo || type == ConsoleAPIType::kLog) {
392 clientLevel = v8::Isolate::kMessageInfo; 395 clientLevel = v8::Isolate::kMessageInfo;
393 } 396 }
394 397
395 if (type != ConsoleAPIType::kClear) { 398 if (type != ConsoleAPIType::kClear) {
396 inspector->client()->consoleAPIMessage( 399 inspector->client()->consoleAPIMessage(
397 groupId, clientLevel, toStringView(message->m_message), 400 contextGroupId, clientLevel, toStringView(message->m_message),
398 toStringView(message->m_url), message->m_lineNumber, 401 toStringView(message->m_url), message->m_lineNumber,
399 message->m_columnNumber, message->m_stackTrace.get()); 402 message->m_columnNumber, message->m_stackTrace.get());
400 } 403 }
401 404
402 return message; 405 return message;
403 } 406 }
404 407
405 // static 408 // static
406 std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException( 409 std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException(
407 double timestamp, const String16& detailedMessage, const String16& url, 410 double timestamp, const String16& detailedMessage, const String16& url,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 483 }
481 484
482 m_messages.push_back(std::move(message)); 485 m_messages.push_back(std::move(message));
483 m_estimatedSize += m_messages.back()->estimatedSize(); 486 m_estimatedSize += m_messages.back()->estimatedSize();
484 } 487 }
485 488
486 void V8ConsoleMessageStorage::clear() { 489 void V8ConsoleMessageStorage::clear() {
487 m_messages.clear(); 490 m_messages.clear();
488 m_estimatedSize = 0; 491 m_estimatedSize = 0;
489 if (V8InspectorSessionImpl* session = 492 if (V8InspectorSessionImpl* session =
490 m_inspector->sessionForContextGroup(m_contextGroupId)) { 493 m_inspector->sessionForContextGroup(m_contextGroupId))
491 session->releaseObjectGroup("console"); 494 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;
521 } 495 }
522 496
523 void V8ConsoleMessageStorage::contextDestroyed(int contextId) { 497 void V8ConsoleMessageStorage::contextDestroyed(int contextId) {
524 m_estimatedSize = 0; 498 m_estimatedSize = 0;
525 for (size_t i = 0; i < m_messages.size(); ++i) { 499 for (size_t i = 0; i < m_messages.size(); ++i) {
526 m_messages[i]->contextDestroyed(contextId); 500 m_messages[i]->contextDestroyed(contextId);
527 m_estimatedSize += m_messages[i]->estimatedSize(); 501 m_estimatedSize += m_messages[i]->estimatedSize();
528 } 502 }
529 auto it = m_data.find(contextId);
530 if (it != m_data.end()) m_data.erase(contextId);
531 } 503 }
532 504
533 } // namespace v8_inspector 505 } // 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