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

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

Issue 1877203004: [DevTools] Follow up with cleanups for InjectedScript::Scope. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ASSERT Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" 5 #include "platform/v8_inspector/V8DebuggerAgentImpl.h"
6 6
7 #include "platform/inspector_protocol/String16.h" 7 #include "platform/inspector_protocol/String16.h"
8 #include "platform/inspector_protocol/Values.h" 8 #include "platform/inspector_protocol/Values.h"
9 #include "platform/v8_inspector/IgnoreExceptionsScope.h"
10 #include "platform/v8_inspector/InjectedScript.h" 9 #include "platform/v8_inspector/InjectedScript.h"
11 #include "platform/v8_inspector/InspectedContext.h" 10 #include "platform/v8_inspector/InspectedContext.h"
12 #include "platform/v8_inspector/JavaScriptCallFrame.h" 11 #include "platform/v8_inspector/JavaScriptCallFrame.h"
13 #include "platform/v8_inspector/MuteConsoleScope.h"
14 #include "platform/v8_inspector/RemoteObjectId.h" 12 #include "platform/v8_inspector/RemoteObjectId.h"
15 #include "platform/v8_inspector/ScriptBreakpoint.h" 13 #include "platform/v8_inspector/ScriptBreakpoint.h"
16 #include "platform/v8_inspector/V8InspectorSessionImpl.h" 14 #include "platform/v8_inspector/V8InspectorSessionImpl.h"
17 #include "platform/v8_inspector/V8Regex.h" 15 #include "platform/v8_inspector/V8Regex.h"
18 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" 16 #include "platform/v8_inspector/V8RuntimeAgentImpl.h"
19 #include "platform/v8_inspector/V8StackTraceImpl.h" 17 #include "platform/v8_inspector/V8StackTraceImpl.h"
20 #include "platform/v8_inspector/V8StringUtil.h" 18 #include "platform/v8_inspector/V8StringUtil.h"
21 #include "platform/v8_inspector/public/V8ContentSearchUtil.h" 19 #include "platform/v8_inspector/public/V8ContentSearchUtil.h"
22 #include "platform/v8_inspector/public/V8Debugger.h" 20 #include "platform/v8_inspector/public/V8Debugger.h"
23 #include "platform/v8_inspector/public/V8DebuggerClient.h" 21 #include "platform/v8_inspector/public/V8DebuggerClient.h"
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 if (!scope.object()->IsFunction()) { 668 if (!scope.object()->IsFunction()) {
671 *errorString = "Value with given id is not a function"; 669 *errorString = "Value with given id is not a function";
672 return; 670 return;
673 } 671 }
674 v8::Local<v8::Function> function = scope.object().As<v8::Function>(); 672 v8::Local<v8::Function> function = scope.object().As<v8::Function>();
675 673
676 v8::Local<v8::Value> scopesValue; 674 v8::Local<v8::Value> scopesValue;
677 v8::Local<v8::Array> scopes; 675 v8::Local<v8::Array> scopes;
678 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu e->IsArray()) { 676 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu e->IsArray()) {
679 scopes = scopesValue.As<v8::Array>(); 677 scopes = scopesValue.As<v8::Array>();
680 if (!scope.injectedScript()->wrapPropertyInArray(errorString, scopes, to V8StringInternalized(m_debugger->isolate(), "object"), scope.objectGroupName())) 678 if (!scope.injectedScript()->wrapPropertyInArray(errorString, scopes, to V8StringInternalized(m_isolate, "object"), scope.objectGroupName()))
681 return; 679 return;
682 } 680 }
683 681
684 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create() 682 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create()
685 .setLocation(buildProtocolLocation(String16::number(function->ScriptId() ), function->GetScriptLineNumber(), function->GetScriptColumnNumber())) 683 .setLocation(buildProtocolLocation(String16::number(function->ScriptId() ), function->GetScriptLineNumber(), function->GetScriptColumnNumber()))
686 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName()) ) 684 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName()) )
687 .setIsGenerator(function->IsGeneratorFunction()).build(); 685 .setIsGenerator(function->IsGeneratorFunction()).build();
688 686
689 if (!scopes.IsEmpty()) { 687 if (!scopes.IsEmpty()) {
690 protocol::ErrorSupport errorSupport; 688 protocol::ErrorSupport errorSupport;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 v8::Local<v8::Value> entriesValue = m_debugger->collectionEntries(object); 739 v8::Local<v8::Value> entriesValue = m_debugger->collectionEntries(object);
742 if (hasInternalError(errorString, entriesValue.IsEmpty())) 740 if (hasInternalError(errorString, entriesValue.IsEmpty()))
743 return; 741 return;
744 if (entriesValue->IsUndefined()) { 742 if (entriesValue->IsUndefined()) {
745 *errorString = "Object with given id is not a collection"; 743 *errorString = "Object with given id is not a collection";
746 return; 744 return;
747 } 745 }
748 if (hasInternalError(errorString, !entriesValue->IsArray())) 746 if (hasInternalError(errorString, !entriesValue->IsArray()))
749 return; 747 return;
750 v8::Local<v8::Array> entriesArray = entriesValue.As<v8::Array>(); 748 v8::Local<v8::Array> entriesArray = entriesValue.As<v8::Array>();
751 if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray, toV8StringInternalized(m_debugger->isolate(), "key"), scope.objectGroupName())) 749 if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray, toV8StringInternalized(m_isolate, "key"), scope.objectGroupName()))
752 return; 750 return;
753 if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray, toV8StringInternalized(m_debugger->isolate(), "value"), scope.objectGroupName()) ) 751 if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray, toV8StringInternalized(m_isolate, "value"), scope.objectGroupName()))
754 return; 752 return;
755 protocol::ErrorSupport errors; 753 protocol::ErrorSupport errors;
756 OwnPtr<protocol::Array<CollectionEntry>> entries = protocol::Array<Collectio nEntry>::parse(toProtocolValue(scope.context(), entriesArray).get(), &errors); 754 OwnPtr<protocol::Array<CollectionEntry>> entries = protocol::Array<Collectio nEntry>::parse(toProtocolValue(scope.context(), entriesArray).get(), &errors);
757 if (hasInternalError(errorString, !entries)) 755 if (hasInternalError(errorString, !entries))
758 return; 756 return;
759 *outEntries = entries.release(); 757 *outEntries = entries.release();
760 } 758 }
761 759
762 void V8DebuggerAgentImpl::schedulePauseOnNextStatement(const String16& breakReas on, PassOwnPtr<protocol::DictionaryValue> data) 760 void V8DebuggerAgentImpl::schedulePauseOnNextStatement(const String16& breakReas on, PassOwnPtr<protocol::DictionaryValue> data)
763 { 761 {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 if (!assertPaused(errorString)) 914 if (!assertPaused(errorString))
917 return; 915 return;
918 InjectedScript::CallFrameScope scope(errorString, m_debugger, m_session->con textGroupId(), callFrameId); 916 InjectedScript::CallFrameScope scope(errorString, m_debugger, m_session->con textGroupId(), callFrameId);
919 if (!scope.initialize()) 917 if (!scope.initialize())
920 return; 918 return;
921 if (scope.frameOrdinal() >= m_pausedCallFrames.size()) { 919 if (scope.frameOrdinal() >= m_pausedCallFrames.size()) {
922 *errorString = "Could not find call frame with given id"; 920 *errorString = "Could not find call frame with given id";
923 return; 921 return;
924 } 922 }
925 923
926 if (includeCommandLineAPI.fromMaybe(false)) { 924 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI() )
927 v8::MaybeLocal<v8::Object> commandLineAPI = scope.injectedScript()->comm andLineAPI(errorString); 925 return;
928 if (commandLineAPI.IsEmpty()) 926 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false))
929 return; 927 scope.ignoreExceptionsAndMuteConsole();
930 scope.installGlobalObjectExtension(commandLineAPI);
931 }
932 928
933 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); 929 v8::MaybeLocal<v8::Value> maybeResultValue = m_pausedCallFrames[scope.frameO rdinal()].get()->evaluate(toV8String(m_isolate, expression));
934 MuteConsoleScope muteConsoleScope(doNotPauseOnExceptionsAndMuteConsole.fromM aybe(false) ? m_debugger : nullptr);
935
936 v8::MaybeLocal<v8::Value> maybeResultValue = m_pausedCallFrames[scope.frameO rdinal()].get()->evaluate(toV8String(m_debugger->isolate(), expression));
937 930
938 // Re-initialize after running client's code, as it could have destroyed con text or session. 931 // Re-initialize after running client's code, as it could have destroyed con text or session.
939 if (!scope.initialize()) 932 if (!scope.initialize())
940 return; 933 return;
941 scope.injectedScript()->wrapEvaluateResult(errorString, 934 scope.injectedScript()->wrapEvaluateResult(errorString,
942 maybeResultValue, 935 maybeResultValue,
943 scope.tryCatch(), 936 scope.tryCatch(),
944 objectGroup.fromMaybe(""), 937 objectGroup.fromMaybe(""),
945 returnByValue.fromMaybe(false), 938 returnByValue.fromMaybe(false),
946 generatePreview.fromMaybe(false), 939 generatePreview.fromMaybe(false),
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 { 1142 {
1150 if (m_pausedContext.IsEmpty() || !m_pausedCallFrames.size()) 1143 if (m_pausedContext.IsEmpty() || !m_pausedCallFrames.size())
1151 return Array<CallFrame>::create(); 1144 return Array<CallFrame>::create();
1152 ErrorString ignored; 1145 ErrorString ignored;
1153 InjectedScript* topFrameInjectedScript = m_session->findInjectedScript(&igno red, V8Debugger::contextId(m_pausedContext.Get(m_isolate))); 1146 InjectedScript* topFrameInjectedScript = m_session->findInjectedScript(&igno red, V8Debugger::contextId(m_pausedContext.Get(m_isolate)));
1154 if (!topFrameInjectedScript) { 1147 if (!topFrameInjectedScript) {
1155 // Context has been reported as removed while on pause. 1148 // Context has been reported as removed while on pause.
1156 return Array<CallFrame>::create(); 1149 return Array<CallFrame>::create();
1157 } 1150 }
1158 1151
1159 v8::Isolate* isolate = topFrameInjectedScript->isolate(); 1152 v8::HandleScope handles(m_isolate);
1160 v8::HandleScope handles(isolate);
1161 v8::Local<v8::Context> context = topFrameInjectedScript->context()->context( ); 1153 v8::Local<v8::Context> context = topFrameInjectedScript->context()->context( );
1162 v8::Context::Scope contextScope(context); 1154 v8::Context::Scope contextScope(context);
1163 1155
1164 v8::Local<v8::Array> objects = v8::Array::New(isolate); 1156 v8::Local<v8::Array> objects = v8::Array::New(m_isolate);
1165 for (size_t frameOrdinal = 0; frameOrdinal < m_pausedCallFrames.size(); ++fr ameOrdinal) { 1157 for (size_t frameOrdinal = 0; frameOrdinal < m_pausedCallFrames.size(); ++fr ameOrdinal) {
1166 JavaScriptCallFrame* currentCallFrame = m_pausedCallFrames[frameOrdinal] .get(); 1158 JavaScriptCallFrame* currentCallFrame = m_pausedCallFrames[frameOrdinal] .get();
1167 1159
1168 v8::Local<v8::Object> details = currentCallFrame->details(); 1160 v8::Local<v8::Object> details = currentCallFrame->details();
1169 if (hasInternalError(errorString, details.IsEmpty())) 1161 if (hasInternalError(errorString, details.IsEmpty()))
1170 return Array<CallFrame>::create(); 1162 return Array<CallFrame>::create();
1171 1163
1172 int contextId = currentCallFrame->contextId(); 1164 int contextId = currentCallFrame->contextId();
1173 InjectedScript* injectedScript = contextId ? m_session->findInjectedScri pt(&ignored, contextId) : nullptr; 1165 InjectedScript* injectedScript = contextId ? m_session->findInjectedScri pt(&ignored, contextId) : nullptr;
1174 if (!injectedScript) 1166 if (!injectedScript)
1175 injectedScript = topFrameInjectedScript; 1167 injectedScript = topFrameInjectedScript;
1176 1168
1177 String16 callFrameId = RemoteCallFrameId::serialize(injectedScript->cont ext()->contextId(), frameOrdinal); 1169 String16 callFrameId = RemoteCallFrameId::serialize(injectedScript->cont ext()->contextId(), frameOrdinal);
1178 if (hasInternalError(errorString, !details->Set(context, toV8StringInter nalized(isolate, "callFrameId"), toV8String(isolate, callFrameId)).FromMaybe(fal se))) 1170 if (hasInternalError(errorString, !details->Set(context, toV8StringInter nalized(m_isolate, "callFrameId"), toV8String(m_isolate, callFrameId)).FromMaybe (false)))
1179 return Array<CallFrame>::create(); 1171 return Array<CallFrame>::create();
1180 1172
1181 v8::Local<v8::Value> scopeChain; 1173 v8::Local<v8::Value> scopeChain;
1182 if (hasInternalError(errorString, !details->Get(context, toV8StringInter nalized(isolate, "scopeChain")).ToLocal(&scopeChain) || !scopeChain->IsArray())) 1174 if (hasInternalError(errorString, !details->Get(context, toV8StringInter nalized(m_isolate, "scopeChain")).ToLocal(&scopeChain) || !scopeChain->IsArray() ))
1183 return Array<CallFrame>::create(); 1175 return Array<CallFrame>::create();
1184 v8::Local<v8::Array> scopeChainArray = scopeChain.As<v8::Array>(); 1176 v8::Local<v8::Array> scopeChainArray = scopeChain.As<v8::Array>();
1185 if (!injectedScript->wrapPropertyInArray(errorString, scopeChainArray, t oV8StringInternalized(isolate, "object"), V8DebuggerAgentImpl::backtraceObjectGr oup)) 1177 if (!injectedScript->wrapPropertyInArray(errorString, scopeChainArray, t oV8StringInternalized(m_isolate, "object"), V8DebuggerAgentImpl::backtraceObject Group))
1186 return Array<CallFrame>::create(); 1178 return Array<CallFrame>::create();
1187 1179
1188 if (!injectedScript->wrapObjectProperty(errorString, details, toV8String Internalized(isolate, "this"), V8DebuggerAgentImpl::backtraceObjectGroup)) 1180 if (!injectedScript->wrapObjectProperty(errorString, details, toV8String Internalized(m_isolate, "this"), V8DebuggerAgentImpl::backtraceObjectGroup))
1189 return Array<CallFrame>::create(); 1181 return Array<CallFrame>::create();
1190 1182
1191 if (details->Has(context, toV8StringInternalized(isolate, "returnValue") ).FromMaybe(false)) { 1183 if (details->Has(context, toV8StringInternalized(m_isolate, "returnValue ")).FromMaybe(false)) {
1192 if (!injectedScript->wrapObjectProperty(errorString, details, toV8St ringInternalized(isolate, "returnValue"), V8DebuggerAgentImpl::backtraceObjectGr oup)) 1184 if (!injectedScript->wrapObjectProperty(errorString, details, toV8St ringInternalized(m_isolate, "returnValue"), V8DebuggerAgentImpl::backtraceObject Group))
1193 return Array<CallFrame>::create(); 1185 return Array<CallFrame>::create();
1194 } 1186 }
1195 1187
1196 if (hasInternalError(errorString, !objects->Set(context, frameOrdinal, d etails).FromMaybe(false))) 1188 if (hasInternalError(errorString, !objects->Set(context, frameOrdinal, d etails).FromMaybe(false)))
1197 return Array<CallFrame>::create(); 1189 return Array<CallFrame>::create();
1198 } 1190 }
1199 1191
1200 protocol::ErrorSupport errorSupport; 1192 protocol::ErrorSupport errorSupport;
1201 OwnPtr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(toProtocolValu e(context, objects).get(), &errorSupport); 1193 OwnPtr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(toProtocolValu e(context, objects).get(), &errorSupport);
1202 if (hasInternalError(errorString, !callFrames)) 1194 if (hasInternalError(errorString, !callFrames))
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 if (!enabled()) 1414 if (!enabled())
1423 return; 1415 return;
1424 m_scheduledDebuggerStep = NoStep; 1416 m_scheduledDebuggerStep = NoStep;
1425 m_scripts.clear(); 1417 m_scripts.clear();
1426 m_blackboxedPositions.clear(); 1418 m_blackboxedPositions.clear();
1427 m_breakpointIdToDebuggerBreakpointIds.clear(); 1419 m_breakpointIdToDebuggerBreakpointIds.clear();
1428 allAsyncTasksCanceled(); 1420 allAsyncTasksCanceled();
1429 } 1421 }
1430 1422
1431 } // namespace blink 1423 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698