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

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

Issue 1838683002: [DevTools] Debugger::currentCallFrames returns array instead linked list (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wrap-with-corrrect-injected-script
Patch Set: Created 4 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 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/IgnoreExceptionsScope.h" 9 #include "platform/v8_inspector/IgnoreExceptionsScope.h"
10 #include "platform/v8_inspector/InjectedScript.h" 10 #include "platform/v8_inspector/InjectedScript.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 { 236 {
237 if (!enabled()) 237 if (!enabled())
238 return; 238 return;
239 239
240 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, protocol::Dict ionaryValue::create()); 240 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, protocol::Dict ionaryValue::create());
241 m_state->setNumber(DebuggerAgentState::pauseOnExceptionsState, V8DebuggerImp l::DontPauseOnExceptions); 241 m_state->setNumber(DebuggerAgentState::pauseOnExceptionsState, V8DebuggerImp l::DontPauseOnExceptions);
242 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, 0); 242 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, 0);
243 243
244 debugger().removeDebuggerAgent(m_contextGroupId); 244 debugger().removeDebuggerAgent(m_contextGroupId);
245 m_pausedContext.Reset(); 245 m_pausedContext.Reset();
246 m_currentCallStack.clear(); 246 JavaScriptCallFrames emptyCallFrames;
247 m_pausedCallFrames.swap(emptyCallFrames);
247 m_scripts.clear(); 248 m_scripts.clear();
248 m_blackboxedPositions.clear(); 249 m_blackboxedPositions.clear();
249 m_breakpointIdToDebuggerBreakpointIds.clear(); 250 m_breakpointIdToDebuggerBreakpointIds.clear();
250 internalSetAsyncCallStackDepth(0); 251 internalSetAsyncCallStackDepth(0);
251 m_continueToLocationBreakpointId = String16(); 252 m_continueToLocationBreakpointId = String16();
252 clearBreakDetails(); 253 clearBreakDetails();
253 m_scheduledDebuggerStep = NoStep; 254 m_scheduledDebuggerStep = NoStep;
254 m_skipNextDebuggerStepOut = false; 255 m_skipNextDebuggerStepOut = false;
255 m_javaScriptPauseScheduled = false; 256 m_javaScriptPauseScheduled = false;
256 m_steppingFromFramework = false; 257 m_steppingFromFramework = false;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 478
478 ScriptBreakpoint breakpoint(lineNumber, columnNumber, ""); 479 ScriptBreakpoint breakpoint(lineNumber, columnNumber, "");
479 m_continueToLocationBreakpointId = debugger().setBreakpoint(scriptId, breakp oint, &lineNumber, &columnNumber, interstateLocationOpt.fromMaybe(false)); 480 m_continueToLocationBreakpointId = debugger().setBreakpoint(scriptId, breakp oint, &lineNumber, &columnNumber, interstateLocationOpt.fromMaybe(false));
480 resume(errorString); 481 resume(errorString);
481 } 482 }
482 483
483 void V8DebuggerAgentImpl::getBacktrace(ErrorString* errorString, OwnPtr<Array<Ca llFrame>>* callFrames, Maybe<StackTrace>* asyncStackTrace) 484 void V8DebuggerAgentImpl::getBacktrace(ErrorString* errorString, OwnPtr<Array<Ca llFrame>>* callFrames, Maybe<StackTrace>* asyncStackTrace)
484 { 485 {
485 if (!assertPaused(errorString)) 486 if (!assertPaused(errorString))
486 return; 487 return;
487 m_currentCallStack = debugger().currentCallFrames(); 488 m_pausedCallFrames = debugger().currentCallFrames();
488 *callFrames = currentCallFrames(errorString); 489 *callFrames = currentCallFrames(errorString);
489 if (!*callFrames) 490 if (!*callFrames)
490 return; 491 return;
491 *asyncStackTrace = currentAsyncStackTrace(); 492 *asyncStackTrace = currentAsyncStackTrace();
492 } 493 }
493 494
494 bool V8DebuggerAgentImpl::isCallStackEmptyOrBlackboxed() 495 bool V8DebuggerAgentImpl::isCurrentCallStackEmptyOrBlackboxed()
495 { 496 {
496 ASSERT(enabled()); 497 ASSERT(enabled());
497 for (int index = 0; ; ++index) { 498 JavaScriptCallFrames callFrames = debugger().currentCallFrames();
498 OwnPtr<JavaScriptCallFrame> frame = debugger().callFrame(index); 499 for (size_t index = 0; index < callFrames.size(); ++index) {
499 if (!frame) 500 if (!isCallFrameWithUnknownScriptOrBlackboxed(callFrames[index].get()))
500 break;
501 if (!isCallFrameWithUnknownScriptOrBlackboxed(frame.get()))
502 return false; 501 return false;
503 } 502 }
504 return true; 503 return true;
505 } 504 }
506 505
507 bool V8DebuggerAgentImpl::isTopCallFrameBlackboxed() 506 bool V8DebuggerAgentImpl::isTopPausedCallFrameBlackboxed()
508 { 507 {
509 ASSERT(enabled()); 508 ASSERT(enabled());
510 return isCallFrameWithUnknownScriptOrBlackboxed(debugger().callFrame(0).get( )); 509 return isCallFrameWithUnknownScriptOrBlackboxed(m_pausedCallFrames.size() ? m_pausedCallFrames[0].get() : nullptr);
511 } 510 }
512 511
513 bool V8DebuggerAgentImpl::isCallFrameWithUnknownScriptOrBlackboxed(JavaScriptCal lFrame* frame) 512 bool V8DebuggerAgentImpl::isCallFrameWithUnknownScriptOrBlackboxed(JavaScriptCal lFrame* frame)
514 { 513 {
515 if (!frame) 514 if (!frame)
516 return true; 515 return true;
517 ScriptsMap::iterator it = m_scripts.find(String16::number(frame->sourceID()) ); 516 ScriptsMap::iterator it = m_scripts.find(String16::number(frame->sourceID()) );
518 if (it == m_scripts.end()) { 517 if (it == m_scripts.end()) {
519 // Unknown scripts are blackboxed. 518 // Unknown scripts are blackboxed.
520 return true; 519 return true;
521 } 520 }
522 auto itBlackboxedPositions = m_blackboxedPositions.find(String16::number(fra me->sourceID())); 521 auto itBlackboxedPositions = m_blackboxedPositions.find(String16::number(fra me->sourceID()));
523 if (itBlackboxedPositions == m_blackboxedPositions.end()) 522 if (itBlackboxedPositions == m_blackboxedPositions.end())
524 return false; 523 return false;
525 524
526 protocol::Vector<std::pair<int, int>>* ranges = itBlackboxedPositions->secon d; 525 protocol::Vector<std::pair<int, int>>* ranges = itBlackboxedPositions->secon d;
527 auto itRange = std::lower_bound(ranges->begin(), ranges->end(), std::make_pa ir(frame->line(), frame->column()), positionComparator); 526 auto itRange = std::lower_bound(ranges->begin(), ranges->end(), std::make_pa ir(frame->line(), frame->column()), positionComparator);
528 // Ranges array contains positions in script where blackbox state is changed . 527 // Ranges array contains positions in script where blackbox state is changed .
529 // [(0,0) ... ranges[0]) isn't blackboxed, [ranges[0] ... ranges[1]) is blac kboxed... 528 // [(0,0) ... ranges[0]) isn't blackboxed, [ranges[0] ... ranges[1]) is blac kboxed...
530 return std::distance(ranges->begin(), itRange) % 2; 529 return std::distance(ranges->begin(), itRange) % 2;
531 } 530 }
532 531
533 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::shouldSkipExceptionPa use() 532 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::shouldSkipExceptionPa use(JavaScriptCallFrame* topCallFrame)
534 { 533 {
535 if (m_steppingFromFramework) 534 if (m_steppingFromFramework)
536 return RequestNoSkip; 535 return RequestNoSkip;
537 if (isTopCallFrameBlackboxed()) 536 if (isCallFrameWithUnknownScriptOrBlackboxed(topCallFrame))
538 return RequestContinue; 537 return RequestContinue;
539 return RequestNoSkip; 538 return RequestNoSkip;
540 } 539 }
541 540
542 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::shouldSkipStepPause() 541 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::shouldSkipStepPause(J avaScriptCallFrame* topCallFrame)
543 { 542 {
544 if (m_steppingFromFramework) 543 if (m_steppingFromFramework)
545 return RequestNoSkip; 544 return RequestNoSkip;
546 545
547 if (m_skipNextDebuggerStepOut) { 546 if (m_skipNextDebuggerStepOut) {
548 m_skipNextDebuggerStepOut = false; 547 m_skipNextDebuggerStepOut = false;
549 if (m_scheduledDebuggerStep == StepOut) 548 if (m_scheduledDebuggerStep == StepOut)
550 return RequestStepOut; 549 return RequestStepOut;
551 } 550 }
552 551
553 if (!isTopCallFrameBlackboxed()) 552 if (!isCallFrameWithUnknownScriptOrBlackboxed(topCallFrame))
554 return RequestNoSkip; 553 return RequestNoSkip;
555 554
556 if (m_skippedStepFrameCount >= maxSkipStepFrameCount) 555 if (m_skippedStepFrameCount >= maxSkipStepFrameCount)
557 return RequestStepOut; 556 return RequestStepOut;
558 557
559 if (!m_skippedStepFrameCount) 558 if (!m_skippedStepFrameCount)
560 m_recursionLevelForStepFrame = 1; 559 m_recursionLevelForStepFrame = 1;
561 560
562 ++m_skippedStepFrameCount; 561 ++m_skippedStepFrameCount;
563 return RequestStepFrame; 562 return RequestStepFrame;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 const String16& scriptId, 608 const String16& scriptId,
610 const String16& newContent, 609 const String16& newContent,
611 const Maybe<bool>& preview, 610 const Maybe<bool>& preview,
612 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* newCallFrames, 611 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* newCallFrames,
613 Maybe<bool>* stackChanged, 612 Maybe<bool>* stackChanged,
614 Maybe<StackTrace>* asyncStackTrace, 613 Maybe<StackTrace>* asyncStackTrace,
615 Maybe<protocol::Debugger::SetScriptSourceError>* optOutCompileError) 614 Maybe<protocol::Debugger::SetScriptSourceError>* optOutCompileError)
616 { 615 {
617 if (!checkEnabled(errorString)) 616 if (!checkEnabled(errorString))
618 return; 617 return;
619 if (!debugger().setScriptSource(scriptId, newContent, preview.fromMaybe(fals e), errorString, optOutCompileError, &m_currentCallStack, stackChanged)) 618 if (!debugger().setScriptSource(scriptId, newContent, preview.fromMaybe(fals e), errorString, optOutCompileError, &m_pausedCallFrames, stackChanged))
620 return; 619 return;
621 620
622 OwnPtr<Array<CallFrame>> callFrames = currentCallFrames(errorString); 621 OwnPtr<Array<CallFrame>> callFrames = currentCallFrames(errorString);
623 if (!callFrames) 622 if (!callFrames)
624 return; 623 return;
625 *newCallFrames = callFrames.release(); 624 *newCallFrames = callFrames.release();
626 *asyncStackTrace = currentAsyncStackTrace(); 625 *asyncStackTrace = currentAsyncStackTrace();
627 626
628 ScriptsMap::iterator it = m_scripts.find(scriptId); 627 ScriptsMap::iterator it = m_scripts.find(scriptId);
629 if (it == m_scripts.end()) 628 if (it == m_scripts.end())
630 return; 629 return;
631 it->second->setSource(newContent); 630 it->second->setSource(newContent);
632 } 631 }
633 632
634 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString, 633 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString,
635 const String16& callFrameId, 634 const String16& callFrameId,
636 OwnPtr<Array<CallFrame>>* newCallFrames, 635 OwnPtr<Array<CallFrame>>* newCallFrames,
637 Maybe<StackTrace>* asyncStackTrace) 636 Maybe<StackTrace>* asyncStackTrace)
638 { 637 {
639 if (!isPaused() || !m_currentCallStack) { 638 if (!assertPaused(errorString))
640 *errorString = "Attempt to access call frame when debugger is not on pau se";
641 return; 639 return;
642 }
643 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 640 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
644 if (!remoteId) 641 if (!remoteId)
645 return; 642 return;
646 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 643 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
647 if (!injectedScript) 644 if (!injectedScript)
648 return; 645 return;
649 646
650 v8::HandleScope scope(m_isolate); 647 v8::HandleScope scope(m_isolate);
651 v8::Local<v8::Context> localContext = injectedScript->context(); 648 v8::Local<v8::Context> localContext = injectedScript->context();
652 649
653 v8::TryCatch tryCatch(m_isolate); 650 v8::TryCatch tryCatch(m_isolate);
654 651
655 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrame(remot eId->frameOrdinal()); 652 size_t frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal());
656 if (!javaScriptCallFrame) { 653 if (frameOrdinal >= m_pausedCallFrames.size()) {
657 *errorString = "Could not find call frame with given id"; 654 *errorString = "Could not find call frame with given id";
658 return; 655 return;
659 } 656 }
660 v8::Local<v8::Value> resultValue; 657 v8::Local<v8::Value> resultValue;
661 v8::Local<v8::Boolean> result; 658 v8::Local<v8::Boolean> result;
662 if (!javaScriptCallFrame->restart().ToLocal(&resultValue) || tryCatch.HasCau ght() || !resultValue->ToBoolean(localContext).ToLocal(&result) || !result->Valu e()) { 659 if (!m_pausedCallFrames[frameOrdinal].get()->restart().ToLocal(&resultValue) || tryCatch.HasCaught() || !resultValue->ToBoolean(localContext).ToLocal(&resul t) || !result->Value()) {
663 *errorString = "Internal error"; 660 *errorString = "Internal error";
664 return; 661 return;
665 } 662 }
666 663
667 m_currentCallStack = debugger().currentCallFrames(); 664 m_pausedCallFrames = debugger().currentCallFrames();
668 665
669 *newCallFrames = currentCallFrames(errorString); 666 *newCallFrames = currentCallFrames(errorString);
670 if (!*newCallFrames) 667 if (!*newCallFrames)
671 return; 668 return;
672 *asyncStackTrace = currentAsyncStackTrace(); 669 *asyncStackTrace = currentAsyncStackTrace();
673 } 670 }
674 671
675 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource) 672 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource)
676 { 673 {
677 if (!checkEnabled(error)) 674 if (!checkEnabled(error))
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 m_steppingFromFramework = false; 882 m_steppingFromFramework = false;
886 m_injectedScriptManager->releaseObjectGroup(V8DebuggerAgentImpl::backtraceOb jectGroup); 883 m_injectedScriptManager->releaseObjectGroup(V8DebuggerAgentImpl::backtraceOb jectGroup);
887 debugger().continueProgram(); 884 debugger().continueProgram();
888 } 885 }
889 886
890 void V8DebuggerAgentImpl::stepOver(ErrorString* errorString) 887 void V8DebuggerAgentImpl::stepOver(ErrorString* errorString)
891 { 888 {
892 if (!assertPaused(errorString)) 889 if (!assertPaused(errorString))
893 return; 890 return;
894 // StepOver at function return point should fallback to StepInto. 891 // StepOver at function return point should fallback to StepInto.
895 OwnPtr<JavaScriptCallFrame> frame = debugger().callFrame(0); 892 JavaScriptCallFrame* frame = m_pausedCallFrames.size() ? m_pausedCallFrames[ 0].get() : nullptr;
896 if (frame && frame->isAtReturn()) { 893 if (frame && frame->isAtReturn()) {
897 stepInto(errorString); 894 stepInto(errorString);
898 return; 895 return;
899 } 896 }
900 m_scheduledDebuggerStep = StepOver; 897 m_scheduledDebuggerStep = StepOver;
901 m_steppingFromFramework = isTopCallFrameBlackboxed(); 898 m_steppingFromFramework = isTopPausedCallFrameBlackboxed();
902 m_injectedScriptManager->releaseObjectGroup(V8DebuggerAgentImpl::backtraceOb jectGroup); 899 m_injectedScriptManager->releaseObjectGroup(V8DebuggerAgentImpl::backtraceOb jectGroup);
903 debugger().stepOverStatement(); 900 debugger().stepOverStatement();
904 } 901 }
905 902
906 void V8DebuggerAgentImpl::stepInto(ErrorString* errorString) 903 void V8DebuggerAgentImpl::stepInto(ErrorString* errorString)
907 { 904 {
908 if (!assertPaused(errorString)) 905 if (!assertPaused(errorString))
909 return; 906 return;
910 m_scheduledDebuggerStep = StepInto; 907 m_scheduledDebuggerStep = StepInto;
911 m_steppingFromFramework = isTopCallFrameBlackboxed(); 908 m_steppingFromFramework = isTopPausedCallFrameBlackboxed();
912 m_injectedScriptManager->releaseObjectGroup(V8DebuggerAgentImpl::backtraceOb jectGroup); 909 m_injectedScriptManager->releaseObjectGroup(V8DebuggerAgentImpl::backtraceOb jectGroup);
913 debugger().stepIntoStatement(); 910 debugger().stepIntoStatement();
914 } 911 }
915 912
916 void V8DebuggerAgentImpl::stepOut(ErrorString* errorString) 913 void V8DebuggerAgentImpl::stepOut(ErrorString* errorString)
917 { 914 {
918 if (!assertPaused(errorString)) 915 if (!assertPaused(errorString))
919 return; 916 return;
920 m_scheduledDebuggerStep = StepOut; 917 m_scheduledDebuggerStep = StepOut;
921 m_skipNextDebuggerStepOut = false; 918 m_skipNextDebuggerStepOut = false;
922 m_recursionLevelForStepOut = 1; 919 m_recursionLevelForStepOut = 1;
923 m_steppingFromFramework = isTopCallFrameBlackboxed(); 920 m_steppingFromFramework = isTopPausedCallFrameBlackboxed();
924 m_injectedScriptManager->releaseObjectGroup(V8DebuggerAgentImpl::backtraceOb jectGroup); 921 m_injectedScriptManager->releaseObjectGroup(V8DebuggerAgentImpl::backtraceOb jectGroup);
925 debugger().stepOutOfFunction(); 922 debugger().stepOutOfFunction();
926 } 923 }
927 924
928 void V8DebuggerAgentImpl::stepIntoAsync(ErrorString* errorString) 925 void V8DebuggerAgentImpl::stepIntoAsync(ErrorString* errorString)
929 { 926 {
930 if (!assertPaused(errorString)) 927 if (!assertPaused(errorString))
931 return; 928 return;
932 if (!trackingAsyncCalls()) { 929 if (!trackingAsyncCalls()) {
933 *errorString = "Can only perform operation if async call stacks are enab led."; 930 *errorString = "Can only perform operation if async call stacks are enab led.";
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 const String16& expression, 967 const String16& expression,
971 const Maybe<String16>& objectGroup, 968 const Maybe<String16>& objectGroup,
972 const Maybe<bool>& includeCommandLineAPI, 969 const Maybe<bool>& includeCommandLineAPI,
973 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 970 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
974 const Maybe<bool>& returnByValue, 971 const Maybe<bool>& returnByValue,
975 const Maybe<bool>& generatePreview, 972 const Maybe<bool>& generatePreview,
976 OwnPtr<RemoteObject>* result, 973 OwnPtr<RemoteObject>* result,
977 Maybe<bool>* wasThrown, 974 Maybe<bool>* wasThrown,
978 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) 975 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails)
979 { 976 {
980 if (!isPaused() || !m_currentCallStack) { 977 if (!assertPaused(errorString))
981 *errorString = "Attempt to access callframe when debugger is not on paus e";
982 return; 978 return;
983 }
984 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 979 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
985 if (!remoteId) 980 if (!remoteId)
986 return; 981 return;
987 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 982 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
988 if (!injectedScript) 983 if (!injectedScript)
989 return; 984 return;
990 985
991 v8::HandleScope scope(injectedScript->isolate()); 986 v8::HandleScope scope(injectedScript->isolate());
992 987
993 if (!injectedScript->canAccessInspectedWindow()) { 988 if (!injectedScript->canAccessInspectedWindow()) {
994 *errorString = "Can not access given context"; 989 *errorString = "Can not access given context";
995 return; 990 return;
996 } 991 }
997 992
998 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrame(remot eId->frameOrdinal()); 993 size_t frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal());
999 if (!javaScriptCallFrame) { 994 if (frameOrdinal >= m_pausedCallFrames.size()) {
1000 *errorString = "Could not find call frame with given id"; 995 *errorString = "Could not find call frame with given id";
1001 return; 996 return;
1002 } 997 }
1003 998
1004 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe( false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object >(); 999 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe( false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object >();
1005 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty()) 1000 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty())
1006 return; 1001 return;
1007 1002
1008 InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedSc ript, m_injectedScriptManager, commandLineAPI); 1003 InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedSc ript, m_injectedScriptManager, commandLineAPI);
1009 1004
1010 v8::TryCatch tryCatch(injectedScript->isolate()); 1005 v8::TryCatch tryCatch(injectedScript->isolate());
1011 1006
1012 v8::MaybeLocal<v8::Value> maybeResultValue = javaScriptCallFrame->evaluate(t oV8String(injectedScript->isolate(), expression)); 1007 v8::MaybeLocal<v8::Value> maybeResultValue = m_pausedCallFrames[frameOrdinal ].get()->evaluate(toV8String(injectedScript->isolate(), expression));
1013 1008
1014 // InjectedScript may be gone after any evaluate call - find it again. 1009 // InjectedScript may be gone after any evaluate call - find it again.
1015 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re moteId.get()); 1010 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re moteId.get());
1016 if (!injectedScript) 1011 if (!injectedScript)
1017 return; 1012 return;
1018 1013
1019 injectedScript->wrapEvaluateResult(errorString, 1014 injectedScript->wrapEvaluateResult(errorString,
1020 maybeResultValue, 1015 maybeResultValue,
1021 tryCatch, 1016 tryCatch,
1022 objectGroup.fromMaybe(""), 1017 objectGroup.fromMaybe(""),
1023 returnByValue.fromMaybe(false), 1018 returnByValue.fromMaybe(false),
1024 generatePreview.fromMaybe(false), 1019 generatePreview.fromMaybe(false),
1025 result, 1020 result,
1026 wasThrown, 1021 wasThrown,
1027 exceptionDetails); 1022 exceptionDetails);
1028 } 1023 }
1029 1024
1030 void V8DebuggerAgentImpl::setVariableValue(ErrorString* errorString, 1025 void V8DebuggerAgentImpl::setVariableValue(ErrorString* errorString,
1031 int scopeNumber, 1026 int scopeNumber,
1032 const String16& variableName, 1027 const String16& variableName,
1033 PassOwnPtr<protocol::Runtime::CallArgument> newValueArgument, 1028 PassOwnPtr<protocol::Runtime::CallArgument> newValueArgument,
1034 const String16& callFrameId) 1029 const String16& callFrameId)
1035 { 1030 {
1036 if (!checkEnabled(errorString)) 1031 if (!checkEnabled(errorString))
1037 return; 1032 return;
1038 if (!isPaused() || !m_currentCallStack) { 1033 if (!assertPaused(errorString))
1039 *errorString = "Attempt to access callframe when debugger is not on paus e";
1040 return; 1034 return;
1041 }
1042 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 1035 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
1043 if (!remoteId) 1036 if (!remoteId)
1044 return; 1037 return;
1045 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 1038 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
1046 if (!injectedScript) 1039 if (!injectedScript)
1047 return; 1040 return;
1048 1041
1049 v8::HandleScope scope(m_isolate); 1042 v8::HandleScope scope(m_isolate);
1050 v8::TryCatch tryCatch(m_isolate); 1043 v8::TryCatch tryCatch(m_isolate);
1051 1044
1052 v8::Local<v8::Value> newValue; 1045 v8::Local<v8::Value> newValue;
1053 if (!injectedScript->resolveCallArgument(errorString, newValueArgument.get() ).ToLocal(&newValue)) 1046 if (!injectedScript->resolveCallArgument(errorString, newValueArgument.get() ).ToLocal(&newValue))
1054 return; 1047 return;
1055 1048
1056 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrame(remot eId->frameOrdinal()); 1049 size_t frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal());
1057 if (!javaScriptCallFrame) { 1050 if (frameOrdinal >= m_pausedCallFrames.size()) {
1058 *errorString = "Could not find call frame with given id"; 1051 *errorString = "Could not find call frame with given id";
1059 return; 1052 return;
1060 } 1053 }
1061 v8::MaybeLocal<v8::Value> result = javaScriptCallFrame->setVariableValue(sco peNumber, toV8String(m_isolate, variableName), newValue); 1054 v8::MaybeLocal<v8::Value> result = m_pausedCallFrames[frameOrdinal].get()->s etVariableValue(scopeNumber, toV8String(m_isolate, variableName), newValue);
1062 if (tryCatch.HasCaught() || result.IsEmpty()) { 1055 if (tryCatch.HasCaught() || result.IsEmpty()) {
1063 *errorString = "Internal error"; 1056 *errorString = "Internal error";
1064 return; 1057 return;
1065 } 1058 }
1066 } 1059 }
1067 1060
1068 void V8DebuggerAgentImpl::setAsyncCallStackDepth(ErrorString* errorString, int d epth) 1061 void V8DebuggerAgentImpl::setAsyncCallStackDepth(ErrorString* errorString, int d epth)
1069 { 1062 {
1070 if (!checkEnabled(errorString)) 1063 if (!checkEnabled(errorString))
1071 return; 1064 return;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 if (m_scheduledDebuggerStep == NoStep) 1337 if (m_scheduledDebuggerStep == NoStep)
1345 debugger().clearStepping(); 1338 debugger().clearStepping();
1346 else if (m_scheduledDebuggerStep == StepOut) 1339 else if (m_scheduledDebuggerStep == StepOut)
1347 m_skipNextDebuggerStepOut = true; 1340 m_skipNextDebuggerStepOut = true;
1348 } 1341 }
1349 } 1342 }
1350 } 1343 }
1351 1344
1352 PassOwnPtr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames(ErrorString* errorString) 1345 PassOwnPtr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames(ErrorString* errorString)
1353 { 1346 {
1354 if (m_pausedContext.IsEmpty() || !m_currentCallStack) 1347 if (m_pausedContext.IsEmpty() || !m_pausedCallFrames.size())
1355 return Array<CallFrame>::create(); 1348 return Array<CallFrame>::create();
1356 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( m_pausedContext.Get(m_isolate)); 1349 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( m_pausedContext.Get(m_isolate));
1357 if (!injectedScript) { 1350 if (!injectedScript) {
1358 // Context has been reported as removed while on pause. 1351 // Context has been reported as removed while on pause.
1359 return Array<CallFrame>::create(); 1352 return Array<CallFrame>::create();
1360 } 1353 }
1361 1354
1362 v8::Isolate* isolate = injectedScript->isolate(); 1355 v8::Isolate* isolate = injectedScript->isolate();
1363 v8::HandleScope handles(isolate); 1356 v8::HandleScope handles(isolate);
1364 v8::Local<v8::Context> context = injectedScript->context(); 1357 v8::Local<v8::Context> context = injectedScript->context();
1365 v8::Context::Scope contextScope(context); 1358 v8::Context::Scope contextScope(context);
1366 1359
1367 JavaScriptCallFrame* currentCallFrame = m_currentCallStack.get();
1368 int callFrameIndex = 0;
1369 OwnPtr<JavaScriptCallFrame> currentCallFrameOwner;
1370 v8::Local<v8::Array> objects = v8::Array::New(isolate); 1360 v8::Local<v8::Array> objects = v8::Array::New(isolate);
1371 while (currentCallFrame) { 1361 for (size_t frameOrdinal = 0; frameOrdinal < m_pausedCallFrames.size(); ++fr ameOrdinal) {
1362 JavaScriptCallFrame* currentCallFrame = m_pausedCallFrames[frameOrdinal] .get();
1363
1372 v8::Local<v8::Object> details = currentCallFrame->details(); 1364 v8::Local<v8::Object> details = currentCallFrame->details();
1373 if (hasInternalError(errorString, details.IsEmpty())) 1365 if (hasInternalError(errorString, details.IsEmpty()))
1374 return Array<CallFrame>::create(); 1366 return Array<CallFrame>::create();
1375 1367
1376 String16 callFrameId = RemoteCallFrameId::serialize(injectedScript->cont extId(), callFrameIndex); 1368 String16 callFrameId = RemoteCallFrameId::serialize(injectedScript->cont extId(), frameOrdinal);
1377 if (hasInternalError(errorString, !details->Set(context, toV8StringInter nalized(isolate, "callFrameId"), toV8String(isolate, callFrameId)).FromMaybe(fal se))) 1369 if (hasInternalError(errorString, !details->Set(context, toV8StringInter nalized(isolate, "callFrameId"), toV8String(isolate, callFrameId)).FromMaybe(fal se)))
1378 return Array<CallFrame>::create(); 1370 return Array<CallFrame>::create();
1379 1371
1380 v8::Local<v8::Value> scopeChain; 1372 v8::Local<v8::Value> scopeChain;
1381 if (hasInternalError(errorString, !details->Get(context, toV8StringInter nalized(isolate, "scopeChain")).ToLocal(&scopeChain) || !scopeChain->IsArray())) 1373 if (hasInternalError(errorString, !details->Get(context, toV8StringInter nalized(isolate, "scopeChain")).ToLocal(&scopeChain) || !scopeChain->IsArray()))
1382 return Array<CallFrame>::create(); 1374 return Array<CallFrame>::create();
1383 v8::Local<v8::Array> scopeChainArray = scopeChain.As<v8::Array>(); 1375 v8::Local<v8::Array> scopeChainArray = scopeChain.As<v8::Array>();
1384 if (!injectedScript->wrapPropertyInArray(errorString, scopeChainArray, t oV8StringInternalized(isolate, "object"), V8DebuggerAgentImpl::backtraceObjectGr oup)) 1376 if (!injectedScript->wrapPropertyInArray(errorString, scopeChainArray, t oV8StringInternalized(isolate, "object"), V8DebuggerAgentImpl::backtraceObjectGr oup))
1385 return Array<CallFrame>::create(); 1377 return Array<CallFrame>::create();
1386 1378
1387 if (!injectedScript->wrapObjectProperty(errorString, details, toV8String Internalized(isolate, "this"), V8DebuggerAgentImpl::backtraceObjectGroup)) 1379 if (!injectedScript->wrapObjectProperty(errorString, details, toV8String Internalized(isolate, "this"), V8DebuggerAgentImpl::backtraceObjectGroup))
1388 return Array<CallFrame>::create(); 1380 return Array<CallFrame>::create();
1389 1381
1390 if (details->Has(context, toV8StringInternalized(isolate, "returnValue") ).FromMaybe(false)) { 1382 if (details->Has(context, toV8StringInternalized(isolate, "returnValue") ).FromMaybe(false)) {
1391 if (!injectedScript->wrapObjectProperty(errorString, details, toV8St ringInternalized(isolate, "returnValue"), V8DebuggerAgentImpl::backtraceObjectGr oup)) 1383 if (!injectedScript->wrapObjectProperty(errorString, details, toV8St ringInternalized(isolate, "returnValue"), V8DebuggerAgentImpl::backtraceObjectGr oup))
1392 return Array<CallFrame>::create(); 1384 return Array<CallFrame>::create();
1393 } 1385 }
1394 1386
1395 if (hasInternalError(errorString, !objects->Set(context, callFrameIndex, details).FromMaybe(false))) 1387 if (hasInternalError(errorString, !objects->Set(context, frameOrdinal, d etails).FromMaybe(false)))
1396 return Array<CallFrame>::create(); 1388 return Array<CallFrame>::create();
1397
1398 currentCallFrameOwner = currentCallFrame->caller();
1399 currentCallFrame = currentCallFrameOwner.get();
1400 ++callFrameIndex;
1401 } 1389 }
1402 1390
1403 protocol::ErrorSupport errorSupport; 1391 protocol::ErrorSupport errorSupport;
1404 OwnPtr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(toProtocolValu e(context, objects).get(), &errorSupport); 1392 OwnPtr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(toProtocolValu e(context, objects).get(), &errorSupport);
1405 if (hasInternalError(errorString, !callFrames)) 1393 if (hasInternalError(errorString, !callFrames))
1406 return Array<CallFrame>::create(); 1394 return Array<CallFrame>::create();
1407 return callFrames.release(); 1395 return callFrames.release();
1408 } 1396 }
1409 1397
1410 PassOwnPtr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace() 1398 PassOwnPtr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace()
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 ScriptBreakpoint breakpoint; 1467 ScriptBreakpoint breakpoint;
1480 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber); 1468 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber);
1481 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber); 1469 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber);
1482 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition); 1470 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition);
1483 OwnPtr<protocol::Debugger::Location> location = resolveBreakpoint(cookie .first, parsedScript.scriptId, breakpoint, UserBreakpointSource); 1471 OwnPtr<protocol::Debugger::Location> location = resolveBreakpoint(cookie .first, parsedScript.scriptId, breakpoint, UserBreakpointSource);
1484 if (location) 1472 if (location)
1485 m_frontend->breakpointResolved(cookie.first, location.release()); 1473 m_frontend->breakpointResolved(cookie.first, location.release());
1486 } 1474 }
1487 } 1475 }
1488 1476
1489 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::didPause(v8::Local<v8 ::Context> context, PassOwnPtr<JavaScriptCallFrame> callFrames, v8::Local<v8::Va lue> exception, const protocol::Vector<String16>& hitBreakpoints, bool isPromise Rejection) 1477 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::didPause(v8::Local<v8 ::Context> context, v8::Local<v8::Value> exception, const protocol::Vector<Strin g16>& hitBreakpoints, bool isPromiseRejection)
1490 { 1478 {
1479 JavaScriptCallFrames callFrames = debugger().currentCallFrames(1);
1480 JavaScriptCallFrame* topCallFrame = callFrames.size() > 0 ? callFrames[0].ge t() : nullptr;
1481
1491 V8DebuggerAgentImpl::SkipPauseRequest result; 1482 V8DebuggerAgentImpl::SkipPauseRequest result;
1492 if (m_skipAllPauses) 1483 if (m_skipAllPauses)
1493 result = RequestContinue; 1484 result = RequestContinue;
1494 else if (!hitBreakpoints.isEmpty()) 1485 else if (!hitBreakpoints.isEmpty())
1495 result = RequestNoSkip; // Don't skip explicit breakpoints even if set i n frameworks. 1486 result = RequestNoSkip; // Don't skip explicit breakpoints even if set i n frameworks.
1496 else if (!exception.IsEmpty()) 1487 else if (!exception.IsEmpty())
1497 result = shouldSkipExceptionPause(); 1488 result = shouldSkipExceptionPause(topCallFrame);
1498 else if (m_scheduledDebuggerStep != NoStep || m_javaScriptPauseScheduled || m_pausingOnNativeEvent) 1489 else if (m_scheduledDebuggerStep != NoStep || m_javaScriptPauseScheduled || m_pausingOnNativeEvent)
1499 result = shouldSkipStepPause(); 1490 result = shouldSkipStepPause(topCallFrame);
1500 else 1491 else
1501 result = RequestNoSkip; 1492 result = RequestNoSkip;
1502 1493
1503 m_skipNextDebuggerStepOut = false; 1494 m_skipNextDebuggerStepOut = false;
1504 if (result != RequestNoSkip) 1495 if (result != RequestNoSkip)
1505 return result; 1496 return result;
1506
1507 // Skip pauses inside V8 internal scripts and on syntax errors. 1497 // Skip pauses inside V8 internal scripts and on syntax errors.
1508 if (!callFrames) 1498 if (!topCallFrame)
1509 return RequestContinue; 1499 return RequestContinue;
1510 1500
1511 ASSERT(m_pausedContext.IsEmpty()); 1501 ASSERT(m_pausedContext.IsEmpty());
1502 callFrames = debugger().currentCallFrames();
1503 m_pausedCallFrames.swap(callFrames);
1512 m_pausedContext.Reset(m_isolate, context); 1504 m_pausedContext.Reset(m_isolate, context);
1513 m_currentCallStack = callFrames;
1514 v8::HandleScope handles(m_isolate); 1505 v8::HandleScope handles(m_isolate);
1515 1506
1516 if (!exception.IsEmpty()) { 1507 if (!exception.IsEmpty()) {
1517 InjectedScript* injectedScript = m_injectedScriptManager->injectedScript For(context); 1508 InjectedScript* injectedScript = m_injectedScriptManager->injectedScript For(context);
1518 if (injectedScript) { 1509 if (injectedScript) {
1519 m_breakReason = isPromiseRejection ? protocol::Debugger::Paused::Rea sonEnum::PromiseRejection : protocol::Debugger::Paused::ReasonEnum::Exception; 1510 m_breakReason = isPromiseRejection ? protocol::Debugger::Paused::Rea sonEnum::PromiseRejection : protocol::Debugger::Paused::ReasonEnum::Exception;
1520 ErrorString errorString; 1511 ErrorString errorString;
1521 auto obj = injectedScript->wrapObject(&errorString, exception, V8Deb uggerAgentImpl::backtraceObjectGroup); 1512 auto obj = injectedScript->wrapObject(&errorString, exception, V8Deb uggerAgentImpl::backtraceObjectGroup);
1522 m_breakAuxData = obj ? obj->serialize() : nullptr; 1513 m_breakAuxData = obj ? obj->serialize() : nullptr;
1523 // m_breakAuxData might be null after this. 1514 // m_breakAuxData might be null after this.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 if (!m_continueToLocationBreakpointId.isEmpty()) { 1549 if (!m_continueToLocationBreakpointId.isEmpty()) {
1559 debugger().removeBreakpoint(m_continueToLocationBreakpointId); 1550 debugger().removeBreakpoint(m_continueToLocationBreakpointId);
1560 m_continueToLocationBreakpointId = ""; 1551 m_continueToLocationBreakpointId = "";
1561 } 1552 }
1562 return result; 1553 return result;
1563 } 1554 }
1564 1555
1565 void V8DebuggerAgentImpl::didContinue() 1556 void V8DebuggerAgentImpl::didContinue()
1566 { 1557 {
1567 m_pausedContext.Reset(); 1558 m_pausedContext.Reset();
1568 m_currentCallStack.clear(); 1559 JavaScriptCallFrames emptyCallFrames;
1560 m_pausedCallFrames.swap(emptyCallFrames);
1569 clearBreakDetails(); 1561 clearBreakDetails();
1570 m_frontend->resumed(); 1562 m_frontend->resumed();
1571 } 1563 }
1572 1564
1573 bool V8DebuggerAgentImpl::canBreakProgram() 1565 bool V8DebuggerAgentImpl::canBreakProgram()
1574 { 1566 {
1575 return debugger().canBreakProgram(); 1567 return debugger().canBreakProgram();
1576 } 1568 }
1577 1569
1578 void V8DebuggerAgentImpl::breakProgram(const String16& breakReason, PassOwnPtr<p rotocol::DictionaryValue> data) 1570 void V8DebuggerAgentImpl::breakProgram(const String16& breakReason, PassOwnPtr<p rotocol::DictionaryValue> data)
1579 { 1571 {
1580 ASSERT(enabled()); 1572 ASSERT(enabled());
1581 if (m_skipAllPauses || !m_pausedContext.IsEmpty() || isCallStackEmptyOrBlack boxed() || !debugger().breakpointsActivated()) 1573 if (m_skipAllPauses || !m_pausedContext.IsEmpty() || isCurrentCallStackEmpty OrBlackboxed() || !debugger().breakpointsActivated())
1582 return; 1574 return;
1583 m_breakReason = breakReason; 1575 m_breakReason = breakReason;
1584 m_breakAuxData = data; 1576 m_breakAuxData = data;
1585 m_scheduledDebuggerStep = NoStep; 1577 m_scheduledDebuggerStep = NoStep;
1586 m_steppingFromFramework = false; 1578 m_steppingFromFramework = false;
1587 m_pausingOnNativeEvent = false; 1579 m_pausingOnNativeEvent = false;
1588 clearStepIntoAsync(); 1580 clearStepIntoAsync();
1589 debugger().breakProgram(); 1581 debugger().breakProgram();
1590 } 1582 }
1591 1583
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 if (!enabled()) 1627 if (!enabled())
1636 return; 1628 return;
1637 m_scheduledDebuggerStep = NoStep; 1629 m_scheduledDebuggerStep = NoStep;
1638 m_scripts.clear(); 1630 m_scripts.clear();
1639 m_blackboxedPositions.clear(); 1631 m_blackboxedPositions.clear();
1640 m_breakpointIdToDebuggerBreakpointIds.clear(); 1632 m_breakpointIdToDebuggerBreakpointIds.clear();
1641 resetAsyncCallTracker(); 1633 resetAsyncCallTracker();
1642 } 1634 }
1643 1635
1644 } // namespace blink 1636 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698