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

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 *newCallFrames = currentCallFrames(errorString);
632 if (!errorString->isEmpty())
dgozman 2016/03/23 18:46:31 Let's check the result value instead.
kozy 2016/03/23 19:15:10 Done.
633 return;
627 *asyncStackTrace = currentAsyncStackTrace(); 634 *asyncStackTrace = currentAsyncStackTrace();
628 635
629 ScriptsMap::iterator it = m_scripts.find(scriptId); 636 ScriptsMap::iterator it = m_scripts.find(scriptId);
630 if (it == m_scripts.end()) 637 if (it == m_scripts.end())
631 return; 638 return;
632 it->second->setSource(newContent); 639 it->second->setSource(newContent);
633 } 640 }
634 641
635 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString, 642 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString,
636 const String16& callFrameId, 643 const String16& callFrameId,
637 OwnPtr<Array<CallFrame>>* newCallFrames, 644 OwnPtr<Array<CallFrame>>* newCallFrames,
638 Maybe<StackTrace>* asyncStackTrace) 645 Maybe<StackTrace>* asyncStackTrace)
639 { 646 {
640 if (!isPaused() || m_currentCallStack.IsEmpty()) { 647 if (!isPaused() || !m_currentCallStack) {
641 *errorString = "Attempt to access call frame when debugger is not on pau se"; 648 *errorString = "Attempt to access call frame when debugger is not on pau se";
642 return; 649 return;
643 } 650 }
644 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 651 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
645 if (!remoteId) 652 if (!remoteId)
646 return; 653 return;
647 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 654 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
648 if (!injectedScript) 655 if (!injectedScript)
649 return; 656 return;
650 657
651 v8::HandleScope scope(m_isolate); 658 v8::HandleScope scope(m_isolate);
652 v8::Local<v8::Context> localContext = injectedScript->context(); 659 v8::Local<v8::Context> localContext = injectedScript->context();
653 660
654 v8::TryCatch tryCatch(m_isolate); 661 v8::TryCatch tryCatch(m_isolate);
655 662
656 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrame(remot eId->frameOrdinal()); 663 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrame(remot eId->frameOrdinal());
657 if (!javaScriptCallFrame) { 664 if (!javaScriptCallFrame) {
658 *errorString = "Could not find call frame with given id"; 665 *errorString = "Could not find call frame with given id";
659 return; 666 return;
660 } 667 }
661 v8::Local<v8::Value> resultValue; 668 v8::Local<v8::Value> resultValue;
662 v8::Local<v8::Boolean> result; 669 v8::Local<v8::Boolean> result;
663 if (!javaScriptCallFrame->restart().ToLocal(&resultValue) || tryCatch.HasCau ght() || !resultValue->ToBoolean(localContext).ToLocal(&result) || !result->Valu e()) { 670 if (!javaScriptCallFrame->restart().ToLocal(&resultValue) || tryCatch.HasCau ght() || !resultValue->ToBoolean(localContext).ToLocal(&result) || !result->Valu e()) {
664 *errorString = "Internal error"; 671 *errorString = "Internal error";
665 return; 672 return;
666 } 673 }
667 674
668 m_currentCallStack.Reset(m_isolate, debugger().currentCallFrames()); 675 m_currentCallStack = debugger().currentCallFrames();
669 676
670 *newCallFrames = currentCallFrames(); 677 *newCallFrames = currentCallFrames(errorString);
678 if (!*newCallFrames)
679 return;
671 *asyncStackTrace = currentAsyncStackTrace(); 680 *asyncStackTrace = currentAsyncStackTrace();
672 } 681 }
673 682
674 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource) 683 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource)
675 { 684 {
676 if (!checkEnabled(error)) 685 if (!checkEnabled(error))
677 return; 686 return;
678 ScriptsMap::iterator it = m_scripts.find(scriptId); 687 ScriptsMap::iterator it = m_scripts.find(scriptId);
679 if (it == m_scripts.end()) { 688 if (it == m_scripts.end()) {
680 *error = "No script for id: " + scriptId; 689 *error = "No script for id: " + scriptId;
(...skipping 28 matching lines...) Expand all
709 718
710 v8::Local<v8::Value> scopesValue; 719 v8::Local<v8::Value> scopesValue;
711 v8::Local<v8::Array> scopes; 720 v8::Local<v8::Array> scopes;
712 String16 groupName = injectedScript->objectGroupName(*remoteId); 721 String16 groupName = injectedScript->objectGroupName(*remoteId);
713 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu e->IsArray()) { 722 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu e->IsArray()) {
714 scopes = scopesValue.As<v8::Array>(); 723 scopes = scopesValue.As<v8::Array>();
715 if (!injectedScript->wrapPropertyInArray(errorString, scopes, toV8String Internalized(injectedScript->isolate(), "object"), groupName)) 724 if (!injectedScript->wrapPropertyInArray(errorString, scopes, toV8String Internalized(injectedScript->isolate(), "object"), groupName))
716 return; 725 return;
717 } 726 }
718 727
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() 728 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create()
725 .setLocation(location.release()) 729 .setLocation(buildProtocolLocation(String16::number(function->ScriptId() ), function->GetScriptLineNumber(), function->GetScriptColumnNumber()))
726 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName()) ) 730 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName()) )
727 .setIsGenerator(function->IsGeneratorFunction()).build(); 731 .setIsGenerator(function->IsGeneratorFunction()).build();
728 732
729 if (!scopes.IsEmpty()) { 733 if (!scopes.IsEmpty()) {
730 protocol::ErrorSupport errorSupport; 734 protocol::ErrorSupport errorSupport;
731 OwnPtr<protocol::Array<protocol::Debugger::Scope>> scopeChain = protocol ::Array<protocol::Debugger::Scope>::parse(toProtocolValue(injectedScript->contex t(), scopes).get(), &errorSupport); 735 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())) 736 if (hasInternalError(errorString, errorSupport.hasErrors()))
733 return; 737 return;
734 functionDetails->setScopeChain(scopeChain.release()); 738 functionDetails->setScopeChain(scopeChain.release());
735 } 739 }
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 const String16& expression, 989 const String16& expression,
986 const Maybe<String16>& objectGroup, 990 const Maybe<String16>& objectGroup,
987 const Maybe<bool>& includeCommandLineAPI, 991 const Maybe<bool>& includeCommandLineAPI,
988 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 992 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
989 const Maybe<bool>& returnByValue, 993 const Maybe<bool>& returnByValue,
990 const Maybe<bool>& generatePreview, 994 const Maybe<bool>& generatePreview,
991 OwnPtr<RemoteObject>* result, 995 OwnPtr<RemoteObject>* result,
992 Maybe<bool>* wasThrown, 996 Maybe<bool>* wasThrown,
993 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) 997 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails)
994 { 998 {
995 if (!isPaused() || m_currentCallStack.IsEmpty()) { 999 if (!isPaused() || !m_currentCallStack) {
996 *errorString = "Attempt to access callframe when debugger is not on paus e"; 1000 *errorString = "Attempt to access callframe when debugger is not on paus e";
997 return; 1001 return;
998 } 1002 }
999 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 1003 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
1000 if (!remoteId) 1004 if (!remoteId)
1001 return; 1005 return;
1002 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 1006 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
1003 if (!injectedScript) 1007 if (!injectedScript)
1004 return; 1008 return;
1005 1009
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 } 1047 }
1044 1048
1045 void V8DebuggerAgentImpl::setVariableValue(ErrorString* errorString, 1049 void V8DebuggerAgentImpl::setVariableValue(ErrorString* errorString,
1046 int scopeNumber, 1050 int scopeNumber,
1047 const String16& variableName, 1051 const String16& variableName,
1048 PassOwnPtr<protocol::Runtime::CallArgument> newValueArgument, 1052 PassOwnPtr<protocol::Runtime::CallArgument> newValueArgument,
1049 const String16& callFrameId) 1053 const String16& callFrameId)
1050 { 1054 {
1051 if (!checkEnabled(errorString)) 1055 if (!checkEnabled(errorString))
1052 return; 1056 return;
1053 if (!isPaused() || m_currentCallStack.IsEmpty()) { 1057 if (!isPaused() || !m_currentCallStack) {
1054 *errorString = "Attempt to access callframe when debugger is not on paus e"; 1058 *errorString = "Attempt to access callframe when debugger is not on paus e";
1055 return; 1059 return;
1056 } 1060 }
1057 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 1061 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
1058 if (!remoteId) 1062 if (!remoteId)
1059 return; 1063 return;
1060 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 1064 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
1061 if (!injectedScript) 1065 if (!injectedScript)
1062 return; 1066 return;
1063 1067
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 // from the old StepFrame. 1403 // from the old StepFrame.
1400 m_skippedStepFrameCount = 0; 1404 m_skippedStepFrameCount = 0;
1401 if (m_scheduledDebuggerStep == NoStep) 1405 if (m_scheduledDebuggerStep == NoStep)
1402 debugger().clearStepping(); 1406 debugger().clearStepping();
1403 else if (m_scheduledDebuggerStep == StepOut) 1407 else if (m_scheduledDebuggerStep == StepOut)
1404 m_skipNextDebuggerStepOut = true; 1408 m_skipNextDebuggerStepOut = true;
1405 } 1409 }
1406 } 1410 }
1407 } 1411 }
1408 1412
1409 PassOwnPtr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames() 1413 PassOwnPtr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames(ErrorString* errorString)
1410 { 1414 {
1411 if (m_pausedContext.IsEmpty() || m_currentCallStack.IsEmpty()) 1415 if (m_pausedContext.IsEmpty() || !m_currentCallStack)
1412 return Array<CallFrame>::create(); 1416 return Array<CallFrame>::create();
1413 v8::HandleScope handles(m_isolate);
1414 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( m_pausedContext.Get(m_isolate)); 1417 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( m_pausedContext.Get(m_isolate));
1415 if (!injectedScript) { 1418 if (!injectedScript) {
1416 // Context has been reported as removed while on pause. 1419 // Context has been reported as removed while on pause.
1417 return Array<CallFrame>::create(); 1420 return Array<CallFrame>::create();
1418 } 1421 }
1419 1422
1420 v8::Local<v8::Object> currentCallStack = m_currentCallStack.Get(m_isolate); 1423 v8::HandleScope handles(injectedScript->isolate());
dgozman 2016/03/23 18:46:31 Let's extract isolate to a local var.
kozy 2016/03/23 19:15:10 Done.
1421 return injectedScript->wrapCallFrames(currentCallStack); 1424 v8::Local<v8::Context> context = injectedScript->context();
1425 v8::Context::Scope contextScope(context);
1426
1427 JavaScriptCallFrame* currentCallFrame = m_currentCallStack.get();
1428 int callFrameIndex = 0;
1429 OwnPtr<JavaScriptCallFrame> currentCallFrameOwner;
1430 v8::Local<v8::Array> objects = v8::Array::New(injectedScript->isolate());
1431 while (currentCallFrame) {
1432 v8::Local<v8::Object> object = currentCallFrame->object();
1433 if (hasInternalError(errorString, object.IsEmpty()))
1434 return Array<CallFrame>::create();
1435
1436 String16 callFrameId = "{\"ordinal\":" + String16::number(callFrameIndex ) + ",\"injectedScriptId\":" + String16::number(injectedScript->contextId()) + " }";
dgozman 2016/03/23 18:46:31 Move this serialization to a static method on Remo
kozy 2016/03/23 19:15:10 Done.
1437 if (hasInternalError(errorString, !object->Set(context, toV8StringIntern alized(injectedScript->isolate(), "callFrameId"), toV8String(injectedScript->iso late(), callFrameId)).FromMaybe(false)))
1438 return Array<CallFrame>::create();
1439
1440 v8::Local<v8::Value> scopeChain;
1441 if (hasInternalError(errorString, !object->Get(context, toV8StringIntern alized(injectedScript->isolate(), "scopeChain")).ToLocal(&scopeChain) || !scopeC hain->IsArray()))
1442 return Array<CallFrame>::create();
1443 v8::Local<v8::Array> scopeChainArray = scopeChain.As<v8::Array>();
1444 if (!injectedScript->wrapPropertyInArray(errorString, scopeChainArray, t oV8StringInternalized(injectedScript->isolate(), "object"), V8DebuggerAgentImpl: :backtraceObjectGroup))
1445 return Array<CallFrame>::create();
1446
1447 if (!injectedScript->wrapObjectProperty(errorString, object, toV8StringI nternalized(injectedScript->isolate(), "this"), V8DebuggerAgentImpl::backtraceOb jectGroup))
1448 return Array<CallFrame>::create();
1449
1450 if (object->Has(context, toV8StringInternalized(injectedScript->isolate( ), "returnValue")).FromMaybe(false)) {
1451 if (!injectedScript->wrapObjectProperty(errorString, object, toV8Str ingInternalized(injectedScript->isolate(), "returnValue"), V8DebuggerAgentImpl:: backtraceObjectGroup))
1452 return Array<CallFrame>::create();
1453 }
1454
1455 if (hasInternalError(errorString, !objects->Set(context, callFrameIndex, object).FromMaybe(false)))
1456 return Array<CallFrame>::create();
1457
1458 currentCallFrameOwner = currentCallFrame->caller();
1459 currentCallFrame = currentCallFrameOwner.get();
1460 ++callFrameIndex;
1461 }
1462
1463 protocol::ErrorSupport errorSupport;
1464 OwnPtr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(toProtocolValu e(context, objects).get(), &errorSupport);
1465 if (hasInternalError(errorString, !callFrames))
1466 return Array<CallFrame>::create();
1467 return callFrames.release();
1422 } 1468 }
1423 1469
1424 PassOwnPtr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace() 1470 PassOwnPtr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace()
1425 { 1471 {
1426 if (m_pausedContext.IsEmpty() || !trackingAsyncCalls() || !m_currentAsyncCal lChain) 1472 if (m_pausedContext.IsEmpty() || !trackingAsyncCalls() || !m_currentAsyncCal lChain)
1427 return nullptr; 1473 return nullptr;
1428 1474
1429 return m_currentAsyncCallChain->buildInspectorObjectForTail(this); 1475 return m_currentAsyncCallChain->buildInspectorObjectForTail(this);
1430 } 1476 }
1431 1477
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 ScriptBreakpoint breakpoint; 1539 ScriptBreakpoint breakpoint;
1494 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber); 1540 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber);
1495 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber); 1541 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber);
1496 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition); 1542 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition);
1497 OwnPtr<protocol::Debugger::Location> location = resolveBreakpoint(cookie .first, parsedScript.scriptId, breakpoint, UserBreakpointSource); 1543 OwnPtr<protocol::Debugger::Location> location = resolveBreakpoint(cookie .first, parsedScript.scriptId, breakpoint, UserBreakpointSource);
1498 if (location) 1544 if (location)
1499 m_frontend->breakpointResolved(cookie.first, location.release()); 1545 m_frontend->breakpointResolved(cookie.first, location.release());
1500 } 1546 }
1501 } 1547 }
1502 1548
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) 1549 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 { 1550 {
1505 V8DebuggerAgentImpl::SkipPauseRequest result; 1551 V8DebuggerAgentImpl::SkipPauseRequest result;
1506 if (m_skipAllPauses) 1552 if (m_skipAllPauses)
1507 result = RequestContinue; 1553 result = RequestContinue;
1508 else if (!hitBreakpoints.isEmpty()) 1554 else if (!hitBreakpoints.isEmpty())
1509 result = RequestNoSkip; // Don't skip explicit breakpoints even if set i n frameworks. 1555 result = RequestNoSkip; // Don't skip explicit breakpoints even if set i n frameworks.
1510 else if (!exception.IsEmpty()) 1556 else if (!exception.IsEmpty())
1511 result = shouldSkipExceptionPause(); 1557 result = shouldSkipExceptionPause();
1512 else if (m_scheduledDebuggerStep != NoStep || m_javaScriptPauseScheduled || m_pausingOnNativeEvent) 1558 else if (m_scheduledDebuggerStep != NoStep || m_javaScriptPauseScheduled || m_pausingOnNativeEvent)
1513 result = shouldSkipStepPause(); 1559 result = shouldSkipStepPause();
1514 else 1560 else
1515 result = RequestNoSkip; 1561 result = RequestNoSkip;
1516 1562
1517 m_skipNextDebuggerStepOut = false; 1563 m_skipNextDebuggerStepOut = false;
1518 if (result != RequestNoSkip) 1564 if (result != RequestNoSkip)
1519 return result; 1565 return result;
1520 1566
1521 // Skip pauses inside V8 internal scripts and on syntax errors. 1567 // Skip pauses inside V8 internal scripts and on syntax errors.
1522 if (callFrames.IsEmpty()) 1568 if (!callFrames)
1523 return RequestContinue; 1569 return RequestContinue;
1524 1570
1525 ASSERT(m_pausedContext.IsEmpty()); 1571 ASSERT(m_pausedContext.IsEmpty());
1526 m_pausedContext.Reset(m_isolate, context); 1572 m_pausedContext.Reset(m_isolate, context);
1527 m_currentCallStack.Reset(m_isolate, callFrames); 1573 m_currentCallStack = callFrames;
1528 v8::HandleScope handles(m_isolate); 1574 v8::HandleScope handles(m_isolate);
1529 1575
1530 if (!exception.IsEmpty()) { 1576 if (!exception.IsEmpty()) {
1531 InjectedScript* injectedScript = m_injectedScriptManager->injectedScript For(context); 1577 InjectedScript* injectedScript = m_injectedScriptManager->injectedScript For(context);
1532 if (injectedScript) { 1578 if (injectedScript) {
1533 m_breakReason = isPromiseRejection ? protocol::Debugger::Paused::Rea sonEnum::PromiseRejection : protocol::Debugger::Paused::ReasonEnum::Exception; 1579 m_breakReason = isPromiseRejection ? protocol::Debugger::Paused::Rea sonEnum::PromiseRejection : protocol::Debugger::Paused::ReasonEnum::Exception;
1534 ErrorString errorString; 1580 ErrorString errorString;
1535 auto obj = injectedScript->wrapObject(&errorString, exception, V8Deb uggerAgentImpl::backtraceObjectGroup); 1581 auto obj = injectedScript->wrapObject(&errorString, exception, V8Deb uggerAgentImpl::backtraceObjectGroup);
1536 m_breakAuxData = obj ? obj->serialize() : nullptr; 1582 m_breakAuxData = obj ? obj->serialize() : nullptr;
1537 // m_breakAuxData might be null after this. 1583 // m_breakAuxData might be null after this.
(...skipping 14 matching lines...) Expand all
1552 1598
1553 BreakpointSource source = breakpointIterator->second->second; 1599 BreakpointSource source = breakpointIterator->second->second;
1554 if (m_breakReason == protocol::Debugger::Paused::ReasonEnum::Other & & source == DebugCommandBreakpointSource) 1600 if (m_breakReason == protocol::Debugger::Paused::ReasonEnum::Other & & source == DebugCommandBreakpointSource)
1555 m_breakReason = protocol::Debugger::Paused::ReasonEnum::DebugCom mand; 1601 m_breakReason = protocol::Debugger::Paused::ReasonEnum::DebugCom mand;
1556 } 1602 }
1557 } 1603 }
1558 1604
1559 if (!m_asyncOperationNotifications.isEmpty()) 1605 if (!m_asyncOperationNotifications.isEmpty())
1560 flushAsyncOperationEvents(nullptr); 1606 flushAsyncOperationEvents(nullptr);
1561 1607
1562 m_frontend->paused(currentCallFrames(), m_breakReason, m_breakAuxData.releas e(), hitBreakpointIds.release(), currentAsyncStackTrace()); 1608 ErrorString errorString;
1609 m_frontend->paused(currentCallFrames(&errorString), m_breakReason, m_breakAu xData.release(), hitBreakpointIds.release(), currentAsyncStackTrace());
1563 m_scheduledDebuggerStep = NoStep; 1610 m_scheduledDebuggerStep = NoStep;
1564 m_javaScriptPauseScheduled = false; 1611 m_javaScriptPauseScheduled = false;
1565 m_steppingFromFramework = false; 1612 m_steppingFromFramework = false;
1566 m_pausingOnNativeEvent = false; 1613 m_pausingOnNativeEvent = false;
1567 m_skippedStepFrameCount = 0; 1614 m_skippedStepFrameCount = 0;
1568 m_recursionLevelForStepFrame = 0; 1615 m_recursionLevelForStepFrame = 0;
1569 clearStepIntoAsync(); 1616 clearStepIntoAsync();
1570 1617
1571 if (!m_continueToLocationBreakpointId.isEmpty()) { 1618 if (!m_continueToLocationBreakpointId.isEmpty()) {
1572 debugger().removeBreakpoint(m_continueToLocationBreakpointId); 1619 debugger().removeBreakpoint(m_continueToLocationBreakpointId);
1573 m_continueToLocationBreakpointId = ""; 1620 m_continueToLocationBreakpointId = "";
1574 } 1621 }
1575 return result; 1622 return result;
1576 } 1623 }
1577 1624
1578 void V8DebuggerAgentImpl::didContinue() 1625 void V8DebuggerAgentImpl::didContinue()
1579 { 1626 {
1580 m_pausedContext.Reset(); 1627 m_pausedContext.Reset();
1581 m_currentCallStack.Reset(); 1628 m_currentCallStack.clear();
1582 clearBreakDetails(); 1629 clearBreakDetails();
1583 m_frontend->resumed(); 1630 m_frontend->resumed();
1584 } 1631 }
1585 1632
1586 bool V8DebuggerAgentImpl::canBreakProgram() 1633 bool V8DebuggerAgentImpl::canBreakProgram()
1587 { 1634 {
1588 return debugger().canBreakProgram(); 1635 return debugger().canBreakProgram();
1589 } 1636 }
1590 1637
1591 void V8DebuggerAgentImpl::breakProgram(const String16& breakReason, PassOwnPtr<p rotocol::DictionaryValue> data) 1638 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; 1696 return;
1650 m_scheduledDebuggerStep = NoStep; 1697 m_scheduledDebuggerStep = NoStep;
1651 m_scripts.clear(); 1698 m_scripts.clear();
1652 m_blackboxedPositions.clear(); 1699 m_blackboxedPositions.clear();
1653 m_breakpointIdToDebuggerBreakpointIds.clear(); 1700 m_breakpointIdToDebuggerBreakpointIds.clear();
1654 resetAsyncCallTracker(); 1701 resetAsyncCallTracker();
1655 m_promiseTracker->clear(); 1702 m_promiseTracker->clear();
1656 } 1703 }
1657 1704
1658 } // namespace blink 1705 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698