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

Side by Side Diff: src/inspector/V8ConsoleMessage.cpp

Issue 2323173004: [inspector] handle context destroyed after console.log (Closed)
Patch Set: fix formatting Created 4 years, 3 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
« no previous file with comments | « src/inspector/V8ConsoleAgentImpl.cpp ('k') | src/inspector/V8InspectorImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/V8ConsoleMessage.h" 5 #include "src/inspector/V8ConsoleMessage.h"
6 6
7 #include "src/inspector/InspectedContext.h" 7 #include "src/inspector/InspectedContext.h"
8 #include "src/inspector/StringUtil.h" 8 #include "src/inspector/StringUtil.h"
9 #include "src/inspector/V8ConsoleAgentImpl.h" 9 #include "src/inspector/V8ConsoleAgentImpl.h"
10 #include "src/inspector/V8InspectorImpl.h" 10 #include "src/inspector/V8InspectorImpl.h"
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 330
331 V8MessageOrigin V8ConsoleMessage::origin() const { return m_origin; } 331 V8MessageOrigin V8ConsoleMessage::origin() const { return m_origin; }
332 332
333 ConsoleAPIType V8ConsoleMessage::type() const { return m_type; } 333 ConsoleAPIType V8ConsoleMessage::type() const { return m_type; }
334 334
335 // static 335 // static
336 std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI( 336 std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(
337 double timestamp, ConsoleAPIType type, 337 double timestamp, ConsoleAPIType type,
338 const std::vector<v8::Local<v8::Value>>& arguments, 338 const std::vector<v8::Local<v8::Value>>& arguments,
339 std::unique_ptr<V8StackTraceImpl> stackTrace, InspectedContext* context) { 339 std::unique_ptr<V8StackTraceImpl> stackTrace, InspectedContext* context) {
340 v8::Isolate* isolate = context->isolate();
341 int contextId = context->contextId();
342 int contextGroupId = context->contextGroupId();
343 V8InspectorImpl* inspector = context->inspector();
344
340 std::unique_ptr<V8ConsoleMessage> message = wrapUnique( 345 std::unique_ptr<V8ConsoleMessage> message = wrapUnique(
341 new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16())); 346 new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16()));
342 if (stackTrace && !stackTrace->isEmpty()) { 347 if (stackTrace && !stackTrace->isEmpty()) {
343 message->m_url = toString16(stackTrace->topSourceURL()); 348 message->m_url = toString16(stackTrace->topSourceURL());
344 message->m_lineNumber = stackTrace->topLineNumber(); 349 message->m_lineNumber = stackTrace->topLineNumber();
345 message->m_columnNumber = stackTrace->topColumnNumber(); 350 message->m_columnNumber = stackTrace->topColumnNumber();
346 } 351 }
347 message->m_stackTrace = std::move(stackTrace); 352 message->m_stackTrace = std::move(stackTrace);
348 message->m_type = type; 353 message->m_type = type;
349 message->m_contextId = context->contextId(); 354 message->m_contextId = contextId;
350 for (size_t i = 0; i < arguments.size(); ++i) 355 for (size_t i = 0; i < arguments.size(); ++i)
351 message->m_arguments.push_back(wrapUnique( 356 message->m_arguments.push_back(
352 new v8::Global<v8::Value>(context->isolate(), arguments.at(i)))); 357 wrapUnique(new v8::Global<v8::Value>(isolate, arguments.at(i))));
353 if (arguments.size()) 358 if (arguments.size())
354 message->m_message = 359 message->m_message = V8ValueStringBuilder::toString(arguments[0], isolate);
355 V8ValueStringBuilder::toString(arguments[0], context->isolate());
356 360
357 V8ConsoleAPIType clientType = V8ConsoleAPIType::kLog; 361 V8ConsoleAPIType clientType = V8ConsoleAPIType::kLog;
358 if (type == ConsoleAPIType::kDebug || type == ConsoleAPIType::kCount || 362 if (type == ConsoleAPIType::kDebug || type == ConsoleAPIType::kCount ||
359 type == ConsoleAPIType::kTimeEnd) 363 type == ConsoleAPIType::kTimeEnd)
360 clientType = V8ConsoleAPIType::kDebug; 364 clientType = V8ConsoleAPIType::kDebug;
361 else if (type == ConsoleAPIType::kError || type == ConsoleAPIType::kAssert) 365 else if (type == ConsoleAPIType::kError || type == ConsoleAPIType::kAssert)
362 clientType = V8ConsoleAPIType::kError; 366 clientType = V8ConsoleAPIType::kError;
363 else if (type == ConsoleAPIType::kWarning) 367 else if (type == ConsoleAPIType::kWarning)
364 clientType = V8ConsoleAPIType::kWarning; 368 clientType = V8ConsoleAPIType::kWarning;
365 else if (type == ConsoleAPIType::kInfo) 369 else if (type == ConsoleAPIType::kInfo)
366 clientType = V8ConsoleAPIType::kInfo; 370 clientType = V8ConsoleAPIType::kInfo;
367 else if (type == ConsoleAPIType::kClear) 371 else if (type == ConsoleAPIType::kClear)
368 clientType = V8ConsoleAPIType::kClear; 372 clientType = V8ConsoleAPIType::kClear;
369 context->inspector()->client()->consoleAPIMessage( 373 inspector->client()->consoleAPIMessage(
370 context->contextGroupId(), clientType, toStringView(message->m_message), 374 contextGroupId, clientType, toStringView(message->m_message),
371 toStringView(message->m_url), message->m_lineNumber, 375 toStringView(message->m_url), message->m_lineNumber,
372 message->m_columnNumber, message->m_stackTrace.get()); 376 message->m_columnNumber, message->m_stackTrace.get());
373 377
374 return message; 378 return message;
375 } 379 }
376 380
377 // static 381 // static
378 std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException( 382 std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException(
379 double timestamp, const String16& detailedMessage, const String16& url, 383 double timestamp, const String16& detailedMessage, const String16& url,
380 unsigned lineNumber, unsigned columnNumber, 384 unsigned lineNumber, unsigned columnNumber,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 V8ConsoleMessageStorage::V8ConsoleMessageStorage(V8InspectorImpl* inspector, 422 V8ConsoleMessageStorage::V8ConsoleMessageStorage(V8InspectorImpl* inspector,
419 int contextGroupId) 423 int contextGroupId)
420 : m_inspector(inspector), 424 : m_inspector(inspector),
421 m_contextGroupId(contextGroupId), 425 m_contextGroupId(contextGroupId),
422 m_expiredCount(0) {} 426 m_expiredCount(0) {}
423 427
424 V8ConsoleMessageStorage::~V8ConsoleMessageStorage() { clear(); } 428 V8ConsoleMessageStorage::~V8ConsoleMessageStorage() { clear(); }
425 429
426 void V8ConsoleMessageStorage::addMessage( 430 void V8ConsoleMessageStorage::addMessage(
427 std::unique_ptr<V8ConsoleMessage> message) { 431 std::unique_ptr<V8ConsoleMessage> message) {
432 int contextGroupId = m_contextGroupId;
433 V8InspectorImpl* inspector = m_inspector;
428 if (message->type() == ConsoleAPIType::kClear) clear(); 434 if (message->type() == ConsoleAPIType::kClear) clear();
429 435
430 V8InspectorSessionImpl* session = 436 V8InspectorSessionImpl* session =
431 m_inspector->sessionForContextGroup(m_contextGroupId); 437 inspector->sessionForContextGroup(contextGroupId);
432 if (session) { 438 if (session) {
433 if (message->origin() == V8MessageOrigin::kConsole) 439 if (message->origin() == V8MessageOrigin::kConsole)
434 session->consoleAgent()->messageAdded(message.get()); 440 session->consoleAgent()->messageAdded(message.get());
435 session->runtimeAgent()->messageAdded(message.get()); 441 session->runtimeAgent()->messageAdded(message.get());
436 } 442 }
443 if (!inspector->hasConsoleMessageStorage(contextGroupId)) return;
437 444
438 DCHECK(m_messages.size() <= maxConsoleMessageCount); 445 DCHECK(m_messages.size() <= maxConsoleMessageCount);
439 if (m_messages.size() == maxConsoleMessageCount) { 446 if (m_messages.size() == maxConsoleMessageCount) {
440 ++m_expiredCount; 447 ++m_expiredCount;
441 m_messages.pop_front(); 448 m_messages.pop_front();
442 } 449 }
443 m_messages.push_back(std::move(message)); 450 m_messages.push_back(std::move(message));
444 } 451 }
445 452
446 void V8ConsoleMessageStorage::clear() { 453 void V8ConsoleMessageStorage::clear() {
447 m_messages.clear(); 454 m_messages.clear();
448 m_expiredCount = 0; 455 m_expiredCount = 0;
449 if (V8InspectorSessionImpl* session = 456 if (V8InspectorSessionImpl* session =
450 m_inspector->sessionForContextGroup(m_contextGroupId)) 457 m_inspector->sessionForContextGroup(m_contextGroupId))
451 session->releaseObjectGroup("console"); 458 session->releaseObjectGroup("console");
452 } 459 }
453 460
454 void V8ConsoleMessageStorage::contextDestroyed(int contextId) { 461 void V8ConsoleMessageStorage::contextDestroyed(int contextId) {
455 for (size_t i = 0; i < m_messages.size(); ++i) 462 for (size_t i = 0; i < m_messages.size(); ++i)
456 m_messages[i]->contextDestroyed(contextId); 463 m_messages[i]->contextDestroyed(contextId);
457 } 464 }
458 465
459 } // namespace v8_inspector 466 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/V8ConsoleAgentImpl.cpp ('k') | src/inspector/V8InspectorImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698