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

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

Issue 2087953004: Switch v8 inspector to stl collections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actually remove a value from the list Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/V8DebuggerAgentImpl.h" 5 #include "platform/v8_inspector/V8DebuggerAgentImpl.h"
6 6
7 #include "platform/inspector_protocol/String16.h" 7 #include "platform/inspector_protocol/String16.h"
8 #include "platform/inspector_protocol/Values.h" 8 #include "platform/inspector_protocol/Values.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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 191
192 void V8DebuggerAgentImpl::enable() 192 void V8DebuggerAgentImpl::enable()
193 { 193 {
194 // debugger().addListener may result in reporting all parsed scripts to 194 // debugger().addListener may result in reporting all parsed scripts to
195 // the agent so it should already be in enabled state by then. 195 // the agent so it should already be in enabled state by then.
196 m_enabled = true; 196 m_enabled = true;
197 m_state->setBoolean(DebuggerAgentState::debuggerEnabled, true); 197 m_state->setBoolean(DebuggerAgentState::debuggerEnabled, true);
198 debugger().debuggerAgentEnabled(); 198 debugger().debuggerAgentEnabled();
199 199
200 protocol::Vector<V8DebuggerParsedScript> compiledScripts; 200 std::vector<V8DebuggerParsedScript> compiledScripts;
201 debugger().getCompiledScripts(m_session->contextGroupId(), compiledScripts); 201 debugger().getCompiledScripts(m_session->contextGroupId(), compiledScripts);
202 for (size_t i = 0; i < compiledScripts.size(); i++) 202 for (size_t i = 0; i < compiledScripts.size(); i++)
203 didParseSource(compiledScripts[i]); 203 didParseSource(compiledScripts[i]);
204 204
205 // FIXME(WK44513): breakpoints activated flag should be synchronized between all front-ends 205 // FIXME(WK44513): breakpoints activated flag should be synchronized between all front-ends
206 debugger().setBreakpointsActivated(true); 206 debugger().setBreakpointsActivated(true);
207 m_session->changeInstrumentationCounter(+1); 207 m_session->changeInstrumentationCounter(+1);
208 } 208 }
209 209
210 bool V8DebuggerAgentImpl::enabled() 210 bool V8DebuggerAgentImpl::enabled()
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, std::move( newValue)); 368 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, std::move( newValue));
369 } 369 }
370 if (breakpointsCookie->get(breakpointId)) { 370 if (breakpointsCookie->get(breakpointId)) {
371 *errorString = "Breakpoint at specified location already exists."; 371 *errorString = "Breakpoint at specified location already exists.";
372 return; 372 return;
373 } 373 }
374 374
375 breakpointsCookie->setObject(breakpointId, buildObjectForBreakpointCookie(ur l, lineNumber, columnNumber, condition, isRegex)); 375 breakpointsCookie->setObject(breakpointId, buildObjectForBreakpointCookie(ur l, lineNumber, columnNumber, condition, isRegex));
376 376
377 ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition); 377 ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition);
378 for (auto& script : m_scripts) { 378 for (const auto& script : m_scripts) {
379 if (!matches(m_debugger, script.second->sourceURL(), url, isRegex)) 379 if (!matches(m_debugger, script.second.sourceURL(), url, isRegex))
380 continue; 380 continue;
381 std::unique_ptr<protocol::Debugger::Location> location = resolveBreakpoi nt(breakpointId, script.first, breakpoint, UserBreakpointSource); 381 std::unique_ptr<protocol::Debugger::Location> location = resolveBreakpoi nt(breakpointId, script.first, breakpoint, UserBreakpointSource);
382 if (location) 382 if (location)
383 (*locations)->addItem(std::move(location)); 383 (*locations)->addItem(std::move(location));
384 } 384 }
385 385
386 *outBreakpointId = breakpointId; 386 *outBreakpointId = breakpointId;
387 } 387 }
388 388
389 static bool parseLocation(ErrorString* errorString, std::unique_ptr<protocol::De bugger::Location> location, String16* scriptId, int* lineNumber, int* columnNumb er) 389 static bool parseLocation(ErrorString* errorString, std::unique_ptr<protocol::De bugger::Location> location, String16* scriptId, int* lineNumber, int* columnNumb er)
(...skipping 13 matching lines...) Expand all
403 String16 scriptId; 403 String16 scriptId;
404 int lineNumber; 404 int lineNumber;
405 int columnNumber; 405 int columnNumber;
406 406
407 if (!parseLocation(errorString, std::move(location), &scriptId, &lineNumber, &columnNumber)) 407 if (!parseLocation(errorString, std::move(location), &scriptId, &lineNumber, &columnNumber))
408 return; 408 return;
409 409
410 String16 condition = optionalCondition.fromMaybe(""); 410 String16 condition = optionalCondition.fromMaybe("");
411 411
412 String16 breakpointId = generateBreakpointId(scriptId, lineNumber, columnNum ber, UserBreakpointSource); 412 String16 breakpointId = generateBreakpointId(scriptId, lineNumber, columnNum ber, UserBreakpointSource);
413 if (m_breakpointIdToDebuggerBreakpointIds.contains(breakpointId)) { 413 if (m_breakpointIdToDebuggerBreakpointIds.find(breakpointId) != m_breakpoint IdToDebuggerBreakpointIds.end()) {
414 *errorString = "Breakpoint at specified location already exists."; 414 *errorString = "Breakpoint at specified location already exists.";
415 return; 415 return;
416 } 416 }
417 ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition); 417 ScriptBreakpoint breakpoint(lineNumber, columnNumber, condition);
418 *actualLocation = resolveBreakpoint(breakpointId, scriptId, breakpoint, User BreakpointSource); 418 *actualLocation = resolveBreakpoint(breakpointId, scriptId, breakpoint, User BreakpointSource);
419 if (*actualLocation) 419 if (*actualLocation)
420 *outBreakpointId = breakpointId; 420 *outBreakpointId = breakpointId;
421 else 421 else
422 *errorString = "Could not resolve breakpoint"; 422 *errorString = "Could not resolve breakpoint";
423 } 423 }
424 424
425 void V8DebuggerAgentImpl::removeBreakpoint(ErrorString* errorString, const Strin g16& breakpointId) 425 void V8DebuggerAgentImpl::removeBreakpoint(ErrorString* errorString, const Strin g16& breakpointId)
426 { 426 {
427 if (!checkEnabled(errorString)) 427 if (!checkEnabled(errorString))
428 return; 428 return;
429 protocol::DictionaryValue* breakpointsCookie = m_state->getObject(DebuggerAg entState::javaScriptBreakpoints); 429 protocol::DictionaryValue* breakpointsCookie = m_state->getObject(DebuggerAg entState::javaScriptBreakpoints);
430 if (breakpointsCookie) 430 if (breakpointsCookie)
431 breakpointsCookie->remove(breakpointId); 431 breakpointsCookie->remove(breakpointId);
432 removeBreakpoint(breakpointId); 432 removeBreakpoint(breakpointId);
433 } 433 }
434 434
435 void V8DebuggerAgentImpl::removeBreakpoint(const String16& breakpointId) 435 void V8DebuggerAgentImpl::removeBreakpoint(const String16& breakpointId)
436 { 436 {
437 DCHECK(enabled()); 437 DCHECK(enabled());
438 BreakpointIdToDebuggerBreakpointIdsMap::iterator debuggerBreakpointIdsIterat or = m_breakpointIdToDebuggerBreakpointIds.find(breakpointId); 438 BreakpointIdToDebuggerBreakpointIdsMap::iterator debuggerBreakpointIdsIterat or = m_breakpointIdToDebuggerBreakpointIds.find(breakpointId);
439 if (debuggerBreakpointIdsIterator == m_breakpointIdToDebuggerBreakpointIds.e nd()) 439 if (debuggerBreakpointIdsIterator == m_breakpointIdToDebuggerBreakpointIds.e nd())
440 return; 440 return;
441 protocol::Vector<String16>* ids = debuggerBreakpointIdsIterator->second; 441 const std::vector<String16>& ids = debuggerBreakpointIdsIterator->second;
442 for (size_t i = 0; i < ids->size(); ++i) { 442 for (size_t i = 0; i < ids.size(); ++i) {
443 const String16& debuggerBreakpointId = ids->at(i); 443 const String16& debuggerBreakpointId = ids[i];
444 444
445 debugger().removeBreakpoint(debuggerBreakpointId); 445 debugger().removeBreakpoint(debuggerBreakpointId);
446 m_serverBreakpoints.remove(debuggerBreakpointId); 446 m_serverBreakpoints.erase(debuggerBreakpointId);
447 } 447 }
448 m_breakpointIdToDebuggerBreakpointIds.remove(breakpointId); 448 m_breakpointIdToDebuggerBreakpointIds.erase(breakpointId);
449 } 449 }
450 450
451 void V8DebuggerAgentImpl::continueToLocation(ErrorString* errorString, 451 void V8DebuggerAgentImpl::continueToLocation(ErrorString* errorString,
452 std::unique_ptr<protocol::Debugger::Location> location, 452 std::unique_ptr<protocol::Debugger::Location> location,
453 const protocol::Maybe<bool>& interstateLocationOpt) 453 const protocol::Maybe<bool>& interstateLocationOpt)
454 { 454 {
455 if (!checkEnabled(errorString)) 455 if (!checkEnabled(errorString))
456 return; 456 return;
457 if (!m_continueToLocationBreakpointId.isEmpty()) { 457 if (!m_continueToLocationBreakpointId.isEmpty()) {
458 debugger().removeBreakpoint(m_continueToLocationBreakpointId); 458 debugger().removeBreakpoint(m_continueToLocationBreakpointId);
459 m_continueToLocationBreakpointId = ""; 459 m_continueToLocationBreakpointId = "";
460 } 460 }
461 461
462 String16 scriptId; 462 String16 scriptId;
463 int lineNumber; 463 int lineNumber;
464 int columnNumber; 464 int columnNumber;
465 465
466 if (!parseLocation(errorString, std::move(location), &scriptId, &lineNumber, &columnNumber)) 466 if (!parseLocation(errorString, std::move(location), &scriptId, &lineNumber, &columnNumber))
467 return; 467 return;
468 468
469 ScriptBreakpoint breakpoint(lineNumber, columnNumber, ""); 469 ScriptBreakpoint breakpoint(lineNumber, columnNumber, "");
470 m_continueToLocationBreakpointId = debugger().setBreakpoint(scriptId, breakp oint, &lineNumber, &columnNumber, interstateLocationOpt.fromMaybe(false)); 470 m_continueToLocationBreakpointId = debugger().setBreakpoint(scriptId, breakp oint, &lineNumber, &columnNumber, interstateLocationOpt.fromMaybe(false));
471 resume(errorString); 471 resume(errorString);
472 } 472 }
473 473
474 void V8DebuggerAgentImpl::getBacktrace(ErrorString* errorString, std::unique_ptr <Array<CallFrame>>* callFrames, Maybe<StackTrace>* asyncStackTrace) 474 void V8DebuggerAgentImpl::getBacktrace(ErrorString* errorString, std::unique_ptr <Array<CallFrame>>* callFrames, Maybe<StackTrace>* asyncStackTrace)
475 { 475 {
476 if (!assertPaused(errorString)) 476 if (!assertPaused(errorString))
477 return; 477 return;
478 m_pausedCallFrames.swap(debugger().currentCallFrames()); 478 JavaScriptCallFrames frames = debugger().currentCallFrames();
479 m_pausedCallFrames.swap(frames);
dgozman 2016/06/24 17:01:13 I'm interested why previous code doesn't work anym
eostroukhov-old 2016/06/24 22:24:25 Compile error: error: non-const lvalue reference t
479 *callFrames = currentCallFrames(errorString); 480 *callFrames = currentCallFrames(errorString);
480 if (!*callFrames) 481 if (!*callFrames)
481 return; 482 return;
482 *asyncStackTrace = currentAsyncStackTrace(); 483 *asyncStackTrace = currentAsyncStackTrace();
483 } 484 }
484 485
485 bool V8DebuggerAgentImpl::isCurrentCallStackEmptyOrBlackboxed() 486 bool V8DebuggerAgentImpl::isCurrentCallStackEmptyOrBlackboxed()
486 { 487 {
487 DCHECK(enabled()); 488 DCHECK(enabled());
488 JavaScriptCallFrames callFrames = debugger().currentCallFrames(); 489 JavaScriptCallFrames callFrames = debugger().currentCallFrames();
489 for (size_t index = 0; index < callFrames.size(); ++index) { 490 for (size_t index = 0; index < callFrames.size(); ++index) {
490 if (!isCallFrameWithUnknownScriptOrBlackboxed(callFrames[index])) 491 if (!isCallFrameWithUnknownScriptOrBlackboxed(callFrames[index].get()))
491 return false; 492 return false;
492 } 493 }
493 return true; 494 return true;
494 } 495 }
495 496
496 bool V8DebuggerAgentImpl::isTopPausedCallFrameBlackboxed() 497 bool V8DebuggerAgentImpl::isTopPausedCallFrameBlackboxed()
497 { 498 {
498 DCHECK(enabled()); 499 DCHECK(enabled());
499 return isCallFrameWithUnknownScriptOrBlackboxed(m_pausedCallFrames.size() ? m_pausedCallFrames[0] : nullptr); 500 JavaScriptCallFrame* frame = m_pausedCallFrames.size() ? m_pausedCallFrames[ 0].get() : nullptr;
501 return isCallFrameWithUnknownScriptOrBlackboxed(frame);
500 } 502 }
501 503
502 bool V8DebuggerAgentImpl::isCallFrameWithUnknownScriptOrBlackboxed(JavaScriptCal lFrame* frame) 504 bool V8DebuggerAgentImpl::isCallFrameWithUnknownScriptOrBlackboxed(JavaScriptCal lFrame* frame)
503 { 505 {
504 if (!frame) 506 if (!frame)
505 return true; 507 return true;
506 ScriptsMap::iterator it = m_scripts.find(String16::number(frame->sourceID()) ); 508 ScriptsMap::iterator it = m_scripts.find(String16::number(frame->sourceID()) );
507 if (it == m_scripts.end()) { 509 if (it == m_scripts.end()) {
508 // Unknown scripts are blackboxed. 510 // Unknown scripts are blackboxed.
509 return true; 511 return true;
510 } 512 }
511 if (m_blackboxPattern) { 513 if (m_blackboxPattern) {
512 String16 scriptSourceURL = it->second->sourceURL(); 514 const String16& scriptSourceURL = it->second.sourceURL();
513 if (!scriptSourceURL.isEmpty() && m_blackboxPattern->match(scriptSourceU RL) != -1) 515 if (!scriptSourceURL.isEmpty() && m_blackboxPattern->match(scriptSourceU RL) != -1)
514 return true; 516 return true;
515 } 517 }
516 auto itBlackboxedPositions = m_blackboxedPositions.find(String16::number(fra me->sourceID())); 518 auto itBlackboxedPositions = m_blackboxedPositions.find(String16::number(fra me->sourceID()));
517 if (itBlackboxedPositions == m_blackboxedPositions.end()) 519 if (itBlackboxedPositions == m_blackboxedPositions.end())
518 return false; 520 return false;
519 521
520 protocol::Vector<std::pair<int, int>>* ranges = itBlackboxedPositions->secon d; 522 const std::vector<std::pair<int, int>>& ranges = itBlackboxedPositions->seco nd;
521 auto itRange = std::lower_bound(ranges->begin(), ranges->end(), std::make_pa ir(frame->line(), frame->column()), positionComparator); 523 auto itRange = std::lower_bound(ranges.cbegin(), ranges.cend(),
524 std::make_pair(frame->line(), frame->column()), positionComparator);
522 // Ranges array contains positions in script where blackbox state is changed . 525 // Ranges array contains positions in script where blackbox state is changed .
523 // [(0,0) ... ranges[0]) isn't blackboxed, [ranges[0] ... ranges[1]) is blac kboxed... 526 // [(0,0) ... ranges[0]) isn't blackboxed, [ranges[0] ... ranges[1]) is blac kboxed...
524 return std::distance(ranges->begin(), itRange) % 2; 527 return std::distance(ranges.begin(), itRange) % 2;
525 } 528 }
526 529
527 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::shouldSkipExceptionPa use(JavaScriptCallFrame* topCallFrame) 530 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::shouldSkipExceptionPa use(JavaScriptCallFrame* topCallFrame)
528 { 531 {
529 if (m_steppingFromFramework) 532 if (m_steppingFromFramework)
530 return RequestNoSkip; 533 return RequestNoSkip;
531 if (isCallFrameWithUnknownScriptOrBlackboxed(topCallFrame)) 534 if (isCallFrameWithUnknownScriptOrBlackboxed(topCallFrame))
532 return RequestContinue; 535 return RequestContinue;
533 return RequestNoSkip; 536 return RequestNoSkip;
534 } 537 }
(...skipping 24 matching lines...) Expand all
559 562
560 std::unique_ptr<protocol::Debugger::Location> V8DebuggerAgentImpl::resolveBreakp oint(const String16& breakpointId, const String16& scriptId, const ScriptBreakpo int& breakpoint, BreakpointSource source) 563 std::unique_ptr<protocol::Debugger::Location> V8DebuggerAgentImpl::resolveBreakp oint(const String16& breakpointId, const String16& scriptId, const ScriptBreakpo int& breakpoint, BreakpointSource source)
561 { 564 {
562 DCHECK(enabled()); 565 DCHECK(enabled());
563 // FIXME: remove these checks once crbug.com/520702 is resolved. 566 // FIXME: remove these checks once crbug.com/520702 is resolved.
564 CHECK(!breakpointId.isEmpty()); 567 CHECK(!breakpointId.isEmpty());
565 CHECK(!scriptId.isEmpty()); 568 CHECK(!scriptId.isEmpty());
566 ScriptsMap::iterator scriptIterator = m_scripts.find(scriptId); 569 ScriptsMap::iterator scriptIterator = m_scripts.find(scriptId);
567 if (scriptIterator == m_scripts.end()) 570 if (scriptIterator == m_scripts.end())
568 return nullptr; 571 return nullptr;
569 V8DebuggerScript* script = scriptIterator->second; 572 const V8DebuggerScript& script = scriptIterator->second;
570 if (breakpoint.lineNumber < script->startLine() || script->endLine() < break point.lineNumber) 573 if (breakpoint.lineNumber < script.startLine() || script.endLine() < breakpo int.lineNumber)
571 return nullptr; 574 return nullptr;
572 575
573 int actualLineNumber; 576 int actualLineNumber;
574 int actualColumnNumber; 577 int actualColumnNumber;
575 String16 debuggerBreakpointId = debugger().setBreakpoint(scriptId, breakpoin t, &actualLineNumber, &actualColumnNumber, false); 578 String16 debuggerBreakpointId = debugger().setBreakpoint(scriptId, breakpoin t, &actualLineNumber, &actualColumnNumber, false);
576 if (debuggerBreakpointId.isEmpty()) 579 if (debuggerBreakpointId.isEmpty())
577 return nullptr; 580 return nullptr;
578 581
579 m_serverBreakpoints.set(debuggerBreakpointId, std::make_pair(breakpointId, s ource)); 582 m_serverBreakpoints[debuggerBreakpointId] = std::make_pair(breakpointId, sou rce);
580 CHECK(!breakpointId.isEmpty()); 583 CHECK(!breakpointId.isEmpty());
581 if (!m_breakpointIdToDebuggerBreakpointIds.contains(breakpointId))
582 m_breakpointIdToDebuggerBreakpointIds.set(breakpointId, protocol::Vector <String16>());
583 584
584 BreakpointIdToDebuggerBreakpointIdsMap::iterator debuggerBreakpointIdsIterat or = m_breakpointIdToDebuggerBreakpointIds.find(breakpointId); 585 m_breakpointIdToDebuggerBreakpointIds[breakpointId].push_back(debuggerBreakp ointId);
585 debuggerBreakpointIdsIterator->second->append(debuggerBreakpointId);
586
587 return buildProtocolLocation(scriptId, actualLineNumber, actualColumnNumber) ; 586 return buildProtocolLocation(scriptId, actualLineNumber, actualColumnNumber) ;
588 } 587 }
589 588
590 void V8DebuggerAgentImpl::searchInContent(ErrorString* error, const String16& sc riptId, const String16& query, 589 void V8DebuggerAgentImpl::searchInContent(ErrorString* error, const String16& sc riptId, const String16& query,
591 const Maybe<bool>& optionalCaseSensitive, 590 const Maybe<bool>& optionalCaseSensitive,
592 const Maybe<bool>& optionalIsRegex, 591 const Maybe<bool>& optionalIsRegex,
593 std::unique_ptr<Array<protocol::Debugger::SearchMatch>>* results) 592 std::unique_ptr<Array<protocol::Debugger::SearchMatch>>* results)
594 { 593 {
595 ScriptsMap::iterator it = m_scripts.find(scriptId); 594 ScriptsMap::iterator it = m_scripts.find(scriptId);
596 if (it != m_scripts.end()) 595 if (it != m_scripts.end())
597 *results = V8ContentSearchUtil::searchInTextByLines(m_session, it->secon d->source(), query, optionalCaseSensitive.fromMaybe(false), optionalIsRegex.from Maybe(false)); 596 *results = V8ContentSearchUtil::searchInTextByLines(m_session, it->secon d.source(), query, optionalCaseSensitive.fromMaybe(false), optionalIsRegex.fromM aybe(false));
598 else 597 else
599 *error = String16("No script for id: " + scriptId); 598 *error = String16("No script for id: " + scriptId);
600 } 599 }
601 600
602 void V8DebuggerAgentImpl::setScriptSource(ErrorString* errorString, 601 void V8DebuggerAgentImpl::setScriptSource(ErrorString* errorString,
603 const String16& scriptId, 602 const String16& scriptId,
604 const String16& newContent, 603 const String16& newContent,
605 const Maybe<bool>& preview, 604 const Maybe<bool>& preview,
606 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* newCallFrames, 605 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* newCallFrames,
607 Maybe<bool>* stackChanged, 606 Maybe<bool>* stackChanged,
608 Maybe<StackTrace>* asyncStackTrace, 607 Maybe<StackTrace>* asyncStackTrace,
609 Maybe<protocol::Debugger::SetScriptSourceError>* optOutCompileError) 608 Maybe<protocol::Debugger::SetScriptSourceError>* optOutCompileError)
610 { 609 {
611 if (!checkEnabled(errorString)) 610 if (!checkEnabled(errorString))
612 return; 611 return;
613 if (!debugger().setScriptSource(scriptId, newContent, preview.fromMaybe(fals e), errorString, optOutCompileError, &m_pausedCallFrames, stackChanged)) 612 if (!debugger().setScriptSource(scriptId, newContent, preview.fromMaybe(fals e), errorString, optOutCompileError, &m_pausedCallFrames, stackChanged))
614 return; 613 return;
615 614
616 std::unique_ptr<Array<CallFrame>> callFrames = currentCallFrames(errorString ); 615 std::unique_ptr<Array<CallFrame>> callFrames = currentCallFrames(errorString );
617 if (!callFrames) 616 if (!callFrames)
618 return; 617 return;
619 *newCallFrames = std::move(callFrames); 618 *newCallFrames = std::move(callFrames);
620 *asyncStackTrace = currentAsyncStackTrace(); 619 *asyncStackTrace = currentAsyncStackTrace();
621 620
622 ScriptsMap::iterator it = m_scripts.find(scriptId); 621 ScriptsMap::iterator it = m_scripts.find(scriptId);
623 if (it == m_scripts.end()) 622 if (it == m_scripts.end())
624 return; 623 return;
625 it->second->setSource(newContent); 624 it->second.setSource(newContent);
626 } 625 }
627 626
628 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString, 627 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString,
629 const String16& callFrameId, 628 const String16& callFrameId,
630 std::unique_ptr<Array<CallFrame>>* newCallFrames, 629 std::unique_ptr<Array<CallFrame>>* newCallFrames,
631 Maybe<StackTrace>* asyncStackTrace) 630 Maybe<StackTrace>* asyncStackTrace)
632 { 631 {
633 if (!assertPaused(errorString)) 632 if (!assertPaused(errorString))
634 return; 633 return;
635 InjectedScript::CallFrameScope scope(errorString, m_debugger, m_session->con textGroupId(), callFrameId); 634 InjectedScript::CallFrameScope scope(errorString, m_debugger, m_session->con textGroupId(), callFrameId);
636 if (!scope.initialize()) 635 if (!scope.initialize())
637 return; 636 return;
638 if (scope.frameOrdinal() >= m_pausedCallFrames.size()) { 637 if (scope.frameOrdinal() >= m_pausedCallFrames.size()) {
639 *errorString = "Could not find call frame with given id"; 638 *errorString = "Could not find call frame with given id";
640 return; 639 return;
641 } 640 }
642 641
643 v8::Local<v8::Value> resultValue; 642 v8::Local<v8::Value> resultValue;
644 v8::Local<v8::Boolean> result; 643 v8::Local<v8::Boolean> result;
645 if (!m_pausedCallFrames[scope.frameOrdinal()]->restart().ToLocal(&resultValu e) || scope.tryCatch().HasCaught() || !resultValue->ToBoolean(scope.context()).T oLocal(&result) || !result->Value()) { 644 if (!m_pausedCallFrames[scope.frameOrdinal()]->restart().ToLocal(&resultValu e) || scope.tryCatch().HasCaught() || !resultValue->ToBoolean(scope.context()).T oLocal(&result) || !result->Value()) {
646 *errorString = "Internal error"; 645 *errorString = "Internal error";
647 return; 646 return;
648 } 647 }
649 m_pausedCallFrames.swap(debugger().currentCallFrames()); 648 JavaScriptCallFrames frames = debugger().currentCallFrames();
649 m_pausedCallFrames.swap(frames);
650 650
651 *newCallFrames = currentCallFrames(errorString); 651 *newCallFrames = currentCallFrames(errorString);
652 if (!*newCallFrames) 652 if (!*newCallFrames)
653 return; 653 return;
654 *asyncStackTrace = currentAsyncStackTrace(); 654 *asyncStackTrace = currentAsyncStackTrace();
655 } 655 }
656 656
657 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource) 657 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource)
658 { 658 {
659 if (!checkEnabled(error)) 659 if (!checkEnabled(error))
660 return; 660 return;
661 ScriptsMap::iterator it = m_scripts.find(scriptId); 661 ScriptsMap::iterator it = m_scripts.find(scriptId);
662 if (it == m_scripts.end()) { 662 if (it == m_scripts.end()) {
663 *error = "No script for id: " + scriptId; 663 *error = "No script for id: " + scriptId;
664 return; 664 return;
665 } 665 }
666 *scriptSource = it->second->source(); 666 *scriptSource = it->second.source();
667 } 667 }
668 668
669 void V8DebuggerAgentImpl::getFunctionDetails(ErrorString* errorString, const Str ing16& functionId, std::unique_ptr<FunctionDetails>* details) 669 void V8DebuggerAgentImpl::getFunctionDetails(ErrorString* errorString, const Str ing16& functionId, std::unique_ptr<FunctionDetails>* details)
670 { 670 {
671 if (!checkEnabled(errorString)) 671 if (!checkEnabled(errorString))
672 return; 672 return;
673 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex tGroupId(), functionId); 673 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex tGroupId(), functionId);
674 if (!scope.initialize()) 674 if (!scope.initialize())
675 return; 675 return;
676 if (!scope.object()->IsFunction()) { 676 if (!scope.object()->IsFunction()) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 m_steppingFromFramework = false; 839 m_steppingFromFramework = false;
840 m_session->releaseObjectGroup(V8InspectorSession::backtraceObjectGroup); 840 m_session->releaseObjectGroup(V8InspectorSession::backtraceObjectGroup);
841 debugger().continueProgram(); 841 debugger().continueProgram();
842 } 842 }
843 843
844 void V8DebuggerAgentImpl::stepOver(ErrorString* errorString) 844 void V8DebuggerAgentImpl::stepOver(ErrorString* errorString)
845 { 845 {
846 if (!assertPaused(errorString)) 846 if (!assertPaused(errorString))
847 return; 847 return;
848 // StepOver at function return point should fallback to StepInto. 848 // StepOver at function return point should fallback to StepInto.
849 JavaScriptCallFrame* frame = m_pausedCallFrames.size() ? m_pausedCallFrames[ 0] : nullptr; 849 JavaScriptCallFrame* frame = !m_pausedCallFrames.empty() ? m_pausedCallFrame s.front().get() : nullptr;
dgozman 2016/06/24 17:01:13 nit: I like [0] more than front()
eostroukhov-old 2016/06/24 22:24:25 Done.
850 if (frame && frame->isAtReturn()) { 850 if (frame && frame->isAtReturn()) {
851 stepInto(errorString); 851 stepInto(errorString);
852 return; 852 return;
853 } 853 }
854 m_scheduledDebuggerStep = StepOver; 854 m_scheduledDebuggerStep = StepOver;
855 m_steppingFromFramework = isTopPausedCallFrameBlackboxed(); 855 m_steppingFromFramework = isTopPausedCallFrameBlackboxed();
856 m_session->releaseObjectGroup(V8InspectorSession::backtraceObjectGroup); 856 m_session->releaseObjectGroup(V8InspectorSession::backtraceObjectGroup);
857 debugger().stepOverStatement(); 857 debugger().stepOverStatement();
858 } 858 }
859 859
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 internalSetAsyncCallStackDepth(depth); 986 internalSetAsyncCallStackDepth(depth);
987 } 987 }
988 988
989 void V8DebuggerAgentImpl::asyncTaskScheduled(const String16& taskName, void* tas k, bool recurring) 989 void V8DebuggerAgentImpl::asyncTaskScheduled(const String16& taskName, void* tas k, bool recurring)
990 { 990 {
991 if (!m_maxAsyncCallStackDepth) 991 if (!m_maxAsyncCallStackDepth)
992 return; 992 return;
993 v8::HandleScope scope(m_isolate); 993 v8::HandleScope scope(m_isolate);
994 std::unique_ptr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, V8 StackTrace::maxCallStackSizeToCapture, taskName); 994 std::unique_ptr<V8StackTraceImpl> chain = V8StackTraceImpl::capture(this, V8 StackTrace::maxCallStackSizeToCapture, taskName);
995 if (chain) { 995 if (chain) {
996 m_asyncTaskStacks.set(task, std::move(chain)); 996 m_asyncTaskStacks[task] = std::move(chain);
997 if (recurring) 997 if (recurring)
998 m_recurringTasks.add(task); 998 m_recurringTasks.insert(task);
999 } 999 }
1000 } 1000 }
1001 1001
1002 void V8DebuggerAgentImpl::asyncTaskCanceled(void* task) 1002 void V8DebuggerAgentImpl::asyncTaskCanceled(void* task)
1003 { 1003 {
1004 if (!m_maxAsyncCallStackDepth) 1004 if (!m_maxAsyncCallStackDepth)
1005 return; 1005 return;
1006 m_asyncTaskStacks.remove(task); 1006 m_asyncTaskStacks.erase(task);
1007 m_recurringTasks.remove(task); 1007 m_recurringTasks.erase(task);
1008 } 1008 }
1009 1009
1010 void V8DebuggerAgentImpl::asyncTaskStarted(void* task) 1010 void V8DebuggerAgentImpl::asyncTaskStarted(void* task)
1011 { 1011 {
1012 // Not enabled, return. 1012 // Not enabled, return.
1013 if (!m_maxAsyncCallStackDepth) 1013 if (!m_maxAsyncCallStackDepth)
1014 return; 1014 return;
1015 1015
1016 m_currentTasks.append(task); 1016 m_currentTasks.push_back(task);
1017 V8StackTraceImpl* stack = m_asyncTaskStacks.get(task); 1017 auto stack_iter = m_asyncTaskStacks.find(task);
alph 2016/06/24 17:37:27 stackIt
eostroukhov-old 2016/06/24 22:24:25 Done.
1018 // Needs to support following order of events: 1018 // Needs to support following order of events:
1019 // - asyncTaskScheduled 1019 // - asyncTaskScheduled
1020 // <-- attached here --> 1020 // <-- attached here -->
1021 // - asyncTaskStarted 1021 // - asyncTaskStarted
1022 // - asyncTaskCanceled <-- canceled before finished 1022 // - asyncTaskCanceled <-- canceled before finished
1023 // <-- async stack requested here --> 1023 // <-- async stack requested here -->
1024 // - asyncTaskFinished 1024 // - asyncTaskFinished
1025 m_currentStacks.append(stack ? stack->cloneImpl() : nullptr); 1025 std::unique_ptr<V8StackTraceImpl> stackTrace;
1026 if (stack_iter != m_asyncTaskStacks.end() && stack_iter->second) {
dgozman 2016/06/24 17:01:13 I think stack_iter->second cannot be nullptr.
eostroukhov-old 2016/06/24 22:24:25 Done.
1027 stackTrace = stack_iter->second->cloneImpl();
1028 }
1029 m_currentStacks.push_back(std::move(stackTrace));
1026 } 1030 }
1027 1031
1028 void V8DebuggerAgentImpl::asyncTaskFinished(void* task) 1032 void V8DebuggerAgentImpl::asyncTaskFinished(void* task)
1029 { 1033 {
1030 if (!m_maxAsyncCallStackDepth) 1034 if (!m_maxAsyncCallStackDepth)
1031 return; 1035 return;
1032 // We could start instrumenting half way and the stack is empty. 1036 // We could start instrumenting half way and the stack is empty.
1033 if (!m_currentStacks.size()) 1037 if (!m_currentStacks.size())
1034 return; 1038 return;
1035 1039
1036 DCHECK(m_currentTasks.last() == task); 1040 DCHECK(m_currentTasks.back() == task);
1037 m_currentTasks.removeLast(); 1041 m_currentTasks.pop_back();
1038 1042 m_currentStacks.pop_back();
1039 m_currentStacks.removeLast(); 1043 m_recurringTasks.erase(task);
1040 if (!m_recurringTasks.contains(task))
dgozman 2016/06/24 17:01:13 This code is messed up.
eostroukhov-old 2016/06/24 22:24:25 Done.
1041 m_asyncTaskStacks.remove(task);
1042 } 1044 }
1043 1045
1044 void V8DebuggerAgentImpl::allAsyncTasksCanceled() 1046 void V8DebuggerAgentImpl::allAsyncTasksCanceled()
1045 { 1047 {
1046 m_asyncTaskStacks.clear(); 1048 m_asyncTaskStacks.clear();
1047 m_recurringTasks.clear(); 1049 m_recurringTasks.clear();
1048 m_currentStacks.clear(); 1050 m_currentStacks.clear();
1049 m_currentTasks.clear(); 1051 m_currentTasks.clear();
1050 } 1052 }
1051 1053
(...skipping 20 matching lines...) Expand all
1072 { 1074 {
1073 std::unique_ptr<V8Regex> regex(new V8Regex(m_debugger, pattern, true /** cas eSensitive */, false /** multiline */)); 1075 std::unique_ptr<V8Regex> regex(new V8Regex(m_debugger, pattern, true /** cas eSensitive */, false /** multiline */));
1074 if (!regex->isValid()) { 1076 if (!regex->isValid()) {
1075 *errorString = "Pattern parser error: " + regex->errorMessage(); 1077 *errorString = "Pattern parser error: " + regex->errorMessage();
1076 return false; 1078 return false;
1077 } 1079 }
1078 m_blackboxPattern = std::move(regex); 1080 m_blackboxPattern = std::move(regex);
1079 return true; 1081 return true;
1080 } 1082 }
1081 1083
1082 void V8DebuggerAgentImpl::setBlackboxedRanges(ErrorString* error, const String16 & scriptId, std::unique_ptr<protocol::Array<protocol::Debugger::ScriptPosition>> inPositions) 1084 void V8DebuggerAgentImpl::setBlackboxedRanges(ErrorString* error, const String16 & scriptId,
1085 std::unique_ptr<protocol::Array<protocol::Debugger::ScriptPosition>> inPosit ions)
1083 { 1086 {
1084 if (!m_scripts.contains(scriptId)) { 1087 if (m_scripts.find(scriptId) == m_scripts.end()) {
1085 *error = "No script with passed id."; 1088 *error = "No script with passed id.";
1086 return; 1089 return;
1087 } 1090 }
1088 1091
1089 if (!inPositions->length()) { 1092 if (!inPositions->length()) {
1090 m_blackboxedPositions.remove(scriptId); 1093 m_blackboxedPositions.erase(scriptId);
1091 return; 1094 return;
1092 } 1095 }
1093 1096
1094 protocol::Vector<std::pair<int, int>> positions(inPositions->length()); 1097 std::vector<std::pair<int, int>> positions;
1095 for (size_t i = 0; i < positions.size(); ++i) { 1098 positions.reserve(inPositions->length());
1099 for (size_t i = 0; i < inPositions->length(); ++i) {
1096 protocol::Debugger::ScriptPosition* position = inPositions->get(i); 1100 protocol::Debugger::ScriptPosition* position = inPositions->get(i);
1097 if (position->getLine() < 0) { 1101 if (position->getLine() < 0) {
1098 *error = "Position missing 'line' or 'line' < 0."; 1102 *error = "Position missing 'line' or 'line' < 0.";
1099 return; 1103 return;
1100 } 1104 }
1101 if (position->getColumn() < 0) { 1105 if (position->getColumn() < 0) {
1102 *error = "Position missing 'column' or 'column' < 0."; 1106 *error = "Position missing 'column' or 'column' < 0.";
1103 return; 1107 return;
1104 } 1108 }
1105 positions[i] = std::make_pair(position->getLine(), position->getColumn() ); 1109 positions.push_back(std::make_pair(position->getLine(), position->getCol umn()));
1106 } 1110 }
1107 1111
1108 for (size_t i = 1; i < positions.size(); ++i) { 1112 for (size_t i = 1; i < positions.size(); ++i) {
1109 if (positions[i - 1].first < positions[i].first) 1113 if (positions[i - 1].first < positions[i].first)
1110 continue; 1114 continue;
1111 if (positions[i - 1].first == positions[i].first && positions[i - 1].sec ond < positions[i].second) 1115 if (positions[i - 1].first == positions[i].first && positions[i - 1].sec ond < positions[i].second)
1112 continue; 1116 continue;
1113 *error = "Input positions array is not sorted or contains duplicate valu es."; 1117 *error = "Input positions array is not sorted or contains duplicate valu es.";
1114 return; 1118 return;
1115 } 1119 }
1116 1120
1117 m_blackboxedPositions.set(scriptId, positions); 1121 m_blackboxedPositions[scriptId] = positions;
1118 } 1122 }
1119 1123
1120 void V8DebuggerAgentImpl::willExecuteScript(int scriptId) 1124 void V8DebuggerAgentImpl::willExecuteScript(int scriptId)
1121 { 1125 {
1122 changeJavaScriptRecursionLevel(+1); 1126 changeJavaScriptRecursionLevel(+1);
1123 // Fast return. 1127 // Fast return.
1124 if (m_scheduledDebuggerStep != StepInto) 1128 if (m_scheduledDebuggerStep != StepInto)
1125 return; 1129 return;
1126 // Skip unknown scripts (e.g. InjectedScript). 1130 // Skip unknown scripts (e.g. InjectedScript).
1127 if (!m_scripts.contains(String16::number(scriptId))) 1131 if (m_scripts.find(String16::number(scriptId)) == m_scripts.end())
1128 return; 1132 return;
1129 schedulePauseOnNextStatementIfSteppingInto(); 1133 schedulePauseOnNextStatementIfSteppingInto();
1130 } 1134 }
1131 1135
1132 void V8DebuggerAgentImpl::didExecuteScript() 1136 void V8DebuggerAgentImpl::didExecuteScript()
1133 { 1137 {
1134 changeJavaScriptRecursionLevel(-1); 1138 changeJavaScriptRecursionLevel(-1);
1135 } 1139 }
1136 1140
1137 void V8DebuggerAgentImpl::changeJavaScriptRecursionLevel(int step) 1141 void V8DebuggerAgentImpl::changeJavaScriptRecursionLevel(int step)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 // Context has been reported as removed while on pause. 1181 // Context has been reported as removed while on pause.
1178 return Array<CallFrame>::create(); 1182 return Array<CallFrame>::create();
1179 } 1183 }
1180 1184
1181 v8::HandleScope handles(m_isolate); 1185 v8::HandleScope handles(m_isolate);
1182 v8::Local<v8::Context> context = topFrameInjectedScript->context()->context( ); 1186 v8::Local<v8::Context> context = topFrameInjectedScript->context()->context( );
1183 v8::Context::Scope contextScope(context); 1187 v8::Context::Scope contextScope(context);
1184 1188
1185 v8::Local<v8::Array> objects = v8::Array::New(m_isolate); 1189 v8::Local<v8::Array> objects = v8::Array::New(m_isolate);
1186 for (size_t frameOrdinal = 0; frameOrdinal < m_pausedCallFrames.size(); ++fr ameOrdinal) { 1190 for (size_t frameOrdinal = 0; frameOrdinal < m_pausedCallFrames.size(); ++fr ameOrdinal) {
1187 JavaScriptCallFrame* currentCallFrame = m_pausedCallFrames[frameOrdinal] ; 1191 const std::unique_ptr<JavaScriptCallFrame>& currentCallFrame = m_pausedC allFrames[frameOrdinal];
1188 1192
1189 v8::Local<v8::Object> details = currentCallFrame->details(); 1193 v8::Local<v8::Object> details = currentCallFrame->details();
1190 if (hasInternalError(errorString, details.IsEmpty())) 1194 if (hasInternalError(errorString, details.IsEmpty()))
1191 return Array<CallFrame>::create(); 1195 return Array<CallFrame>::create();
1192 1196
1193 int contextId = currentCallFrame->contextId(); 1197 int contextId = currentCallFrame->contextId();
1194 InjectedScript* injectedScript = contextId ? m_session->findInjectedScri pt(&ignored, contextId) : nullptr; 1198 InjectedScript* injectedScript = contextId ? m_session->findInjectedScri pt(&ignored, contextId) : nullptr;
1195 if (!injectedScript) 1199 if (!injectedScript)
1196 injectedScript = topFrameInjectedScript; 1200 injectedScript = topFrameInjectedScript;
1197 1201
(...skipping 22 matching lines...) Expand all
1220 1224
1221 protocol::ErrorSupport errorSupport; 1225 protocol::ErrorSupport errorSupport;
1222 std::unique_ptr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(toPro tocolValue(context, objects).get(), &errorSupport); 1226 std::unique_ptr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(toPro tocolValue(context, objects).get(), &errorSupport);
1223 if (hasInternalError(errorString, !callFrames)) 1227 if (hasInternalError(errorString, !callFrames))
1224 return Array<CallFrame>::create(); 1228 return Array<CallFrame>::create();
1225 return callFrames; 1229 return callFrames;
1226 } 1230 }
1227 1231
1228 std::unique_ptr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace() 1232 std::unique_ptr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace()
1229 { 1233 {
1230 if (m_pausedContext.IsEmpty() || !m_maxAsyncCallStackDepth || !m_currentStac ks.size() || !m_currentStacks.last()) 1234 if (m_pausedContext.IsEmpty() || !m_maxAsyncCallStackDepth || m_currentStack s.empty())
1231 return nullptr; 1235 return nullptr;
1232 1236
1233 return m_currentStacks.last()->buildInspectorObjectForTail(this); 1237 const std::unique_ptr<V8StackTraceImpl>& stackTrace = m_currentStacks.back() ;
1238 return stackTrace ? stackTrace->buildInspectorObjectForTail(this) : nullptr;
1234 } 1239 }
1235 1240
1236 V8StackTraceImpl* V8DebuggerAgentImpl::currentAsyncCallChain() 1241 V8StackTraceImpl* V8DebuggerAgentImpl::currentAsyncCallChain()
1237 { 1242 {
1238 if (!m_currentStacks.size()) 1243 return m_currentStacks.empty() ? nullptr : m_currentStacks.back().get();
1239 return nullptr;
1240 return m_currentStacks.last();
1241 } 1244 }
1242 1245
1243 void V8DebuggerAgentImpl::didParseSource(const V8DebuggerParsedScript& parsedScr ipt) 1246 void V8DebuggerAgentImpl::didParseSource(const V8DebuggerParsedScript& parsedScr ipt)
1244 { 1247 {
1245 V8DebuggerScript script = parsedScript.script; 1248 V8DebuggerScript script = parsedScript.script;
1246 1249
1247 bool isDeprecatedSourceURL = false; 1250 bool isDeprecatedSourceURL = false;
1248 if (!parsedScript.success) 1251 if (!parsedScript.success)
1249 script.setSourceURL(V8ContentSearchUtil::findSourceURL(script.source(), false, &isDeprecatedSourceURL)); 1252 script.setSourceURL(V8ContentSearchUtil::findSourceURL(script.source(), false, &isDeprecatedSourceURL));
1250 else if (script.hasSourceURL()) 1253 else if (script.hasSourceURL())
(...skipping 20 matching lines...) Expand all
1271 const bool* isContentScriptParam = isContentScript ? &isContentScript : null ptr; 1274 const bool* isContentScriptParam = isContentScript ? &isContentScript : null ptr;
1272 const bool* isInternalScriptParam = isInternalScript ? &isInternalScript : n ullptr; 1275 const bool* isInternalScriptParam = isInternalScript ? &isInternalScript : n ullptr;
1273 const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr; 1276 const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr;
1274 const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr; 1277 const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr;
1275 const bool* deprecatedCommentWasUsedParam = deprecatedCommentWasUsed ? &depr ecatedCommentWasUsed : nullptr; 1278 const bool* deprecatedCommentWasUsedParam = deprecatedCommentWasUsed ? &depr ecatedCommentWasUsed : nullptr;
1276 if (parsedScript.success) 1279 if (parsedScript.success)
1277 m_frontend.scriptParsed(parsedScript.scriptId, scriptURL, script.startLi ne(), script.startColumn(), script.endLine(), script.endColumn(), executionConte xtId, script.hash(), isContentScriptParam, isInternalScriptParam, isLiveEditPara m, sourceMapURLParam, hasSourceURLParam, deprecatedCommentWasUsedParam); 1280 m_frontend.scriptParsed(parsedScript.scriptId, scriptURL, script.startLi ne(), script.startColumn(), script.endLine(), script.endColumn(), executionConte xtId, script.hash(), isContentScriptParam, isInternalScriptParam, isLiveEditPara m, sourceMapURLParam, hasSourceURLParam, deprecatedCommentWasUsedParam);
1278 else 1281 else
1279 m_frontend.scriptFailedToParse(parsedScript.scriptId, scriptURL, script. startLine(), script.startColumn(), script.endLine(), script.endColumn(), executi onContextId, script.hash(), isContentScriptParam, isInternalScriptParam, sourceM apURLParam, hasSourceURLParam, deprecatedCommentWasUsedParam); 1282 m_frontend.scriptFailedToParse(parsedScript.scriptId, scriptURL, script. startLine(), script.startColumn(), script.endLine(), script.endColumn(), executi onContextId, script.hash(), isContentScriptParam, isInternalScriptParam, sourceM apURLParam, hasSourceURLParam, deprecatedCommentWasUsedParam);
1280 1283
1281 m_scripts.set(parsedScript.scriptId, script); 1284 m_scripts[parsedScript.scriptId] = script;
1282 1285
1283 if (scriptURL.isEmpty() || !parsedScript.success) 1286 if (scriptURL.isEmpty() || !parsedScript.success)
1284 return; 1287 return;
1285 1288
1286 protocol::DictionaryValue* breakpointsCookie = m_state->getObject(DebuggerAg entState::javaScriptBreakpoints); 1289 protocol::DictionaryValue* breakpointsCookie = m_state->getObject(DebuggerAg entState::javaScriptBreakpoints);
1287 if (!breakpointsCookie) 1290 if (!breakpointsCookie)
1288 return; 1291 return;
1289 1292
1290 for (size_t i = 0; i < breakpointsCookie->size(); ++i) { 1293 for (size_t i = 0; i < breakpointsCookie->size(); ++i) {
1291 auto cookie = breakpointsCookie->at(i); 1294 auto cookie = breakpointsCookie->at(i);
1292 protocol::DictionaryValue* breakpointObject = protocol::DictionaryValue: :cast(cookie.second); 1295 protocol::DictionaryValue* breakpointObject = protocol::DictionaryValue: :cast(cookie.second);
1293 bool isRegex; 1296 bool isRegex;
1294 breakpointObject->getBoolean(DebuggerAgentState::isRegex, &isRegex); 1297 breakpointObject->getBoolean(DebuggerAgentState::isRegex, &isRegex);
1295 String16 url; 1298 String16 url;
1296 breakpointObject->getString(DebuggerAgentState::url, &url); 1299 breakpointObject->getString(DebuggerAgentState::url, &url);
1297 if (!matches(m_debugger, scriptURL, url, isRegex)) 1300 if (!matches(m_debugger, scriptURL, url, isRegex))
1298 continue; 1301 continue;
1299 ScriptBreakpoint breakpoint; 1302 ScriptBreakpoint breakpoint;
1300 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber); 1303 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber);
1301 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber); 1304 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber);
1302 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition); 1305 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition);
1303 std::unique_ptr<protocol::Debugger::Location> location = resolveBreakpoi nt(cookie.first, parsedScript.scriptId, breakpoint, UserBreakpointSource); 1306 std::unique_ptr<protocol::Debugger::Location> location = resolveBreakpoi nt(cookie.first, parsedScript.scriptId, breakpoint, UserBreakpointSource);
1304 if (location) 1307 if (location)
1305 m_frontend.breakpointResolved(cookie.first, std::move(location)); 1308 m_frontend.breakpointResolved(cookie.first, std::move(location));
1306 } 1309 }
1307 } 1310 }
1308 1311
1309 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::didPause(v8::Local<v8 ::Context> context, v8::Local<v8::Value> exception, const protocol::Vector<Strin g16>& hitBreakpoints, bool isPromiseRejection) 1312 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::didPause(v8::Local<v8 ::Context> context, v8::Local<v8::Value> exception, const std::vector<String16>& hitBreakpoints, bool isPromiseRejection)
1310 { 1313 {
1311 JavaScriptCallFrames callFrames = debugger().currentCallFrames(1); 1314 JavaScriptCallFrames callFrames = debugger().currentCallFrames(1);
1312 JavaScriptCallFrame* topCallFrame = callFrames.size() > 0 ? callFrames[0] : nullptr; 1315 JavaScriptCallFrame* topCallFrame = !callFrames.empty() ? callFrames.begin() ->get() : nullptr;
1313 1316
1314 V8DebuggerAgentImpl::SkipPauseRequest result; 1317 V8DebuggerAgentImpl::SkipPauseRequest result;
1315 if (m_skipAllPauses) 1318 if (m_skipAllPauses)
1316 result = RequestContinue; 1319 result = RequestContinue;
1317 else if (!hitBreakpoints.isEmpty()) 1320 else if (!hitBreakpoints.empty())
1318 result = RequestNoSkip; // Don't skip explicit breakpoints even if set i n frameworks. 1321 result = RequestNoSkip; // Don't skip explicit breakpoints even if set i n frameworks.
1319 else if (!exception.IsEmpty()) 1322 else if (!exception.IsEmpty())
1320 result = shouldSkipExceptionPause(topCallFrame); 1323 result = shouldSkipExceptionPause(topCallFrame);
1321 else if (m_scheduledDebuggerStep != NoStep || m_javaScriptPauseScheduled || m_pausingOnNativeEvent) 1324 else if (m_scheduledDebuggerStep != NoStep || m_javaScriptPauseScheduled || m_pausingOnNativeEvent)
1322 result = shouldSkipStepPause(topCallFrame); 1325 result = shouldSkipStepPause(topCallFrame);
1323 else 1326 else
1324 result = RequestNoSkip; 1327 result = RequestNoSkip;
1325 1328
1326 m_skipNextDebuggerStepOut = false; 1329 m_skipNextDebuggerStepOut = false;
1327 if (result != RequestNoSkip) 1330 if (result != RequestNoSkip)
1328 return result; 1331 return result;
1329 // Skip pauses inside V8 internal scripts and on syntax errors. 1332 // Skip pauses inside V8 internal scripts and on syntax errors.
1330 if (!topCallFrame) 1333 if (!topCallFrame)
1331 return RequestContinue; 1334 return RequestContinue;
1332 1335
1333 DCHECK(m_pausedContext.IsEmpty()); 1336 DCHECK(m_pausedContext.IsEmpty());
1334 m_pausedCallFrames.swap(debugger().currentCallFrames()); 1337 JavaScriptCallFrames frames = debugger().currentCallFrames();
1338 m_pausedCallFrames.swap(frames);
1335 m_pausedContext.Reset(m_isolate, context); 1339 m_pausedContext.Reset(m_isolate, context);
1336 v8::HandleScope handles(m_isolate); 1340 v8::HandleScope handles(m_isolate);
1337 1341
1338 if (!exception.IsEmpty()) { 1342 if (!exception.IsEmpty()) {
1339 ErrorString ignored; 1343 ErrorString ignored;
1340 InjectedScript* injectedScript = m_session->findInjectedScript(&ignored, V8Debugger::contextId(context)); 1344 InjectedScript* injectedScript = m_session->findInjectedScript(&ignored, V8Debugger::contextId(context));
1341 if (injectedScript) { 1345 if (injectedScript) {
1342 m_breakReason = isPromiseRejection ? protocol::Debugger::Paused::Rea sonEnum::PromiseRejection : protocol::Debugger::Paused::ReasonEnum::Exception; 1346 m_breakReason = isPromiseRejection ? protocol::Debugger::Paused::Rea sonEnum::PromiseRejection : protocol::Debugger::Paused::ReasonEnum::Exception;
1343 ErrorString errorString; 1347 ErrorString errorString;
1344 auto obj = injectedScript->wrapObject(&errorString, exception, V8Ins pectorSession::backtraceObjectGroup); 1348 auto obj = injectedScript->wrapObject(&errorString, exception, V8Ins pectorSession::backtraceObjectGroup);
1345 m_breakAuxData = obj ? obj->serialize() : nullptr; 1349 m_breakAuxData = obj ? obj->serialize() : nullptr;
1346 // m_breakAuxData might be null after this. 1350 // m_breakAuxData might be null after this.
1347 } 1351 }
1348 } 1352 }
1349 1353
1350 std::unique_ptr<Array<String16>> hitBreakpointIds = Array<String16>::create( ); 1354 std::unique_ptr<Array<String16>> hitBreakpointIds = Array<String16>::create( );
1351 1355
1352 for (const auto& point : hitBreakpoints) { 1356 for (const auto& point : hitBreakpoints) {
1353 DebugServerBreakpointToBreakpointIdAndSourceMap::iterator breakpointIter ator = m_serverBreakpoints.find(point); 1357 DebugServerBreakpointToBreakpointIdAndSourceMap::iterator breakpointIter ator = m_serverBreakpoints.find(point);
1354 if (breakpointIterator != m_serverBreakpoints.end()) { 1358 if (breakpointIterator != m_serverBreakpoints.end()) {
1355 const String16& localId = breakpointIterator->second->first; 1359 const String16& localId = breakpointIterator->second.first;
1356 hitBreakpointIds->addItem(localId); 1360 hitBreakpointIds->addItem(localId);
1357 1361
1358 BreakpointSource source = breakpointIterator->second->second; 1362 BreakpointSource source = breakpointIterator->second.second;
1359 if (m_breakReason == protocol::Debugger::Paused::ReasonEnum::Other & & source == DebugCommandBreakpointSource) 1363 if (m_breakReason == protocol::Debugger::Paused::ReasonEnum::Other & & source == DebugCommandBreakpointSource)
1360 m_breakReason = protocol::Debugger::Paused::ReasonEnum::DebugCom mand; 1364 m_breakReason = protocol::Debugger::Paused::ReasonEnum::DebugCom mand;
1361 } 1365 }
1362 } 1366 }
1363 1367
1364 ErrorString errorString; 1368 ErrorString errorString;
1365 m_frontend.paused(currentCallFrames(&errorString), m_breakReason, std::move( m_breakAuxData), std::move(hitBreakpointIds), currentAsyncStackTrace()); 1369 m_frontend.paused(currentCallFrames(&errorString), m_breakReason, std::move( m_breakAuxData), std::move(hitBreakpointIds), currentAsyncStackTrace());
1366 m_scheduledDebuggerStep = NoStep; 1370 m_scheduledDebuggerStep = NoStep;
1367 m_javaScriptPauseScheduled = false; 1371 m_javaScriptPauseScheduled = false;
1368 m_steppingFromFramework = false; 1372 m_steppingFromFramework = false;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 if (!enabled()) 1441 if (!enabled())
1438 return; 1442 return;
1439 m_scheduledDebuggerStep = NoStep; 1443 m_scheduledDebuggerStep = NoStep;
1440 m_scripts.clear(); 1444 m_scripts.clear();
1441 m_blackboxedPositions.clear(); 1445 m_blackboxedPositions.clear();
1442 m_breakpointIdToDebuggerBreakpointIds.clear(); 1446 m_breakpointIdToDebuggerBreakpointIds.clear();
1443 allAsyncTasksCanceled(); 1447 allAsyncTasksCanceled();
1444 } 1448 }
1445 1449
1446 } // namespace blink 1450 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698