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

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> createProtocolLocation(const Str ing16& scriptId, int lineNumber, int columnNumber)
153 {
154 return protocol::Debugger::Location::create()
155 .setScriptId(scriptId)
156 .setLineNumber(lineNumber)
157 .setColumnNumber(columnNumber).build();
158 }
159
160 static PassOwnPtr<Array<protocol::Debugger::Scope>> toProtocolScopeChain(ErrorSt ring* errorString, InjectedScript* injectedScript, JavaScriptCallFrame* callFram e)
161 {
162 v8::Local<v8::Value> scopeChainValue = callFrame->scopeChain();
163 if (hasInternalError(errorString, scopeChainValue.IsEmpty() || !scopeChainVa lue->IsArray()))
164 return nullptr;
165 v8::Local<v8::Array> scopeChainArray = scopeChainValue.As<v8::Array>();
166 if (!injectedScript->wrapObjectsInArray(errorString, scopeChainArray, V8Debu ggerAgent::backtraceObjectGroup))
167 return nullptr;
168 OwnPtr<Array<protocol::Debugger::Scope>> outScopeChain = Array<protocol::Deb ugger::Scope>::create();
169 for (size_t i = 0; i < scopeChainArray->Length(); ++i) {
170 v8::Local<v8::Value> scopeValue;
171 if (hasInternalError(errorString, !scopeChainArray->Get(injectedScript-> context(), i).ToLocal(&scopeValue)))
172 return nullptr;
173 protocol::ErrorSupport errorSupport;
174 OwnPtr<RemoteObject> scopeRemoteObject = RemoteObject::parse(toProtocolV alue(injectedScript->context(), scopeValue).get(), &errorSupport);
175 if (hasInternalError(errorString, !scopeRemoteObject))
176 return nullptr;
177
178 OwnPtr<protocol::Debugger::Scope> protocolScope = protocol::Debugger::Sc ope::create()
179 .setType(toProtocolStringWithTypeCheck(callFrame->scopeType(i)))
180 .setObject(scopeRemoteObject.release())
181 .setName(toProtocolStringWithTypeCheck(callFrame->scopeName(i)))
182 .build();
183
184 v8::Local<v8::Value> startLocationValue = callFrame->scopeStartLocation( i);
185 if (hasInternalError(errorString, startLocationValue.IsEmpty()))
186 return nullptr;
187
188 if (!startLocationValue->IsUndefined() && !startLocationValue->IsNull()) {
189 OwnPtr<protocol::Debugger::Location> startLocation = protocol::Debug ger::Location::parse(toProtocolValue(injectedScript->context(), startLocationVal ue).get(), &errorSupport);
190 if (hasInternalError(errorString, !startLocation))
191 return nullptr;
192 protocolScope->setStartLocation(startLocation.release());
193 }
194
195 v8::Local<v8::Value> endLocationValue = callFrame->scopeEndLocation(i);
196 if (hasInternalError(errorString, endLocationValue.IsEmpty()))
197 return nullptr;
198
199 if (!endLocationValue->IsUndefined() && !endLocationValue->IsNull()) {
200 OwnPtr<protocol::Debugger::Location> endLocation = protocol::Debugge r::Location::parse(toProtocolValue(injectedScript->context(), endLocationValue). get(), &errorSupport);
201 if (hasInternalError(errorString, !endLocation))
202 return nullptr;
203 protocolScope->setEndLocation(endLocation.release());
204 }
205
206 outScopeChain->addItem(protocolScope.release());
207 }
208 return outScopeChain.release();
209 }
210
211 static PassOwnPtr<CallFrame> toProtocolCallFrame(ErrorString* errorString, Injec tedScript* injectedScript, int callFrameIndex, JavaScriptCallFrame* callFrame)
212 {
213 String16 callFrameId = "{\"ordinal\":" + String16::number(callFrameIndex) + ",\"injectedScriptId\":" + String16::number(injectedScript->contextId()) + "}";
214 String16 scriptId = String16::number(callFrame->sourceID());
215 OwnPtr<Array<protocol::Debugger::Scope>> scopeChainArray = toProtocolScopeCh ain(errorString, injectedScript, callFrame);
216 if (hasInternalError(errorString, !scopeChainArray))
217 return nullptr;
218 OwnPtr<RemoteObject> thisRemoteObject = injectedScript->wrapObject(errorStri ng, callFrame->thisObject(), V8DebuggerAgent::backtraceObjectGroup);
219 if (hasInternalError(errorString, !thisRemoteObject))
220 return nullptr;
221 OwnPtr<CallFrame> outCallFrame = CallFrame::create()
222 .setCallFrameId(callFrameId)
223 .setFunctionName(callFrame->functionName())
224 .setFunctionLocation(createProtocolLocation(scriptId, callFrame->functio nLine(), callFrame->functionColumn()))
225 .setLocation(createProtocolLocation(scriptId, callFrame->line(), callFra me->column()))
226 .setScopeChain(scopeChainArray.release())
227 .setThis(thisRemoteObject.release())
228 .build();
229
230 v8::Local<v8::Value> returnValue = callFrame->returnValue();
231 if (hasInternalError(errorString, returnValue.IsEmpty()))
232 return nullptr;
233 if (!returnValue->IsUndefined()) {
234 OwnPtr<RemoteObject> returnRemoteValue = injectedScript->wrapObject(erro rString, returnValue, V8DebuggerAgent::backtraceObjectGroup);
235 if (hasInternalError(errorString, !returnRemoteValue))
236 return nullptr;
237 outCallFrame->setReturnValue(returnRemoteValue.release());
238 }
239 return outCallFrame.release();
240 }
241
153 PassOwnPtr<V8DebuggerAgent> V8DebuggerAgent::create(V8RuntimeAgent* runtimeAgent ) 242 PassOwnPtr<V8DebuggerAgent> V8DebuggerAgent::create(V8RuntimeAgent* runtimeAgent )
154 { 243 {
155 V8RuntimeAgentImpl* runtimeAgentImpl = static_cast<V8RuntimeAgentImpl*>(runt imeAgent); 244 V8RuntimeAgentImpl* runtimeAgentImpl = static_cast<V8RuntimeAgentImpl*>(runt imeAgent);
156 return adoptPtr(new V8DebuggerAgentImpl(runtimeAgentImpl->getInjectedScriptM anager(), runtimeAgentImpl->debugger(), runtimeAgentImpl->contextGroupId())); 245 return adoptPtr(new V8DebuggerAgentImpl(runtimeAgentImpl->getInjectedScriptM anager(), runtimeAgentImpl->debugger(), runtimeAgentImpl->contextGroupId()));
157 } 246 }
158 247
159 V8DebuggerAgentImpl::V8DebuggerAgentImpl(InjectedScriptManager* injectedScriptMa nager, V8DebuggerImpl* debugger, int contextGroupId) 248 V8DebuggerAgentImpl::V8DebuggerAgentImpl(InjectedScriptManager* injectedScriptMa nager, V8DebuggerImpl* debugger, int contextGroupId)
160 : m_injectedScriptManager(injectedScriptManager) 249 : m_injectedScriptManager(injectedScriptManager)
161 , m_debugger(debugger) 250 , m_debugger(debugger)
162 , m_contextGroupId(contextGroupId) 251 , m_contextGroupId(contextGroupId)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 return; 324 return;
236 325
237 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, protocol::Dict ionaryValue::create()); 326 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, protocol::Dict ionaryValue::create());
238 m_state->setNumber(DebuggerAgentState::pauseOnExceptionsState, V8DebuggerImp l::DontPauseOnExceptions); 327 m_state->setNumber(DebuggerAgentState::pauseOnExceptionsState, V8DebuggerImp l::DontPauseOnExceptions);
239 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, 0); 328 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, 0);
240 m_state->setBoolean(DebuggerAgentState::promiseTrackerEnabled, false); 329 m_state->setBoolean(DebuggerAgentState::promiseTrackerEnabled, false);
241 m_state->setBoolean(DebuggerAgentState::promiseTrackerCaptureStacks, false); 330 m_state->setBoolean(DebuggerAgentState::promiseTrackerCaptureStacks, false);
242 331
243 debugger().removeDebuggerAgent(m_contextGroupId); 332 debugger().removeDebuggerAgent(m_contextGroupId);
244 m_pausedContext.Reset(); 333 m_pausedContext.Reset();
245 m_currentCallStack.Reset(); 334 m_currentCallStack.clear();
246 m_scripts.clear(); 335 m_scripts.clear();
247 m_blackboxedPositions.clear(); 336 m_blackboxedPositions.clear();
248 m_breakpointIdToDebuggerBreakpointIds.clear(); 337 m_breakpointIdToDebuggerBreakpointIds.clear();
249 internalSetAsyncCallStackDepth(0); 338 internalSetAsyncCallStackDepth(0);
250 m_promiseTracker->setEnabled(false, false); 339 m_promiseTracker->setEnabled(false, false);
251 m_continueToLocationBreakpointId = String16(); 340 m_continueToLocationBreakpointId = String16();
252 clearBreakDetails(); 341 clearBreakDetails();
253 m_scheduledDebuggerStep = NoStep; 342 m_scheduledDebuggerStep = NoStep;
254 m_skipNextDebuggerStepOut = false; 343 m_skipNextDebuggerStepOut = false;
255 m_javaScriptPauseScheduled = false; 344 m_javaScriptPauseScheduled = false;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 568
480 ScriptBreakpoint breakpoint(lineNumber, columnNumber, ""); 569 ScriptBreakpoint breakpoint(lineNumber, columnNumber, "");
481 m_continueToLocationBreakpointId = debugger().setBreakpoint(scriptId, breakp oint, &lineNumber, &columnNumber, interstateLocationOpt.fromMaybe(false)); 570 m_continueToLocationBreakpointId = debugger().setBreakpoint(scriptId, breakp oint, &lineNumber, &columnNumber, interstateLocationOpt.fromMaybe(false));
482 resume(errorString); 571 resume(errorString);
483 } 572 }
484 573
485 void V8DebuggerAgentImpl::getBacktrace(ErrorString* errorString, OwnPtr<Array<Ca llFrame>>* callFrames, Maybe<StackTrace>* asyncStackTrace) 574 void V8DebuggerAgentImpl::getBacktrace(ErrorString* errorString, OwnPtr<Array<Ca llFrame>>* callFrames, Maybe<StackTrace>* asyncStackTrace)
486 { 575 {
487 if (!assertPaused(errorString)) 576 if (!assertPaused(errorString))
488 return; 577 return;
489 m_currentCallStack.Reset(m_isolate, debugger().currentCallFrames()); 578 m_currentCallStack = debugger().currentCallFrames();
490 *callFrames = currentCallFrames(); 579 *callFrames = currentCallFrames(errorString);
dgozman 2016/03/23 00:12:35 if error - return nothing?
kozy 2016/03/23 02:13:10 Done.
491 *asyncStackTrace = currentAsyncStackTrace(); 580 *asyncStackTrace = currentAsyncStackTrace();
492 } 581 }
493 582
494 bool V8DebuggerAgentImpl::isCallStackEmptyOrBlackboxed() 583 bool V8DebuggerAgentImpl::isCallStackEmptyOrBlackboxed()
495 { 584 {
496 ASSERT(enabled()); 585 ASSERT(enabled());
497 for (int index = 0; ; ++index) { 586 for (int index = 0; ; ++index) {
498 OwnPtr<JavaScriptCallFrame> frame = debugger().callFrame(index); 587 OwnPtr<JavaScriptCallFrame> frame = debugger().callFrame(index);
499 if (!frame) 588 if (!frame)
500 break; 589 break;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 return nullptr; 672 return nullptr;
584 673
585 m_serverBreakpoints.set(debuggerBreakpointId, std::make_pair(breakpointId, s ource)); 674 m_serverBreakpoints.set(debuggerBreakpointId, std::make_pair(breakpointId, s ource));
586 RELEASE_ASSERT(!breakpointId.isEmpty()); 675 RELEASE_ASSERT(!breakpointId.isEmpty());
587 if (!m_breakpointIdToDebuggerBreakpointIds.contains(breakpointId)) 676 if (!m_breakpointIdToDebuggerBreakpointIds.contains(breakpointId))
588 m_breakpointIdToDebuggerBreakpointIds.set(breakpointId, protocol::Vector <String16>()); 677 m_breakpointIdToDebuggerBreakpointIds.set(breakpointId, protocol::Vector <String16>());
589 678
590 BreakpointIdToDebuggerBreakpointIdsMap::iterator debuggerBreakpointIdsIterat or = m_breakpointIdToDebuggerBreakpointIds.find(breakpointId); 679 BreakpointIdToDebuggerBreakpointIdsMap::iterator debuggerBreakpointIdsIterat or = m_breakpointIdToDebuggerBreakpointIds.find(breakpointId);
591 debuggerBreakpointIdsIterator->second->append(debuggerBreakpointId); 680 debuggerBreakpointIdsIterator->second->append(debuggerBreakpointId);
592 681
593 OwnPtr<protocol::Debugger::Location> location = protocol::Debugger::Location ::create() 682 return createProtocolLocation(scriptId, actualLineNumber, actualColumnNumber );
dgozman 2016/03/23 00:12:35 buildLocation
kozy 2016/03/23 02:13:10 Done.
594 .setScriptId(scriptId)
595 .setLineNumber(actualLineNumber)
596 .setColumnNumber(actualColumnNumber).build();
597 return location.release();
598 } 683 }
599 684
600 void V8DebuggerAgentImpl::searchInContent(ErrorString* error, const String16& sc riptId, const String16& query, 685 void V8DebuggerAgentImpl::searchInContent(ErrorString* error, const String16& sc riptId, const String16& query,
601 const Maybe<bool>& optionalCaseSensitive, 686 const Maybe<bool>& optionalCaseSensitive,
602 const Maybe<bool>& optionalIsRegex, 687 const Maybe<bool>& optionalIsRegex,
603 OwnPtr<Array<protocol::Debugger::SearchMatch>>* results) 688 OwnPtr<Array<protocol::Debugger::SearchMatch>>* results)
604 { 689 {
605 ScriptsMap::iterator it = m_scripts.find(scriptId); 690 ScriptsMap::iterator it = m_scripts.find(scriptId);
606 if (it != m_scripts.end()) 691 if (it != m_scripts.end())
607 *results = V8ContentSearchUtil::searchInTextByLines(m_debugger, it->seco nd->source(), query, optionalCaseSensitive.fromMaybe(false), optionalIsRegex.fro mMaybe(false)); 692 *results = V8ContentSearchUtil::searchInTextByLines(m_debugger, it->seco nd->source(), query, optionalCaseSensitive.fromMaybe(false), optionalIsRegex.fro mMaybe(false));
608 else 693 else
609 *error = String16("No script for id: " + scriptId); 694 *error = String16("No script for id: " + scriptId);
610 } 695 }
611 696
612 void V8DebuggerAgentImpl::setScriptSource(ErrorString* error, 697 void V8DebuggerAgentImpl::setScriptSource(ErrorString* errorString,
613 const String16& scriptId, 698 const String16& scriptId,
614 const String16& newContent, 699 const String16& newContent,
615 const Maybe<bool>& preview, 700 const Maybe<bool>& preview,
616 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* newCallFrames, 701 Maybe<protocol::Array<protocol::Debugger::CallFrame>>* newCallFrames,
617 Maybe<bool>* stackChanged, 702 Maybe<bool>* stackChanged,
618 Maybe<StackTrace>* asyncStackTrace, 703 Maybe<StackTrace>* asyncStackTrace,
619 Maybe<protocol::Debugger::SetScriptSourceError>* optOutCompileError) 704 Maybe<protocol::Debugger::SetScriptSourceError>* optOutCompileError)
620 { 705 {
621 if (!checkEnabled(error)) 706 if (!checkEnabled(errorString))
622 return; 707 return;
623 if (!debugger().setScriptSource(scriptId, newContent, preview.fromMaybe(fals e), error, optOutCompileError, &m_currentCallStack, stackChanged)) 708 if (!debugger().setScriptSource(scriptId, newContent, preview.fromMaybe(fals e), errorString, optOutCompileError, &m_currentCallStack, stackChanged))
624 return; 709 return;
625 710
626 *newCallFrames = currentCallFrames(); 711 *newCallFrames = currentCallFrames(errorString);
712 if (!errorString->isEmpty())
713 return;
627 *asyncStackTrace = currentAsyncStackTrace(); 714 *asyncStackTrace = currentAsyncStackTrace();
628 715
629 ScriptsMap::iterator it = m_scripts.find(scriptId); 716 ScriptsMap::iterator it = m_scripts.find(scriptId);
630 if (it == m_scripts.end()) 717 if (it == m_scripts.end())
631 return; 718 return;
632 it->second->setSource(newContent); 719 it->second->setSource(newContent);
633 } 720 }
634 721
635 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString, 722 void V8DebuggerAgentImpl::restartFrame(ErrorString* errorString,
636 const String16& callFrameId, 723 const String16& callFrameId,
637 OwnPtr<Array<CallFrame>>* newCallFrames, 724 OwnPtr<Array<CallFrame>>* newCallFrames,
638 Maybe<StackTrace>* asyncStackTrace) 725 Maybe<StackTrace>* asyncStackTrace)
639 { 726 {
640 if (!isPaused() || m_currentCallStack.IsEmpty()) { 727 if (!isPaused() || !m_currentCallStack) {
641 *errorString = "Attempt to access call frame when debugger is not on pau se"; 728 *errorString = "Attempt to access call frame when debugger is not on pau se";
642 return; 729 return;
643 } 730 }
644 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 731 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
645 if (!remoteId) 732 if (!remoteId)
646 return; 733 return;
647 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 734 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
648 if (!injectedScript) 735 if (!injectedScript)
649 return; 736 return;
650 737
651 v8::HandleScope scope(m_isolate); 738 v8::HandleScope scope(m_isolate);
652 v8::Local<v8::Context> localContext = injectedScript->context(); 739 v8::Local<v8::Context> localContext = injectedScript->context();
653 740
654 v8::TryCatch tryCatch(m_isolate); 741 v8::TryCatch tryCatch(m_isolate);
655 742
656 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrame(remot eId->frameOrdinal()); 743 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrame(remot eId->frameOrdinal());
657 if (!javaScriptCallFrame) { 744 if (!javaScriptCallFrame) {
658 *errorString = "Could not find call frame with given id"; 745 *errorString = "Could not find call frame with given id";
659 return; 746 return;
660 } 747 }
661 v8::Local<v8::Value> resultValue; 748 v8::Local<v8::Value> resultValue;
662 v8::Local<v8::Boolean> result; 749 v8::Local<v8::Boolean> result;
663 if (!javaScriptCallFrame->restart().ToLocal(&resultValue) || tryCatch.HasCau ght() || !resultValue->ToBoolean(localContext).ToLocal(&result) || !result->Valu e()) { 750 if (!javaScriptCallFrame->restart().ToLocal(&resultValue) || tryCatch.HasCau ght() || !resultValue->ToBoolean(localContext).ToLocal(&result) || !result->Valu e()) {
664 *errorString = "Internal error"; 751 *errorString = "Internal error";
665 return; 752 return;
666 } 753 }
667 754
668 m_currentCallStack.Reset(m_isolate, debugger().currentCallFrames()); 755 m_currentCallStack = debugger().currentCallFrames();
669 756
670 *newCallFrames = currentCallFrames(); 757 *newCallFrames = currentCallFrames(errorString);
758 if (!errorString->isEmpty())
dgozman 2016/03/23 00:12:35 should we check newCallFrames instead?
kozy 2016/03/23 02:13:10 Done.
759 return;
671 *asyncStackTrace = currentAsyncStackTrace(); 760 *asyncStackTrace = currentAsyncStackTrace();
672 } 761 }
673 762
674 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource) 763 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource)
675 { 764 {
676 if (!checkEnabled(error)) 765 if (!checkEnabled(error))
677 return; 766 return;
678 ScriptsMap::iterator it = m_scripts.find(scriptId); 767 ScriptsMap::iterator it = m_scripts.find(scriptId);
679 if (it == m_scripts.end()) { 768 if (it == m_scripts.end()) {
680 *error = "No script for id: " + scriptId; 769 *error = "No script for id: " + scriptId;
(...skipping 28 matching lines...) Expand all
709 798
710 v8::Local<v8::Value> scopesValue; 799 v8::Local<v8::Value> scopesValue;
711 v8::Local<v8::Array> scopes; 800 v8::Local<v8::Array> scopes;
712 String16 groupName = injectedScript->objectGroupName(*remoteId); 801 String16 groupName = injectedScript->objectGroupName(*remoteId);
713 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu e->IsArray()) { 802 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu e->IsArray()) {
714 scopes = scopesValue.As<v8::Array>(); 803 scopes = scopesValue.As<v8::Array>();
715 if (!injectedScript->wrapPropertyInArray(errorString, scopes, toV8String Internalized(injectedScript->isolate(), "object"), groupName)) 804 if (!injectedScript->wrapPropertyInArray(errorString, scopes, toV8String Internalized(injectedScript->isolate(), "object"), groupName))
716 return; 805 return;
717 } 806 }
718 807
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() 808 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create()
725 .setLocation(location.release()) 809 .setLocation(createProtocolLocation(String16::number(function->ScriptId( )), function->GetScriptLineNumber(), function->GetScriptColumnNumber()))
726 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName()) ) 810 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName()) )
727 .setIsGenerator(function->IsGeneratorFunction()).build(); 811 .setIsGenerator(function->IsGeneratorFunction()).build();
728 812
729 if (!scopes.IsEmpty()) { 813 if (!scopes.IsEmpty()) {
730 protocol::ErrorSupport errorSupport; 814 protocol::ErrorSupport errorSupport;
731 OwnPtr<protocol::Array<protocol::Debugger::Scope>> scopeChain = protocol ::Array<protocol::Debugger::Scope>::parse(toProtocolValue(injectedScript->contex t(), scopes).get(), &errorSupport); 815 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())) 816 if (hasInternalError(errorString, errorSupport.hasErrors()))
733 return; 817 return;
734 functionDetails->setScopeChain(scopeChain.release()); 818 functionDetails->setScopeChain(scopeChain.release());
735 } 819 }
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 const String16& expression, 1069 const String16& expression,
986 const Maybe<String16>& objectGroup, 1070 const Maybe<String16>& objectGroup,
987 const Maybe<bool>& includeCommandLineAPI, 1071 const Maybe<bool>& includeCommandLineAPI,
988 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 1072 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
989 const Maybe<bool>& returnByValue, 1073 const Maybe<bool>& returnByValue,
990 const Maybe<bool>& generatePreview, 1074 const Maybe<bool>& generatePreview,
991 OwnPtr<RemoteObject>* result, 1075 OwnPtr<RemoteObject>* result,
992 Maybe<bool>* wasThrown, 1076 Maybe<bool>* wasThrown,
993 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) 1077 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails)
994 { 1078 {
995 if (!isPaused() || m_currentCallStack.IsEmpty()) { 1079 if (!isPaused() || !m_currentCallStack) {
996 *errorString = "Attempt to access callframe when debugger is not on paus e"; 1080 *errorString = "Attempt to access callframe when debugger is not on paus e";
997 return; 1081 return;
998 } 1082 }
999 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 1083 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
1000 if (!remoteId) 1084 if (!remoteId)
1001 return; 1085 return;
1002 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 1086 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
1003 if (!injectedScript) 1087 if (!injectedScript)
1004 return; 1088 return;
1005 1089
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 } 1127 }
1044 1128
1045 void V8DebuggerAgentImpl::setVariableValue(ErrorString* errorString, 1129 void V8DebuggerAgentImpl::setVariableValue(ErrorString* errorString,
1046 int scopeNumber, 1130 int scopeNumber,
1047 const String16& variableName, 1131 const String16& variableName,
1048 PassOwnPtr<protocol::Runtime::CallArgument> newValueArgument, 1132 PassOwnPtr<protocol::Runtime::CallArgument> newValueArgument,
1049 const String16& callFrameId) 1133 const String16& callFrameId)
1050 { 1134 {
1051 if (!checkEnabled(errorString)) 1135 if (!checkEnabled(errorString))
1052 return; 1136 return;
1053 if (!isPaused() || m_currentCallStack.IsEmpty()) { 1137 if (!isPaused() || !m_currentCallStack) {
1054 *errorString = "Attempt to access callframe when debugger is not on paus e"; 1138 *errorString = "Attempt to access callframe when debugger is not on paus e";
1055 return; 1139 return;
1056 } 1140 }
1057 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId); 1141 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(errorString, c allFrameId);
1058 if (!remoteId) 1142 if (!remoteId)
1059 return; 1143 return;
1060 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); 1144 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get());
1061 if (!injectedScript) 1145 if (!injectedScript)
1062 return; 1146 return;
1063 1147
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 // from the old StepFrame. 1483 // from the old StepFrame.
1400 m_skippedStepFrameCount = 0; 1484 m_skippedStepFrameCount = 0;
1401 if (m_scheduledDebuggerStep == NoStep) 1485 if (m_scheduledDebuggerStep == NoStep)
1402 debugger().clearStepping(); 1486 debugger().clearStepping();
1403 else if (m_scheduledDebuggerStep == StepOut) 1487 else if (m_scheduledDebuggerStep == StepOut)
1404 m_skipNextDebuggerStepOut = true; 1488 m_skipNextDebuggerStepOut = true;
1405 } 1489 }
1406 } 1490 }
1407 } 1491 }
1408 1492
1409 PassOwnPtr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames() 1493 PassOwnPtr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames(ErrorString* errorString)
1410 { 1494 {
1411 if (m_pausedContext.IsEmpty() || m_currentCallStack.IsEmpty()) 1495 if (m_pausedContext.IsEmpty() || !m_currentCallStack)
1412 return Array<CallFrame>::create(); 1496 return Array<CallFrame>::create();
1413 v8::HandleScope handles(m_isolate);
1414 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( m_pausedContext.Get(m_isolate)); 1497 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( m_pausedContext.Get(m_isolate));
1415 if (!injectedScript) { 1498 if (!injectedScript) {
1416 // Context has been reported as removed while on pause. 1499 // Context has been reported as removed while on pause.
1417 return Array<CallFrame>::create(); 1500 return Array<CallFrame>::create();
1418 } 1501 }
1419 1502
1420 v8::Local<v8::Object> currentCallStack = m_currentCallStack.Get(m_isolate); 1503 v8::HandleScope handles(injectedScript->isolate());
1421 return injectedScript->wrapCallFrames(currentCallStack); 1504 v8::Local<v8::Context> context = injectedScript->context();
1505 v8::Context::Scope contextScope(context);
1506
1507 OwnPtr<Array<CallFrame>> callFrames = Array<CallFrame>::create();
1508
1509 JavaScriptCallFrame* currentCallFrame = m_currentCallStack.get();
1510 int callFrameIndex = 0;
1511 OwnPtr<JavaScriptCallFrame> currentCallFrameOwner;
1512 while (currentCallFrame) {
1513 OwnPtr<CallFrame> callFrame = toProtocolCallFrame(errorString, injectedS cript, callFrameIndex, currentCallFrame);
1514 if (!callFrame)
1515 return Array<CallFrame>::create();
1516 callFrames->addItem(callFrame.release());
1517
1518 currentCallFrameOwner = currentCallFrame->caller();
1519 currentCallFrame = currentCallFrameOwner.get();
1520 ++callFrameIndex;
1521 }
1522 return callFrames.release();
1422 } 1523 }
1423 1524
1424 PassOwnPtr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace() 1525 PassOwnPtr<StackTrace> V8DebuggerAgentImpl::currentAsyncStackTrace()
1425 { 1526 {
1426 if (m_pausedContext.IsEmpty() || !trackingAsyncCalls() || !m_currentAsyncCal lChain) 1527 if (m_pausedContext.IsEmpty() || !trackingAsyncCalls() || !m_currentAsyncCal lChain)
1427 return nullptr; 1528 return nullptr;
1428 1529
1429 return m_currentAsyncCallChain->buildInspectorObjectForTail(this); 1530 return m_currentAsyncCallChain->buildInspectorObjectForTail(this);
1430 } 1531 }
1431 1532
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 ScriptBreakpoint breakpoint; 1594 ScriptBreakpoint breakpoint;
1494 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber); 1595 breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakpoint. lineNumber);
1495 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber); 1596 breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakpoin t.columnNumber);
1496 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition); 1597 breakpointObject->getString(DebuggerAgentState::condition, &breakpoint.c ondition);
1497 OwnPtr<protocol::Debugger::Location> location = resolveBreakpoint(cookie .first, parsedScript.scriptId, breakpoint, UserBreakpointSource); 1598 OwnPtr<protocol::Debugger::Location> location = resolveBreakpoint(cookie .first, parsedScript.scriptId, breakpoint, UserBreakpointSource);
1498 if (location) 1599 if (location)
1499 m_frontend->breakpointResolved(cookie.first, location.release()); 1600 m_frontend->breakpointResolved(cookie.first, location.release());
1500 } 1601 }
1501 } 1602 }
1502 1603
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) 1604 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 { 1605 {
1505 V8DebuggerAgentImpl::SkipPauseRequest result; 1606 V8DebuggerAgentImpl::SkipPauseRequest result;
1506 if (m_skipAllPauses) 1607 if (m_skipAllPauses)
1507 result = RequestContinue; 1608 result = RequestContinue;
1508 else if (!hitBreakpoints.isEmpty()) 1609 else if (!hitBreakpoints.isEmpty())
1509 result = RequestNoSkip; // Don't skip explicit breakpoints even if set i n frameworks. 1610 result = RequestNoSkip; // Don't skip explicit breakpoints even if set i n frameworks.
1510 else if (!exception.IsEmpty()) 1611 else if (!exception.IsEmpty())
1511 result = shouldSkipExceptionPause(); 1612 result = shouldSkipExceptionPause();
1512 else if (m_scheduledDebuggerStep != NoStep || m_javaScriptPauseScheduled || m_pausingOnNativeEvent) 1613 else if (m_scheduledDebuggerStep != NoStep || m_javaScriptPauseScheduled || m_pausingOnNativeEvent)
1513 result = shouldSkipStepPause(); 1614 result = shouldSkipStepPause();
1514 else 1615 else
1515 result = RequestNoSkip; 1616 result = RequestNoSkip;
1516 1617
1517 m_skipNextDebuggerStepOut = false; 1618 m_skipNextDebuggerStepOut = false;
1518 if (result != RequestNoSkip) 1619 if (result != RequestNoSkip)
1519 return result; 1620 return result;
1520 1621
1521 // Skip pauses inside V8 internal scripts and on syntax errors. 1622 // Skip pauses inside V8 internal scripts and on syntax errors.
1522 if (callFrames.IsEmpty()) 1623 if (!callFrames)
1523 return RequestContinue; 1624 return RequestContinue;
1524 1625
1525 ASSERT(m_pausedContext.IsEmpty()); 1626 ASSERT(m_pausedContext.IsEmpty());
1526 m_pausedContext.Reset(m_isolate, context); 1627 m_pausedContext.Reset(m_isolate, context);
1527 m_currentCallStack.Reset(m_isolate, callFrames); 1628
dgozman 2016/03/23 00:12:35 nit: extra blank line
kozy 2016/03/23 02:13:10 Done.
1629 m_currentCallStack = callFrames;
1528 v8::HandleScope handles(m_isolate); 1630 v8::HandleScope handles(m_isolate);
1529 1631
1530 if (!exception.IsEmpty()) { 1632 if (!exception.IsEmpty()) {
1531 InjectedScript* injectedScript = m_injectedScriptManager->injectedScript For(context); 1633 InjectedScript* injectedScript = m_injectedScriptManager->injectedScript For(context);
1532 if (injectedScript) { 1634 if (injectedScript) {
1533 m_breakReason = isPromiseRejection ? protocol::Debugger::Paused::Rea sonEnum::PromiseRejection : protocol::Debugger::Paused::ReasonEnum::Exception; 1635 m_breakReason = isPromiseRejection ? protocol::Debugger::Paused::Rea sonEnum::PromiseRejection : protocol::Debugger::Paused::ReasonEnum::Exception;
1534 ErrorString errorString; 1636 ErrorString errorString;
1535 auto obj = injectedScript->wrapObject(&errorString, exception, V8Deb uggerAgentImpl::backtraceObjectGroup); 1637 auto obj = injectedScript->wrapObject(&errorString, exception, V8Deb uggerAgentImpl::backtraceObjectGroup);
1536 m_breakAuxData = obj ? obj->serialize() : nullptr; 1638 m_breakAuxData = obj ? obj->serialize() : nullptr;
1537 // m_breakAuxData might be null after this. 1639 // m_breakAuxData might be null after this.
(...skipping 14 matching lines...) Expand all
1552 1654
1553 BreakpointSource source = breakpointIterator->second->second; 1655 BreakpointSource source = breakpointIterator->second->second;
1554 if (m_breakReason == protocol::Debugger::Paused::ReasonEnum::Other & & source == DebugCommandBreakpointSource) 1656 if (m_breakReason == protocol::Debugger::Paused::ReasonEnum::Other & & source == DebugCommandBreakpointSource)
1555 m_breakReason = protocol::Debugger::Paused::ReasonEnum::DebugCom mand; 1657 m_breakReason = protocol::Debugger::Paused::ReasonEnum::DebugCom mand;
1556 } 1658 }
1557 } 1659 }
1558 1660
1559 if (!m_asyncOperationNotifications.isEmpty()) 1661 if (!m_asyncOperationNotifications.isEmpty())
1560 flushAsyncOperationEvents(nullptr); 1662 flushAsyncOperationEvents(nullptr);
1561 1663
1562 m_frontend->paused(currentCallFrames(), m_breakReason, m_breakAuxData.releas e(), hitBreakpointIds.release(), currentAsyncStackTrace()); 1664 ErrorString errorString;
1665 m_frontend->paused(currentCallFrames(&errorString), m_breakReason, m_breakAu xData.release(), hitBreakpointIds.release(), currentAsyncStackTrace());
1563 m_scheduledDebuggerStep = NoStep; 1666 m_scheduledDebuggerStep = NoStep;
1564 m_javaScriptPauseScheduled = false; 1667 m_javaScriptPauseScheduled = false;
1565 m_steppingFromFramework = false; 1668 m_steppingFromFramework = false;
1566 m_pausingOnNativeEvent = false; 1669 m_pausingOnNativeEvent = false;
1567 m_skippedStepFrameCount = 0; 1670 m_skippedStepFrameCount = 0;
1568 m_recursionLevelForStepFrame = 0; 1671 m_recursionLevelForStepFrame = 0;
1569 clearStepIntoAsync(); 1672 clearStepIntoAsync();
1570 1673
1571 if (!m_continueToLocationBreakpointId.isEmpty()) { 1674 if (!m_continueToLocationBreakpointId.isEmpty()) {
1572 debugger().removeBreakpoint(m_continueToLocationBreakpointId); 1675 debugger().removeBreakpoint(m_continueToLocationBreakpointId);
1573 m_continueToLocationBreakpointId = ""; 1676 m_continueToLocationBreakpointId = "";
1574 } 1677 }
1575 return result; 1678 return result;
1576 } 1679 }
1577 1680
1578 void V8DebuggerAgentImpl::didContinue() 1681 void V8DebuggerAgentImpl::didContinue()
1579 { 1682 {
1580 m_pausedContext.Reset(); 1683 m_pausedContext.Reset();
1581 m_currentCallStack.Reset(); 1684 m_currentCallStack.clear();
1582 clearBreakDetails(); 1685 clearBreakDetails();
1583 m_frontend->resumed(); 1686 m_frontend->resumed();
1584 } 1687 }
1585 1688
1586 bool V8DebuggerAgentImpl::canBreakProgram() 1689 bool V8DebuggerAgentImpl::canBreakProgram()
1587 { 1690 {
1588 return debugger().canBreakProgram(); 1691 return debugger().canBreakProgram();
1589 } 1692 }
1590 1693
1591 void V8DebuggerAgentImpl::breakProgram(const String16& breakReason, PassOwnPtr<p rotocol::DictionaryValue> data) 1694 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; 1752 return;
1650 m_scheduledDebuggerStep = NoStep; 1753 m_scheduledDebuggerStep = NoStep;
1651 m_scripts.clear(); 1754 m_scripts.clear();
1652 m_blackboxedPositions.clear(); 1755 m_blackboxedPositions.clear();
1653 m_breakpointIdToDebuggerBreakpointIds.clear(); 1756 m_breakpointIdToDebuggerBreakpointIds.clear();
1654 resetAsyncCallTracker(); 1757 resetAsyncCallTracker();
1655 m_promiseTracker->clear(); 1758 m_promiseTracker->clear();
1656 } 1759 }
1657 1760
1658 } // namespace blink 1761 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698