OLD | NEW |
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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 if (!scope.object()->IsFunction()) { | 669 if (!scope.object()->IsFunction()) { |
672 *errorString = "Value with given id is not a function"; | 670 *errorString = "Value with given id is not a function"; |
673 return; | 671 return; |
674 } | 672 } |
675 v8::Local<v8::Function> function = scope.object().As<v8::Function>(); | 673 v8::Local<v8::Function> function = scope.object().As<v8::Function>(); |
676 | 674 |
677 v8::Local<v8::Value> scopesValue; | 675 v8::Local<v8::Value> scopesValue; |
678 v8::Local<v8::Array> scopes; | 676 v8::Local<v8::Array> scopes; |
679 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu
e->IsArray()) { | 677 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu
e->IsArray()) { |
680 scopes = scopesValue.As<v8::Array>(); | 678 scopes = scopesValue.As<v8::Array>(); |
681 if (!scope.injectedScript()->wrapPropertyInArray(errorString, scopes, to
V8StringInternalized(m_debugger->isolate(), "object"), scope.objectGroupName())) | 679 if (!scope.injectedScript()->wrapPropertyInArray(errorString, scopes, to
V8StringInternalized(m_isolate, "object"), scope.objectGroupName())) |
682 return; | 680 return; |
683 } | 681 } |
684 | 682 |
685 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create() | 683 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create() |
686 .setLocation(buildProtocolLocation(String16::number(function->ScriptId()
), function->GetScriptLineNumber(), function->GetScriptColumnNumber())) | 684 .setLocation(buildProtocolLocation(String16::number(function->ScriptId()
), function->GetScriptLineNumber(), function->GetScriptColumnNumber())) |
687 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName())
) | 685 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName())
) |
688 .setIsGenerator(function->IsGeneratorFunction()).build(); | 686 .setIsGenerator(function->IsGeneratorFunction()).build(); |
689 | 687 |
690 if (!scopes.IsEmpty()) { | 688 if (!scopes.IsEmpty()) { |
691 protocol::ErrorSupport errorSupport; | 689 protocol::ErrorSupport errorSupport; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 v8::Local<v8::Value> entriesValue = m_debugger->collectionEntries(object); | 740 v8::Local<v8::Value> entriesValue = m_debugger->collectionEntries(object); |
743 if (hasInternalError(errorString, entriesValue.IsEmpty())) | 741 if (hasInternalError(errorString, entriesValue.IsEmpty())) |
744 return; | 742 return; |
745 if (entriesValue->IsUndefined()) { | 743 if (entriesValue->IsUndefined()) { |
746 *errorString = "Object with given id is not a collection"; | 744 *errorString = "Object with given id is not a collection"; |
747 return; | 745 return; |
748 } | 746 } |
749 if (hasInternalError(errorString, !entriesValue->IsArray())) | 747 if (hasInternalError(errorString, !entriesValue->IsArray())) |
750 return; | 748 return; |
751 v8::Local<v8::Array> entriesArray = entriesValue.As<v8::Array>(); | 749 v8::Local<v8::Array> entriesArray = entriesValue.As<v8::Array>(); |
752 if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray,
toV8StringInternalized(m_debugger->isolate(), "key"), scope.objectGroupName())) | 750 if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray,
toV8StringInternalized(m_isolate, "key"), scope.objectGroupName())) |
753 return; | 751 return; |
754 if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray,
toV8StringInternalized(m_debugger->isolate(), "value"), scope.objectGroupName())
) | 752 if (!scope.injectedScript()->wrapPropertyInArray(errorString, entriesArray,
toV8StringInternalized(m_isolate, "value"), scope.objectGroupName())) |
755 return; | 753 return; |
756 protocol::ErrorSupport errors; | 754 protocol::ErrorSupport errors; |
757 OwnPtr<protocol::Array<CollectionEntry>> entries = protocol::Array<Collectio
nEntry>::parse(toProtocolValue(scope.context(), entriesArray).get(), &errors); | 755 OwnPtr<protocol::Array<CollectionEntry>> entries = protocol::Array<Collectio
nEntry>::parse(toProtocolValue(scope.context(), entriesArray).get(), &errors); |
758 if (hasInternalError(errorString, !entries)) | 756 if (hasInternalError(errorString, !entries)) |
759 return; | 757 return; |
760 *outEntries = entries.release(); | 758 *outEntries = entries.release(); |
761 } | 759 } |
762 | 760 |
763 void V8DebuggerAgentImpl::schedulePauseOnNextStatement(const String16& breakReas
on, PassOwnPtr<protocol::DictionaryValue> data) | 761 void V8DebuggerAgentImpl::schedulePauseOnNextStatement(const String16& breakReas
on, PassOwnPtr<protocol::DictionaryValue> data) |
764 { | 762 { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 if (!assertPaused(errorString)) | 915 if (!assertPaused(errorString)) |
918 return; | 916 return; |
919 InjectedScript::CallFrameScope scope(errorString, m_debugger, m_session->con
textGroupId(), callFrameId); | 917 InjectedScript::CallFrameScope scope(errorString, m_debugger, m_session->con
textGroupId(), callFrameId); |
920 if (!scope.initialize()) | 918 if (!scope.initialize()) |
921 return; | 919 return; |
922 if (scope.frameOrdinal() >= m_pausedCallFrames.size()) { | 920 if (scope.frameOrdinal() >= m_pausedCallFrames.size()) { |
923 *errorString = "Could not find call frame with given id"; | 921 *errorString = "Could not find call frame with given id"; |
924 return; | 922 return; |
925 } | 923 } |
926 | 924 |
927 if (includeCommandLineAPI.fromMaybe(false)) { | 925 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) |
928 v8::MaybeLocal<v8::Object> commandLineAPI = scope.injectedScript()->comm
andLineAPI(errorString); | 926 return; |
929 if (commandLineAPI.IsEmpty()) | 927 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
930 return; | 928 scope.ignoreExceptionsAndMuteConsole(); |
931 scope.installGlobalObjectExtension(commandLineAPI); | |
932 } | |
933 | 929 |
934 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon
sole.fromMaybe(false) ? m_debugger : nullptr); | 930 v8::MaybeLocal<v8::Value> maybeResultValue = m_pausedCallFrames[scope.frameO
rdinal()].get()->evaluate(toV8String(m_isolate, expression)); |
935 MuteConsoleScope muteConsoleScope(doNotPauseOnExceptionsAndMuteConsole.fromM
aybe(false) ? m_debugger : nullptr); | |
936 | |
937 v8::MaybeLocal<v8::Value> maybeResultValue = m_pausedCallFrames[scope.frameO
rdinal()].get()->evaluate(toV8String(m_debugger->isolate(), expression)); | |
938 | 931 |
939 // Re-initialize after running client's code, as it could have destroyed con
text or session. | 932 // Re-initialize after running client's code, as it could have destroyed con
text or session. |
940 if (!scope.initialize()) | 933 if (!scope.initialize()) |
941 return; | 934 return; |
942 scope.injectedScript()->wrapEvaluateResult(errorString, | 935 scope.injectedScript()->wrapEvaluateResult(errorString, |
943 maybeResultValue, | 936 maybeResultValue, |
944 scope.tryCatch(), | 937 scope.tryCatch(), |
945 objectGroup.fromMaybe(""), | 938 objectGroup.fromMaybe(""), |
946 returnByValue.fromMaybe(false), | 939 returnByValue.fromMaybe(false), |
947 generatePreview.fromMaybe(false), | 940 generatePreview.fromMaybe(false), |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 { | 1143 { |
1151 if (m_pausedContext.IsEmpty() || !m_pausedCallFrames.size()) | 1144 if (m_pausedContext.IsEmpty() || !m_pausedCallFrames.size()) |
1152 return Array<CallFrame>::create(); | 1145 return Array<CallFrame>::create(); |
1153 ErrorString ignored; | 1146 ErrorString ignored; |
1154 InjectedScript* topFrameInjectedScript = m_session->findInjectedScript(&igno
red, V8Debugger::contextId(m_pausedContext.Get(m_isolate))); | 1147 InjectedScript* topFrameInjectedScript = m_session->findInjectedScript(&igno
red, V8Debugger::contextId(m_pausedContext.Get(m_isolate))); |
1155 if (!topFrameInjectedScript) { | 1148 if (!topFrameInjectedScript) { |
1156 // Context has been reported as removed while on pause. | 1149 // Context has been reported as removed while on pause. |
1157 return Array<CallFrame>::create(); | 1150 return Array<CallFrame>::create(); |
1158 } | 1151 } |
1159 | 1152 |
1160 v8::Isolate* isolate = topFrameInjectedScript->isolate(); | 1153 v8::HandleScope handles(m_isolate); |
1161 v8::HandleScope handles(isolate); | |
1162 v8::Local<v8::Context> context = topFrameInjectedScript->context()->context(
); | 1154 v8::Local<v8::Context> context = topFrameInjectedScript->context()->context(
); |
1163 v8::Context::Scope contextScope(context); | 1155 v8::Context::Scope contextScope(context); |
1164 | 1156 |
1165 v8::Local<v8::Array> objects = v8::Array::New(isolate); | 1157 v8::Local<v8::Array> objects = v8::Array::New(m_isolate); |
1166 for (size_t frameOrdinal = 0; frameOrdinal < m_pausedCallFrames.size(); ++fr
ameOrdinal) { | 1158 for (size_t frameOrdinal = 0; frameOrdinal < m_pausedCallFrames.size(); ++fr
ameOrdinal) { |
1167 JavaScriptCallFrame* currentCallFrame = m_pausedCallFrames[frameOrdinal]
.get(); | 1159 JavaScriptCallFrame* currentCallFrame = m_pausedCallFrames[frameOrdinal]
.get(); |
1168 | 1160 |
1169 v8::Local<v8::Object> details = currentCallFrame->details(); | 1161 v8::Local<v8::Object> details = currentCallFrame->details(); |
1170 if (hasInternalError(errorString, details.IsEmpty())) | 1162 if (hasInternalError(errorString, details.IsEmpty())) |
1171 return Array<CallFrame>::create(); | 1163 return Array<CallFrame>::create(); |
1172 | 1164 |
1173 int contextId = currentCallFrame->contextId(); | 1165 int contextId = currentCallFrame->contextId(); |
1174 InjectedScript* injectedScript = contextId ? m_session->findInjectedScri
pt(&ignored, contextId) : nullptr; | 1166 InjectedScript* injectedScript = contextId ? m_session->findInjectedScri
pt(&ignored, contextId) : nullptr; |
1175 if (!injectedScript) | 1167 if (!injectedScript) |
1176 injectedScript = topFrameInjectedScript; | 1168 injectedScript = topFrameInjectedScript; |
1177 | 1169 |
1178 String16 callFrameId = RemoteCallFrameId::serialize(injectedScript->cont
ext()->contextId(), frameOrdinal); | 1170 String16 callFrameId = RemoteCallFrameId::serialize(injectedScript->cont
ext()->contextId(), frameOrdinal); |
1179 if (hasInternalError(errorString, !details->Set(context, toV8StringInter
nalized(isolate, "callFrameId"), toV8String(isolate, callFrameId)).FromMaybe(fal
se))) | 1171 if (hasInternalError(errorString, !details->Set(context, toV8StringInter
nalized(m_isolate, "callFrameId"), toV8String(m_isolate, callFrameId)).FromMaybe
(false))) |
1180 return Array<CallFrame>::create(); | 1172 return Array<CallFrame>::create(); |
1181 | 1173 |
1182 v8::Local<v8::Value> scopeChain; | 1174 v8::Local<v8::Value> scopeChain; |
1183 if (hasInternalError(errorString, !details->Get(context, toV8StringInter
nalized(isolate, "scopeChain")).ToLocal(&scopeChain) || !scopeChain->IsArray())) | 1175 if (hasInternalError(errorString, !details->Get(context, toV8StringInter
nalized(m_isolate, "scopeChain")).ToLocal(&scopeChain) || !scopeChain->IsArray()
)) |
1184 return Array<CallFrame>::create(); | 1176 return Array<CallFrame>::create(); |
1185 v8::Local<v8::Array> scopeChainArray = scopeChain.As<v8::Array>(); | 1177 v8::Local<v8::Array> scopeChainArray = scopeChain.As<v8::Array>(); |
1186 if (!injectedScript->wrapPropertyInArray(errorString, scopeChainArray, t
oV8StringInternalized(isolate, "object"), V8DebuggerAgentImpl::backtraceObjectGr
oup)) | 1178 if (!injectedScript->wrapPropertyInArray(errorString, scopeChainArray, t
oV8StringInternalized(m_isolate, "object"), V8DebuggerAgentImpl::backtraceObject
Group)) |
1187 return Array<CallFrame>::create(); | 1179 return Array<CallFrame>::create(); |
1188 | 1180 |
1189 if (!injectedScript->wrapObjectProperty(errorString, details, toV8String
Internalized(isolate, "this"), V8DebuggerAgentImpl::backtraceObjectGroup)) | 1181 if (!injectedScript->wrapObjectProperty(errorString, details, toV8String
Internalized(m_isolate, "this"), V8DebuggerAgentImpl::backtraceObjectGroup)) |
1190 return Array<CallFrame>::create(); | 1182 return Array<CallFrame>::create(); |
1191 | 1183 |
1192 if (details->Has(context, toV8StringInternalized(isolate, "returnValue")
).FromMaybe(false)) { | 1184 if (details->Has(context, toV8StringInternalized(m_isolate, "returnValue
")).FromMaybe(false)) { |
1193 if (!injectedScript->wrapObjectProperty(errorString, details, toV8St
ringInternalized(isolate, "returnValue"), V8DebuggerAgentImpl::backtraceObjectGr
oup)) | 1185 if (!injectedScript->wrapObjectProperty(errorString, details, toV8St
ringInternalized(m_isolate, "returnValue"), V8DebuggerAgentImpl::backtraceObject
Group)) |
1194 return Array<CallFrame>::create(); | 1186 return Array<CallFrame>::create(); |
1195 } | 1187 } |
1196 | 1188 |
1197 if (hasInternalError(errorString, !objects->Set(context, frameOrdinal, d
etails).FromMaybe(false))) | 1189 if (hasInternalError(errorString, !objects->Set(context, frameOrdinal, d
etails).FromMaybe(false))) |
1198 return Array<CallFrame>::create(); | 1190 return Array<CallFrame>::create(); |
1199 } | 1191 } |
1200 | 1192 |
1201 protocol::ErrorSupport errorSupport; | 1193 protocol::ErrorSupport errorSupport; |
1202 OwnPtr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(toProtocolValu
e(context, objects).get(), &errorSupport); | 1194 OwnPtr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(toProtocolValu
e(context, objects).get(), &errorSupport); |
1203 if (hasInternalError(errorString, !callFrames)) | 1195 if (hasInternalError(errorString, !callFrames)) |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1424 if (!enabled()) | 1416 if (!enabled()) |
1425 return; | 1417 return; |
1426 m_scheduledDebuggerStep = NoStep; | 1418 m_scheduledDebuggerStep = NoStep; |
1427 m_scripts.clear(); | 1419 m_scripts.clear(); |
1428 m_blackboxedPositions.clear(); | 1420 m_blackboxedPositions.clear(); |
1429 m_breakpointIdToDebuggerBreakpointIds.clear(); | 1421 m_breakpointIdToDebuggerBreakpointIds.clear(); |
1430 allAsyncTasksCanceled(); | 1422 allAsyncTasksCanceled(); |
1431 } | 1423 } |
1432 | 1424 |
1433 } // namespace blink | 1425 } // namespace blink |
OLD | NEW |