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

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

Issue 1826623002: [DevTools] Move wrapCallFrames from InjectedScriptSource.js to native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-no-scopes
Patch Set: Created 4 years, 9 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"
11 #include "platform/v8_inspector/InjectedScriptHost.h" 11 #include "platform/v8_inspector/InjectedScriptHost.h"
12 #include "platform/v8_inspector/InjectedScriptManager.h" 12 #include "platform/v8_inspector/InjectedScriptManager.h"
13 #include "platform/v8_inspector/JavaScriptCallFrame.h" 13 #include "platform/v8_inspector/JavaScriptCallFrame.h"
14 #include "platform/v8_inspector/PromiseTracker.h" 14 #include "platform/v8_inspector/PromiseTracker.h"
15 #include "platform/v8_inspector/RemoteObjectId.h" 15 #include "platform/v8_inspector/RemoteObjectId.h"
16 #include "platform/v8_inspector/V8AsyncCallTracker.h" 16 #include "platform/v8_inspector/V8AsyncCallTracker.h"
17 #include "platform/v8_inspector/V8JavaScriptCallFrame.h"
18 #include "platform/v8_inspector/V8Regex.h" 17 #include "platform/v8_inspector/V8Regex.h"
19 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" 18 #include "platform/v8_inspector/V8RuntimeAgentImpl.h"
20 #include "platform/v8_inspector/V8StackTraceImpl.h" 19 #include "platform/v8_inspector/V8StackTraceImpl.h"
21 #include "platform/v8_inspector/V8StringUtil.h" 20 #include "platform/v8_inspector/V8StringUtil.h"
22 #include "platform/v8_inspector/public/V8ContentSearchUtil.h" 21 #include "platform/v8_inspector/public/V8ContentSearchUtil.h"
23 #include "platform/v8_inspector/public/V8Debugger.h" 22 #include "platform/v8_inspector/public/V8Debugger.h"
24 #include "platform/v8_inspector/public/V8DebuggerClient.h" 23 #include "platform/v8_inspector/public/V8DebuggerClient.h"
25 #include "platform/v8_inspector/public/V8ToProtocolValue.h" 24 #include "platform/v8_inspector/public/V8ToProtocolValue.h"
26 25
27 using blink::protocol::Array; 26 using blink::protocol::Array;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return hash.toString(); 142 return hash.toString();
144 } 143 }
145 144
146 static bool hasInternalError(ErrorString* errorString, bool hasError) 145 static bool hasInternalError(ErrorString* errorString, bool hasError)
147 { 146 {
148 if (hasError) 147 if (hasError)
149 *errorString = "Internal error"; 148 *errorString = "Internal error";
150 return hasError; 149 return hasError;
151 } 150 }
152 151
152 static PassOwnPtr<protocol::Debugger::Location> buildProtocolLocation(const Stri ng16& scriptId, int lineNumber, int columnNumber)
153 {
154 return protocol::Debugger::Location::create()
155 .setScriptId(scriptId)
156 .setLineNumber(lineNumber)
157 .setColumnNumber(columnNumber).build();
158 }
159
153 PassOwnPtr<V8DebuggerAgent> V8DebuggerAgent::create(V8RuntimeAgent* runtimeAgent ) 160 PassOwnPtr<V8DebuggerAgent> V8DebuggerAgent::create(V8RuntimeAgent* runtimeAgent )
154 { 161 {
155 V8RuntimeAgentImpl* runtimeAgentImpl = static_cast<V8RuntimeAgentImpl*>(runt imeAgent); 162 V8RuntimeAgentImpl* runtimeAgentImpl = static_cast<V8RuntimeAgentImpl*>(runt imeAgent);
156 return adoptPtr(new V8DebuggerAgentImpl(runtimeAgentImpl->getInjectedScriptM anager(), runtimeAgentImpl->debugger(), runtimeAgentImpl->contextGroupId())); 163 return adoptPtr(new V8DebuggerAgentImpl(runtimeAgentImpl->getInjectedScriptM anager(), runtimeAgentImpl->debugger(), runtimeAgentImpl->contextGroupId()));
157 } 164 }
158 165
159 V8DebuggerAgentImpl::V8DebuggerAgentImpl(InjectedScriptManager* injectedScriptMa nager, V8DebuggerImpl* debugger, int contextGroupId) 166 V8DebuggerAgentImpl::V8DebuggerAgentImpl(InjectedScriptManager* injectedScriptMa nager, V8DebuggerImpl* debugger, int contextGroupId)
160 : m_injectedScriptManager(injectedScriptManager) 167 : m_injectedScriptManager(injectedScriptManager)
161 , m_debugger(debugger) 168 , m_debugger(debugger)
162 , m_contextGroupId(contextGroupId) 169 , m_contextGroupId(contextGroupId)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 return; 242 return;
236 243
237 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, protocol::Dict ionaryValue::create()); 244 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, protocol::Dict ionaryValue::create());
238 m_state->setNumber(DebuggerAgentState::pauseOnExceptionsState, V8DebuggerImp l::DontPauseOnExceptions); 245 m_state->setNumber(DebuggerAgentState::pauseOnExceptionsState, V8DebuggerImp l::DontPauseOnExceptions);
239 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, 0); 246 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, 0);
240 m_state->setBoolean(DebuggerAgentState::promiseTrackerEnabled, false); 247 m_state->setBoolean(DebuggerAgentState::promiseTrackerEnabled, false);
241 m_state->setBoolean(DebuggerAgentState::promiseTrackerCaptureStacks, false); 248 m_state->setBoolean(DebuggerAgentState::promiseTrackerCaptureStacks, false);
242 249
243 debugger().removeDebuggerAgent(m_contextGroupId); 250 debugger().removeDebuggerAgent(m_contextGroupId);
244 m_pausedContext.Reset(); 251 m_pausedContext.Reset();
245 m_currentCallStack.Reset(); 252 m_currentCallStack.clear();
246 m_scripts.clear(); 253 m_scripts.clear();
247 m_blackboxedPositions.clear(); 254 m_blackboxedPositions.clear();
248 m_breakpointIdToDebuggerBreakpointIds.clear(); 255 m_breakpointIdToDebuggerBreakpointIds.clear();
249 internalSetAsyncCallStackDepth(0); 256 internalSetAsyncCallStackDepth(0);
250 m_promiseTracker->setEnabled(false, false); 257 m_promiseTracker->setEnabled(false, false);
251 m_continueToLocationBreakpointId = String16(); 258 m_continueToLocationBreakpointId = String16();
252 clearBreakDetails(); 259 clearBreakDetails();
253 m_scheduledDebuggerStep = NoStep; 260 m_scheduledDebuggerStep = NoStep;
254 m_skipNextDebuggerStepOut = false; 261 m_skipNextDebuggerStepOut = false;
255 m_javaScriptPauseScheduled = false; 262 m_javaScriptPauseScheduled = false;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 486
480 ScriptBreakpoint breakpoint(lineNumber, columnNumber, ""); 487 ScriptBreakpoint breakpoint(lineNumber, columnNumber, "");
481 m_continueToLocationBreakpointId = debugger().setBreakpoint(scriptId, breakp oint, &lineNumber, &columnNumber, interstateLocationOpt.fromMaybe(false)); 488 m_continueToLocationBreakpointId = debugger().setBreakpoint(scriptId, breakp oint, &lineNumber, &columnNumber, interstateLocationOpt.fromMaybe(false));
482 resume(errorString); 489 resume(errorString);
483 } 490 }
484 491
485 void V8DebuggerAgentImpl::getBacktrace(ErrorString* errorString, OwnPtr<Array<Ca llFrame>>* callFrames, Maybe<StackTrace>* asyncStackTrace) 492 void V8DebuggerAgentImpl::getBacktrace(ErrorString* errorString, OwnPtr<Array<Ca llFrame>>* callFrames, Maybe<StackTrace>* asyncStackTrace)
486 { 493 {
487 if (!assertPaused(errorString)) 494 if (!assertPaused(errorString))
488 return; 495 return;
489 m_currentCallStack.Reset(m_isolate, debugger().currentCallFrames()); 496 m_currentCallStack = debugger().currentCallFrames();
490 *callFrames = currentCallFrames(); 497 *callFrames = currentCallFrames(errorString);
498 if (!*callFrames)
499 return;
491 *asyncStackTrace = currentAsyncStackTrace(); 500 *asyncStackTrace = currentAsyncStackTrace();
492 } 501 }
493 502
494 bool V8DebuggerAgentImpl::isCallStackEmptyOrBlackboxed() 503 bool V8DebuggerAgentImpl::isCallStackEmptyOrBlackboxed()
495 { 504 {
496 ASSERT(enabled()); 505 ASSERT(enabled());
497 for (int index = 0; ; ++index) { 506 for (int index = 0; ; ++index) {
498 OwnPtr<JavaScriptCallFrame> frame = debugger().callFrame(index); 507 OwnPtr<JavaScriptCallFrame> frame = debugger().callFrame(index);
499 if (!frame) 508 if (!frame)
500 break; 509 break;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 return nullptr; 592 return nullptr;
584 593
585 m_serverBreakpoints.set(debuggerBreakpointId, std::make_pair(breakpointId, s ource)); 594 m_serverBreakpoints.set(debuggerBreakpointId, std::make_pair(breakpointId, s ource));
586 RELEASE_ASSERT(!breakpointId.isEmpty()); 595 RELEASE_ASSERT(!breakpointId.isEmpty());
587 if (!m_breakpointIdToDebuggerBreakpointIds.contains(breakpointId)) 596 if (!m_breakpointIdToDebuggerBreakpointIds.contains(breakpointId))
588 m_breakpointIdToDebuggerBreakpointIds.set(breakpointId, protocol::Vector <String16>()); 597 m_breakpointIdToDebuggerBreakpointIds.set(breakpointId, protocol::Vector <String16>());
589 598
590 BreakpointIdToDebuggerBreakpointIdsMap::iterator debuggerBreakpointIdsIterat or = m_breakpointIdToDebuggerBreakpointIds.find(breakpointId); 599 BreakpointIdToDebuggerBreakpointIdsMap::iterator debuggerBreakpointIdsIterat or = m_breakpointIdToDebuggerBreakpointIds.find(breakpointId);
591 debuggerBreakpointIdsIterator->second->append(debuggerBreakpointId); 600 debuggerBreakpointIdsIterator->second->append(debuggerBreakpointId);
592 601
593 OwnPtr<protocol::Debugger::Location> location = protocol::Debugger::Location ::create() 602 return buildProtocolLocation(scriptId, actualLineNumber, actualColumnNumber) ;
594 .setScriptId(scriptId)
595 .setLineNumber(actualLineNumber)
596 .setColumnNumber(actualColumnNumber).build();
597 return location.release();
598 } 603 }
599 604
600 void V8DebuggerAgentImpl::searchInContent(ErrorString* error, const String16& sc riptId, const String16& query, 605 void V8DebuggerAgentImpl::searchInContent(ErrorString* error, const String16& sc riptId, const String16& query,
601 const Maybe<bool>& optionalCaseSensitive, 606 const Maybe<bool>& optionalCaseSensitive,
602 const Maybe<bool>& optionalIsRegex, 607 const Maybe<bool>& optionalIsRegex,
603 OwnPtr<Array<protocol::Debugger::SearchMatch>>* results) 608 OwnPtr<Array<protocol::Debugger::SearchMatch>>* results)
604 { 609 {
605 ScriptsMap::iterator it = m_scripts.find(scriptId); 610 ScriptsMap::iterator it = m_scripts.find(scriptId);
606 if (it != m_scripts.end()) 611 if (it != m_scripts.end())
607 *results = V8ContentSearchUtil::searchInTextByLines(m_debugger, it->seco nd->source(), query, optionalCaseSensitive.fromMaybe(false), optionalIsRegex.fro mMaybe(false)); 612 *results = V8ContentSearchUtil::searchInTextByLines(m_debugger, it->seco nd->source(), query, optionalCaseSensitive.fromMaybe(false), optionalIsRegex.fro mMaybe(false));
608 else 613 else
609 *error = String16("No script for id: " + scriptId); 614 *error = String16("No script for id: " + scriptId);
610 } 615 }
611 616
612 void V8DebuggerAgentImpl::setScriptSource(ErrorString* error, 617 void V8DebuggerAgentImpl::setScriptSource(ErrorString* errorString,
613 const String16& scriptId, 618 const String16& scriptId,
614 const String16& newContent, 619 const String16& newContent,
615 const Maybe<bool>& preview, 620 const Maybe<bool>& preview,
616 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* newCallFrames, 621 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* newCallFrames,
617 Maybe<bool>* stackChanged, 622 Maybe<bool>* stackChanged,
618 Maybe<StackTrace>* asyncStackTrace, 623 Maybe<StackTrace>* asyncStackTrace,
619 Maybe<protocol::Debugger::SetScriptSourceError>* optOutCompileError) 624 Maybe<protocol::Debugger::SetScriptSourceError>* optOutCompileError)
620 { 625 {
621 if (!checkEnabled(error)) 626 if (!checkEnabled(errorString))
622 return; 627 return;
623 if (!debugger().setScriptSource(scriptId, newContent, preview.fromMaybe(fals e), error, optOutCompileError, &m_currentCallStack, stackChanged)) 628 if (!debugger().setScriptSource(scriptId, newContent, preview.fromMaybe(fals e), errorString, optOutCompileError, &m_currentCallStack, stackChanged))
624 return; 629 return;
625 630
626 *newCallFrames = currentCallFrames(); 631 OwnPtr<Array<CallFrame>> callFrames = currentCallFrames(errorString);
632 if (!callFrames)
633 return;
634 *newCallFrames = callFrames.release();
627 *asyncStackTrace = currentAsyncStackTrace(); 635 *asyncStackTrace = currentAsyncStackTrace();
628 636
629 ScriptsMap::iterator it = m_scripts.find(scriptId); 637 ScriptsMap::iterator it = m_scripts.find(scriptId);
630 if (it == m_scripts.end()) 638 if (it == m_scripts.end())
631 return; 639 return;
632 it->second->setSource(newContent); 640 it->second->setSource(newContent);
633 } 641 }
634 642
635 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString, 643 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString,
636 const String16& callFrameId, 644 const String16& callFrameId,
637 OwnPtr<Array<CallFrame>>* newCallFrames, 645 OwnPtr<Array<CallFrame>>* newCallFrames,
638 Maybe<StackTrace>* asyncStackTrace) 646 Maybe<StackTrace>* asyncStackTrace)
639 { 647 {
640 if (!isPaused() || m_currentCallStack.IsEmpty()) { 648 if (!isPaused() || !m_currentCallStack) {
641 *errorString = "Attempt to access call frame when debugger is not on pau se"; 649 *errorString = "Attempt to access call frame when debugger is not on pau se";
642 return; 650 return;
643 } 651 }
644 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 652 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
645 if (!remoteId) 653 if (!remoteId)
646 return; 654 return;
647 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 655 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
648 if (!injectedScript) 656 if (!injectedScript)
649 return; 657 return;
650 658
651 v8::HandleScope scope(m_isolate); 659 v8::HandleScope scope(m_isolate);
652 v8::Local<v8::Context> localContext = injectedScript->context(); 660 v8::Local<v8::Context> localContext = injectedScript->context();
653 661
654 v8::TryCatch tryCatch(m_isolate); 662 v8::TryCatch tryCatch(m_isolate);
655 663
656 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrame(remot eId->frameOrdinal()); 664 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrame(remot eId->frameOrdinal());
657 if (!javaScriptCallFrame) { 665 if (!javaScriptCallFrame) {
658 *errorString = "Could not find call frame with given id"; 666 *errorString = "Could not find call frame with given id";
659 return; 667 return;
660 } 668 }
661 v8::Local<v8::Value> resultValue; 669 v8::Local<v8::Value> resultValue;
662 v8::Local<v8::Boolean> result; 670 v8::Local<v8::Boolean> result;
663 if (!javaScriptCallFrame->restart().ToLocal(&resultValue) || tryCatch.HasCau ght() || !resultValue->ToBoolean(localContext).ToLocal(&result) || !result->Valu e()) { 671 if (!javaScriptCallFrame->restart().ToLocal(&resultValue) || tryCatch.HasCau ght() || !resultValue->ToBoolean(localContext).ToLocal(&result) || !result->Valu e()) {
664 *errorString = "Internal error"; 672 *errorString = "Internal error";
665 return; 673 return;
666 } 674 }
667 675
668 m_currentCallStack.Reset(m_isolate, debugger().currentCallFrames()); 676 m_currentCallStack = debugger().currentCallFrames();
669 677
670 *newCallFrames = currentCallFrames(); 678 *newCallFrames = currentCallFrames(errorString);
679 if (!*newCallFrames)
680 return;
671 *asyncStackTrace = currentAsyncStackTrace(); 681 *asyncStackTrace = currentAsyncStackTrace();
672 } 682 }
673 683
674 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource) 684 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource)
675 { 685 {
676 if (!checkEnabled(error)) 686 if (!checkEnabled(error))
677 return; 687 return;
678 ScriptsMap::iterator it = m_scripts.find(scriptId); 688 ScriptsMap::iterator it = m_scripts.find(scriptId);
679 if (it == m_scripts.end()) { 689 if (it == m_scripts.end()) {
680 *error = "No script for id: " + scriptId; 690 *error = "No script for id: " + scriptId;
(...skipping 28 matching lines...) Expand all
709 719
710 v8::Local<v8::Value> scopesValue; 720 v8::Local<v8::Value> scopesValue;
711 v8::Local<v8::Array> scopes; 721 v8::Local<v8::Array> scopes;
712 String16 groupName = injectedScript->objectGroupName(*remoteId); 722 String16 groupName = injectedScript->objectGroupName(*remoteId);
713 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu e->IsArray()) { 723 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu e->IsArray()) {
714 scopes = scopesValue.As<v8::Array>(); 724 scopes = scopesValue.As<v8::Array>();
715 if (!injectedScript->wrapPropertyInArray(errorString, scopes, toV8String Internalized(injectedScript->isolate(), "object"), groupName)) 725 if (!injectedScript->wrapPropertyInArray(errorString, scopes, toV8String Internalized(injectedScript->isolate(), "object"), groupName))
716 return; 726 return;
717 } 727 }
718 728
719 OwnPtr<protocol::Debugger::Location> location = protocol::Debugger::Location ::create()
720 .setScriptId(String16::number(function->ScriptId()))
721 .setLineNumber(function->GetScriptLineNumber())
722 .setColumnNumber(function->GetScriptColumnNumber()).build();
723
724 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create() 729 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create()
725 .setLocation(location.release()) 730 .setLocation(buildProtocolLocation(String16::number(function->ScriptId() ), function->GetScriptLineNumber(), function->GetScriptColumnNumber()))
726 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName()) ) 731 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName()) )
727 .setIsGenerator(function->IsGeneratorFunction()).build(); 732 .setIsGenerator(function->IsGeneratorFunction()).build();
728 733
729 if (!scopes.IsEmpty()) { 734 if (!scopes.IsEmpty()) {
730 protocol::ErrorSupport errorSupport; 735 protocol::ErrorSupport errorSupport;
731 OwnPtr<protocol::Array<protocol::Debugger::Scope>> scopeChain = protocol ::Array<protocol::Debugger::Scope>::parse(toProtocolValue(injectedScript->contex t(), scopes).get(), &errorSupport); 736 OwnPtr<protocol::Array<protocol::Debugger::Scope>> scopeChain = protocol ::Array<protocol::Debugger::Scope>::parse(toProtocolValue(injectedScript->contex t(), scopes).get(), &errorSupport);
732 if (hasInternalError(errorString, errorSupport.hasErrors())) 737 if (hasInternalError(errorString, errorSupport.hasErrors()))
733 return; 738 return;
734 functionDetails->setScopeChain(scopeChain.release()); 739 functionDetails->setScopeChain(scopeChain.release());
735 } 740 }
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 const String16& expression, 990 const String16& expression,
986 const Maybe<String16>& objectGroup, 991 const Maybe<String16>& objectGroup,
987 const Maybe<bool>& includeCommandLineAPI, 992 const Maybe<bool>& includeCommandLineAPI,
988 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 993 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
989 const Maybe<bool>& returnByValue, 994 const Maybe<bool>& returnByValue,
990 const Maybe<bool>& generatePreview, 995 const Maybe<bool>& generatePreview,
991 OwnPtr<RemoteObject>* result, 996 OwnPtr<RemoteObject>* result,
992 Maybe<bool>* wasThrown, 997 Maybe<bool>* wasThrown,
993 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) 998 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails)
994 { 999 {
995 if (!isPaused() || m_currentCallStack.IsEmpty()) { 1000 if (!isPaused() || !m_currentCallStack) {
996 *errorString = "Attempt to access callframe when debugger is not on paus e"; 1001 *errorString = "Attempt to access callframe when debugger is not on paus e";
997 return; 1002 return;
998 } 1003 }
999 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 1004 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
1000 if (!remoteId) 1005 if (!remoteId)
1001 return; 1006 return;
1002 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 1007 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
1003 if (!injectedScript) 1008 if (!injectedScript)
1004 return; 1009 return;
1005 1010
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 } 1048 }
1044 1049
1045 void V8DebuggerAgentImpl::setVariableValue(ErrorString* errorString, 1050 void V8DebuggerAgentImpl::setVariableValue(ErrorString* errorString,
1046 int scopeNumber, 1051 int scopeNumber,
1047 const String16& variableName, 1052 const String16& variableName,
1048 PassOwnPtr<protocol::Runtime::CallArgument> newValueArgument, 1053 PassOwnPtr<protocol::Runtime::CallArgument> newValueArgument,
1049 const String16& callFrameId) 1054 const String16& callFrameId)
1050 { 1055 {
1051 if (!checkEnabled(errorString)) 1056 if (!checkEnabled(errorString))
1052 return; 1057 return;
1053 if (!isPaused() || m_currentCallStack.IsEmpty()) { 1058 if (!isPaused() || !m_currentCallStack) {
1054 *errorString = "Attempt to access callframe when debugger is not on paus e"; 1059 *errorString = "Attempt to access callframe when debugger is not on paus e";
1055 return; 1060 return;
1056 } 1061 }
1057 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 1062 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
1058 if (!remoteId) 1063 if (!remoteId)
1059 return; 1064 return;
1060 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 1065 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
1061 if (!injectedScript) 1066 if (!injectedScript)
1062 return; 1067 return;
1063 1068
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 // from the old StepFrame. 1404 // from the old StepFrame.
1400 m_skippedStepFrameCount = 0; 1405 m_skippedStepFrameCount = 0;
1401 if (m_scheduledDebuggerStep == NoStep) 1406 if (m_scheduledDebuggerStep == NoStep)
1402 debugger().clearStepping(); 1407 debugger().clearStepping();
1403 else if (m_scheduledDebuggerStep == StepOut) 1408 else if (m_scheduledDebuggerStep == StepOut)
1404 m_skipNextDebuggerStepOut = true; 1409 m_skipNextDebuggerStepOut = true;
1405 } 1410 }
1406 } 1411 }
1407 } 1412 }
1408 1413
1409 PassOwnPtr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames() 1414 PassOwnPtr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames(ErrorString* errorString)
1410 { 1415 {
1411 if (m_pausedContext.IsEmpty() || m_currentCallStack.IsEmpty()) 1416 if (m_pausedContext.IsEmpty() || !m_currentCallStack)
1412 return Array<CallFrame>::create(); 1417 return Array<CallFrame>::create();
1413 v8::HandleScope handles(m_isolate);
1414 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( m_pausedContext.Get(m_isolate)); 1418 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( m_pausedContext.Get(m_isolate));
1415 if (!injectedScript) { 1419 if (!injectedScript) {
1416 // Context has been reported as removed while on pause. 1420 // Context has been reported as removed while on pause.
1417 return Array<CallFrame>::create(); 1421 return Array<CallFrame>::create();
1418 } 1422 }
1419 1423
1420 v8::Local<v8::Object> currentCallStack = m_currentCallStack.Get(m_isolate); 1424 v8::Isolate* isolate = injectedScript->isolate();
1421 return injectedScript->wrapCallFrames(currentCallStack); 1425 v8::HandleScope handles(isolate);
1426 v8::Local<v8::Context> context = injectedScript->context();
1427 v8::Context::Scope contextScope(context);
1428
1429 JavaScriptCallFrame* currentCallFrame = m_currentCallStack.get();
1430 int callFrameIndex = 0;
1431 OwnPtr<JavaScriptCallFrame> currentCallFrameOwner;
1432 v8::Local<v8::Array> objects = v8::Array::New(isolate);
1433 while (currentCallFrame) {
1434 v8::Local<v8::Object> details = currentCallFrame->details();
1435 if (hasInternalError(errorString, details.IsEmpty()))
1436 return Array<CallFrame>::create();
1437
1438 String16 callFrameId = RemoteCallFrameId::serialize(injectedScript->cont extId(), callFrameIndex);
1439 if (hasInternalError(errorString, !details->Set(context, toV8StringInter nalized(isolate, "callFrameId"), toV8String(isolate, callFrameId)).FromMaybe(fal se)))
1440 return Array<CallFrame>::create();
1441
1442 v8::Local<v8::Value> scopeChain;
1443 if (hasInternalError(errorString, !details->Get(context, toV8StringInter nalized(isolate, "scopeChain")).ToLocal(&scopeChain) || !scopeChain->IsArray()))
1444 return Array<CallFrame>::create();
1445 v8::Local<v8::Array> scopeChainArray = scopeChain.As<v8::Array>();
1446 if (!injectedScript->wrapPropertyInArray(errorString, scopeChainArray, t oV8StringInternalized(isolate, "object"), V8DebuggerAgentImpl::backtraceObjectGr oup))
1447 return Array<CallFrame>::create();
1448
1449 if (!injectedScript->wrapObjectProperty(errorString, details, toV8String Internalized(isolate, "this"), V8DebuggerAgentImpl::backtraceObjectGroup))
1450 return Array<CallFrame>::create();
1451
1452 if (details->Has(context, toV8StringInternalized(isolate, "returnValue") ).FromMaybe(false)) {
1453 if (!injectedScript->wrapObjectProperty(errorString, details, toV8St ringInternalized(isolate, "returnValue"), V8DebuggerAgentImpl::backtraceObjectGr oup))
1454 return Array<CallFrame>::create();
1455 }
1456
1457 if (hasInternalError(errorString, !objects->Set(context, callFrameIndex, details).FromMaybe(false)))
1458 return Array<CallFrame>::create();
1459
1460 currentCallFrameOwner = currentCallFrame->caller();
1461 currentCallFrame = currentCallFrameOwner.get();
1462 ++callFrameIndex;
1463 }
1464
1465 protocol::ErrorSupport errorSupport;
1466 OwnPtr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(toProtocolValu e(context, objects).get(), &errorSupport);
1467 if (hasInternalError(errorString, !callFrames))
1468 return Array<CallFrame>::create();
1469 return callFrames.release();
1422 } 1470 }
1423 1471
1424 PassOwnPtr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace() 1472 PassOwnPtr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace()
1425 { 1473 {
1426 if (m_pausedContext.IsEmpty() || !trackingAsyncCalls() || !m_currentAsyncCal lChain) 1474 if (m_pausedContext.IsEmpty() || !trackingAsyncCalls() || !m_currentAsyncCal lChain)
1427 return nullptr; 1475 return nullptr;
1428 1476
1429 return m_currentAsyncCallChain->buildInspectorObjectForTail(this); 1477 return m_currentAsyncCallChain->buildInspectorObjectForTail(this);
1430 } 1478 }
1431 1479
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 ScriptBreakpoint breakpoint; 1541 ScriptBreakpoint breakpoint;
1494 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber); 1542 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber);
1495 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber); 1543 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber);
1496 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition); 1544 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition);
1497 OwnPtr<protocol::Debugger::Location> location = resolveBreakpoint(cookie .first, parsedScript.scriptId, breakpoint, UserBreakpointSource); 1545 OwnPtr<protocol::Debugger::Location> location = resolveBreakpoint(cookie .first, parsedScript.scriptId, breakpoint, UserBreakpointSource);
1498 if (location) 1546 if (location)
1499 m_frontend->breakpointResolved(cookie.first, location.release()); 1547 m_frontend->breakpointResolved(cookie.first, location.release());
1500 } 1548 }
1501 } 1549 }
1502 1550
1503 V8DebuggerAgentImpl::SkipPauseRequest V8DebuggerAgentImpl::didPause(v8::Local<v8 ::Context> context, v8::Local<v8::Object> callFrames, v8::Local<v8::Value> excep tion, const protocol::Vector<String16>& hitBreakpoints, bool isPromiseRejection) 1551 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)
1504 { 1552 {
1505 V8DebuggerAgentImpl::SkipPauseRequest result; 1553 V8DebuggerAgentImpl::SkipPauseRequest result;
1506 if (m_skipAllPauses) 1554 if (m_skipAllPauses)
1507 result = RequestContinue; 1555 result = RequestContinue;
1508 else if (!hitBreakpoints.isEmpty()) 1556 else if (!hitBreakpoints.isEmpty())
1509 result = RequestNoSkip; // Don't skip explicit breakpoints even if set i n frameworks. 1557 result = RequestNoSkip; // Don't skip explicit breakpoints even if set i n frameworks.
1510 else if (!exception.IsEmpty()) 1558 else if (!exception.IsEmpty())
1511 result = shouldSkipExceptionPause(); 1559 result = shouldSkipExceptionPause();
1512 else if (m_scheduledDebuggerStep != NoStep || m_javaScriptPauseScheduled || m_pausingOnNativeEvent) 1560 else if (m_scheduledDebuggerStep != NoStep || m_javaScriptPauseScheduled || m_pausingOnNativeEvent)
1513 result = shouldSkipStepPause(); 1561 result = shouldSkipStepPause();
1514 else 1562 else
1515 result = RequestNoSkip; 1563 result = RequestNoSkip;
1516 1564
1517 m_skipNextDebuggerStepOut = false; 1565 m_skipNextDebuggerStepOut = false;
1518 if (result != RequestNoSkip) 1566 if (result != RequestNoSkip)
1519 return result; 1567 return result;
1520 1568
1521 // Skip pauses inside V8 internal scripts and on syntax errors. 1569 // Skip pauses inside V8 internal scripts and on syntax errors.
1522 if (callFrames.IsEmpty()) 1570 if (!callFrames)
1523 return RequestContinue; 1571 return RequestContinue;
1524 1572
1525 ASSERT(m_pausedContext.IsEmpty()); 1573 ASSERT(m_pausedContext.IsEmpty());
1526 m_pausedContext.Reset(m_isolate, context); 1574 m_pausedContext.Reset(m_isolate, context);
1527 m_currentCallStack.Reset(m_isolate, callFrames); 1575 m_currentCallStack = callFrames;
1528 v8::HandleScope handles(m_isolate); 1576 v8::HandleScope handles(m_isolate);
1529 1577
1530 if (!exception.IsEmpty()) { 1578 if (!exception.IsEmpty()) {
1531 InjectedScript* injectedScript = m_injectedScriptManager->injectedScript For(context); 1579 InjectedScript* injectedScript = m_injectedScriptManager->injectedScript For(context);
1532 if (injectedScript) { 1580 if (injectedScript) {
1533 m_breakReason = isPromiseRejection ? protocol::Debugger::Paused::Rea sonEnum::PromiseRejection : protocol::Debugger::Paused::ReasonEnum::Exception; 1581 m_breakReason = isPromiseRejection ? protocol::Debugger::Paused::Rea sonEnum::PromiseRejection : protocol::Debugger::Paused::ReasonEnum::Exception;
1534 ErrorString errorString; 1582 ErrorString errorString;
1535 auto obj = injectedScript->wrapObject(&errorString, exception, V8Deb uggerAgentImpl::backtraceObjectGroup); 1583 auto obj = injectedScript->wrapObject(&errorString, exception, V8Deb uggerAgentImpl::backtraceObjectGroup);
1536 m_breakAuxData = obj ? obj->serialize() : nullptr; 1584 m_breakAuxData = obj ? obj->serialize() : nullptr;
1537 // m_breakAuxData might be null after this. 1585 // m_breakAuxData might be null after this.
(...skipping 14 matching lines...) Expand all
1552 1600
1553 BreakpointSource source = breakpointIterator->second->second; 1601 BreakpointSource source = breakpointIterator->second->second;
1554 if (m_breakReason == protocol::Debugger::Paused::ReasonEnum::Other & & source == DebugCommandBreakpointSource) 1602 if (m_breakReason == protocol::Debugger::Paused::ReasonEnum::Other & & source == DebugCommandBreakpointSource)
1555 m_breakReason = protocol::Debugger::Paused::ReasonEnum::DebugCom mand; 1603 m_breakReason = protocol::Debugger::Paused::ReasonEnum::DebugCom mand;
1556 } 1604 }
1557 } 1605 }
1558 1606
1559 if (!m_asyncOperationNotifications.isEmpty()) 1607 if (!m_asyncOperationNotifications.isEmpty())
1560 flushAsyncOperationEvents(nullptr); 1608 flushAsyncOperationEvents(nullptr);
1561 1609
1562 m_frontend->paused(currentCallFrames(), m_breakReason, m_breakAuxData.releas e(), hitBreakpointIds.release(), currentAsyncStackTrace()); 1610 ErrorString errorString;
1611 m_frontend->paused(currentCallFrames(&errorString), m_breakReason, m_breakAu xData.release(), hitBreakpointIds.release(), currentAsyncStackTrace());
1563 m_scheduledDebuggerStep = NoStep; 1612 m_scheduledDebuggerStep = NoStep;
1564 m_javaScriptPauseScheduled = false; 1613 m_javaScriptPauseScheduled = false;
1565 m_steppingFromFramework = false; 1614 m_steppingFromFramework = false;
1566 m_pausingOnNativeEvent = false; 1615 m_pausingOnNativeEvent = false;
1567 m_skippedStepFrameCount = 0; 1616 m_skippedStepFrameCount = 0;
1568 m_recursionLevelForStepFrame = 0; 1617 m_recursionLevelForStepFrame = 0;
1569 clearStepIntoAsync(); 1618 clearStepIntoAsync();
1570 1619
1571 if (!m_continueToLocationBreakpointId.isEmpty()) { 1620 if (!m_continueToLocationBreakpointId.isEmpty()) {
1572 debugger().removeBreakpoint(m_continueToLocationBreakpointId); 1621 debugger().removeBreakpoint(m_continueToLocationBreakpointId);
1573 m_continueToLocationBreakpointId = ""; 1622 m_continueToLocationBreakpointId = "";
1574 } 1623 }
1575 return result; 1624 return result;
1576 } 1625 }
1577 1626
1578 void V8DebuggerAgentImpl::didContinue() 1627 void V8DebuggerAgentImpl::didContinue()
1579 { 1628 {
1580 m_pausedContext.Reset(); 1629 m_pausedContext.Reset();
1581 m_currentCallStack.Reset(); 1630 m_currentCallStack.clear();
1582 clearBreakDetails(); 1631 clearBreakDetails();
1583 m_frontend->resumed(); 1632 m_frontend->resumed();
1584 } 1633 }
1585 1634
1586 bool V8DebuggerAgentImpl::canBreakProgram() 1635 bool V8DebuggerAgentImpl::canBreakProgram()
1587 { 1636 {
1588 return debugger().canBreakProgram(); 1637 return debugger().canBreakProgram();
1589 } 1638 }
1590 1639
1591 void V8DebuggerAgentImpl::breakProgram(const String16& breakReason, PassOwnPtr<p rotocol::DictionaryValue> data) 1640 void V8DebuggerAgentImpl::breakProgram(const String16& breakReason, PassOwnPtr<p rotocol::DictionaryValue> data)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 return; 1698 return;
1650 m_scheduledDebuggerStep = NoStep; 1699 m_scheduledDebuggerStep = NoStep;
1651 m_scripts.clear(); 1700 m_scripts.clear();
1652 m_blackboxedPositions.clear(); 1701 m_blackboxedPositions.clear();
1653 m_breakpointIdToDebuggerBreakpointIds.clear(); 1702 m_breakpointIdToDebuggerBreakpointIds.clear();
1654 resetAsyncCallTracker(); 1703 resetAsyncCallTracker();
1655 m_promiseTracker->clear(); 1704 m_promiseTracker->clear();
1656 } 1705 }
1657 1706
1658 } // namespace blink 1707 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698