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" | 9 #include "platform/v8_inspector/IgnoreExceptionsScope.h" |
10 #include "platform/v8_inspector/InjectedScript.h" | 10 #include "platform/v8_inspector/InjectedScript.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 for (size_t i = 0; i < hashesSize; ++i) | 137 for (size_t i = 0; i < hashesSize; ++i) |
138 hashes[i] = (hashes[i] + zi[i] * (prime[i] - 1)) % prime[i]; | 138 hashes[i] = (hashes[i] + zi[i] * (prime[i] - 1)) % prime[i]; |
139 | 139 |
140 String16Builder hash; | 140 String16Builder hash; |
141 for (size_t i = 0; i < hashesSize; ++i) | 141 for (size_t i = 0; i < hashesSize; ++i) |
142 appendUnsignedAsHex(hashes[i], &hash); | 142 appendUnsignedAsHex(hashes[i], &hash); |
143 return hash.toString(); | 143 return hash.toString(); |
144 } | 144 } |
145 | 145 |
| 146 static bool hasInternalError(ErrorString* errorString, bool hasError) |
| 147 { |
| 148 if (hasError) |
| 149 *errorString = "Internal error"; |
| 150 return hasError; |
| 151 } |
| 152 |
146 PassOwnPtr<V8DebuggerAgent> V8DebuggerAgent::create(V8RuntimeAgent* runtimeAgent
) | 153 PassOwnPtr<V8DebuggerAgent> V8DebuggerAgent::create(V8RuntimeAgent* runtimeAgent
) |
147 { | 154 { |
148 V8RuntimeAgentImpl* runtimeAgentImpl = static_cast<V8RuntimeAgentImpl*>(runt
imeAgent); | 155 V8RuntimeAgentImpl* runtimeAgentImpl = static_cast<V8RuntimeAgentImpl*>(runt
imeAgent); |
149 return adoptPtr(new V8DebuggerAgentImpl(runtimeAgentImpl->getInjectedScriptM
anager(), runtimeAgentImpl->debugger(), runtimeAgentImpl->contextGroupId())); | 156 return adoptPtr(new V8DebuggerAgentImpl(runtimeAgentImpl->getInjectedScriptM
anager(), runtimeAgentImpl->debugger(), runtimeAgentImpl->contextGroupId())); |
150 } | 157 } |
151 | 158 |
152 V8DebuggerAgentImpl::V8DebuggerAgentImpl(InjectedScriptManager* injectedScriptMa
nager, V8DebuggerImpl* debugger, int contextGroupId) | 159 V8DebuggerAgentImpl::V8DebuggerAgentImpl(InjectedScriptManager* injectedScriptMa
nager, V8DebuggerImpl* debugger, int contextGroupId) |
153 : m_injectedScriptManager(injectedScriptManager) | 160 : m_injectedScriptManager(injectedScriptManager) |
154 , m_debugger(debugger) | 161 , m_debugger(debugger) |
155 , m_contextGroupId(contextGroupId) | 162 , m_contextGroupId(contextGroupId) |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 if (!injectedScript->findObject(errorString, *remoteId, &value)) | 702 if (!injectedScript->findObject(errorString, *remoteId, &value)) |
696 return; | 703 return; |
697 if (!value->IsFunction()) { | 704 if (!value->IsFunction()) { |
698 *errorString = "Value with given id is not a function"; | 705 *errorString = "Value with given id is not a function"; |
699 return; | 706 return; |
700 } | 707 } |
701 v8::Local<v8::Function> function = value.As<v8::Function>(); | 708 v8::Local<v8::Function> function = value.As<v8::Function>(); |
702 | 709 |
703 v8::Local<v8::Value> scopesValue; | 710 v8::Local<v8::Value> scopesValue; |
704 v8::Local<v8::Array> scopes; | 711 v8::Local<v8::Array> scopes; |
705 String16 objectGroupName = injectedScript->objectGroupName(*remoteId); | 712 String16 groupName = injectedScript->objectGroupName(*remoteId); |
706 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu
e->IsArray()) { | 713 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu
e->IsArray()) { |
707 scopes = scopesValue.As<v8::Array>(); | 714 scopes = scopesValue.As<v8::Array>(); |
708 for (size_t i = 0; i < scopes->Length(); ++i) { | 715 if (!injectedScript->wrapPropertyInArray(errorString, scopes, toV8String
Internalized(injectedScript->isolate(), "object"), groupName)) |
709 v8::Local<v8::Value> scope; | 716 return; |
710 if (!scopes->Get(injectedScript->context(), i).ToLocal(&scope) || !s
cope->IsObject()) { | |
711 *errorString = "Internal error"; | |
712 return; | |
713 } | |
714 if (!injectedScript->wrapObjectProperty(errorString, scope.As<v8::Ob
ject>(), toV8String(injectedScript->isolate(), "object"), objectGroupName)) | |
715 return; | |
716 } | |
717 } | 717 } |
718 | 718 |
719 OwnPtr<protocol::Debugger::Location> location = protocol::Debugger::Location
::create() | 719 OwnPtr<protocol::Debugger::Location> location = protocol::Debugger::Location
::create() |
720 .setScriptId(String16::number(function->ScriptId())) | 720 .setScriptId(String16::number(function->ScriptId())) |
721 .setLineNumber(function->GetScriptLineNumber()) | 721 .setLineNumber(function->GetScriptLineNumber()) |
722 .setColumnNumber(function->GetScriptColumnNumber()).build(); | 722 .setColumnNumber(function->GetScriptColumnNumber()).build(); |
723 | 723 |
724 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create() | 724 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create() |
725 .setLocation(location.release()) | 725 .setLocation(location.release()) |
726 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName())
) | 726 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName())
) |
727 .setIsGenerator(function->IsGeneratorFunction()).build(); | 727 .setIsGenerator(function->IsGeneratorFunction()).build(); |
728 | 728 |
729 if (!scopes.IsEmpty()) { | 729 if (!scopes.IsEmpty()) { |
730 protocol::ErrorSupport errorSupport; | 730 protocol::ErrorSupport errorSupport; |
731 OwnPtr<protocol::Array<protocol::Debugger::Scope>> scopeChain = protocol
::Array<protocol::Debugger::Scope>::parse(toProtocolValue(injectedScript->contex
t(), scopes).get(), &errorSupport); | 731 OwnPtr<protocol::Array<protocol::Debugger::Scope>> scopeChain = protocol
::Array<protocol::Debugger::Scope>::parse(toProtocolValue(injectedScript->contex
t(), scopes).get(), &errorSupport); |
732 if (errorSupport.hasErrors()) { | 732 if (hasInternalError(errorString, errorSupport.hasErrors())) |
733 *errorString = "Internal error"; | |
734 return; | 733 return; |
735 } | |
736 functionDetails->setScopeChain(scopeChain.release()); | 734 functionDetails->setScopeChain(scopeChain.release()); |
737 } | 735 } |
738 | 736 |
739 *details = functionDetails.release(); | 737 *details = functionDetails.release(); |
740 } | 738 } |
741 | 739 |
742 void V8DebuggerAgentImpl::getGeneratorObjectDetails(ErrorString* errorString, co
nst String16& objectId, OwnPtr<GeneratorObjectDetails>* outDetails) | 740 void V8DebuggerAgentImpl::getGeneratorObjectDetails(ErrorString* errorString, co
nst String16& objectId, OwnPtr<GeneratorObjectDetails>* outDetails) |
743 { | 741 { |
744 if (!checkEnabled(errorString)) | 742 if (!checkEnabled(errorString)) |
745 return; | 743 return; |
(...skipping 12 matching lines...) Expand all Loading... |
758 v8::Local<v8::Value> value; | 756 v8::Local<v8::Value> value; |
759 if (!injectedScript->findObject(errorString, *remoteId, &value)) | 757 if (!injectedScript->findObject(errorString, *remoteId, &value)) |
760 return; | 758 return; |
761 if (!value->IsObject() || !value->ToObject(context).ToLocal(&object)) { | 759 if (!value->IsObject() || !value->ToObject(context).ToLocal(&object)) { |
762 *errorString = "Value with given id is not an Object"; | 760 *errorString = "Value with given id is not an Object"; |
763 return; | 761 return; |
764 } | 762 } |
765 | 763 |
766 v8::Local<v8::Object> detailsObject; | 764 v8::Local<v8::Object> detailsObject; |
767 v8::Local<v8::Value> detailsValue = debugger().generatorObjectDetails(object
); | 765 v8::Local<v8::Value> detailsValue = debugger().generatorObjectDetails(object
); |
768 if (!detailsValue->IsObject() || !detailsValue->ToObject(context).ToLocal(&d
etailsObject)) { | 766 if (hasInternalError(errorString, !detailsValue->IsObject() || !detailsValue
->ToObject(context).ToLocal(&detailsObject))) |
769 *errorString = "Internal error"; | |
770 return; | 767 return; |
771 } | |
772 | 768 |
773 String16 groupName = injectedScript->objectGroupName(*remoteId); | 769 String16 groupName = injectedScript->objectGroupName(*remoteId); |
774 if (!injectedScript->wrapObjectProperty(errorString, detailsObject, toV8Stri
ng(m_isolate, "function"), groupName)) | 770 if (!injectedScript->wrapObjectProperty(errorString, detailsObject, toV8Stri
ngInternalized(m_isolate, "function"), groupName)) |
775 return; | 771 return; |
776 | 772 |
777 protocol::ErrorSupport errors; | 773 protocol::ErrorSupport errors; |
778 OwnPtr<GeneratorObjectDetails> protocolDetails = GeneratorObjectDetails::par
se(toProtocolValue(context, detailsObject).get(), &errors); | 774 OwnPtr<GeneratorObjectDetails> protocolDetails = GeneratorObjectDetails::par
se(toProtocolValue(context, detailsObject).get(), &errors); |
779 if (!protocolDetails) { | 775 if (hasInternalError(errorString, !protocolDetails)) |
780 *errorString = "Internal error"; | |
781 return; | 776 return; |
782 } | |
783 *outDetails = protocolDetails.release(); | 777 *outDetails = protocolDetails.release(); |
784 } | 778 } |
785 | 779 |
786 void V8DebuggerAgentImpl::getCollectionEntries(ErrorString* errorString, const S
tring16& objectId, OwnPtr<protocol::Array<CollectionEntry>>* entries) | 780 void V8DebuggerAgentImpl::getCollectionEntries(ErrorString* errorString, const S
tring16& objectId, OwnPtr<protocol::Array<CollectionEntry>>* outEntries) |
787 { | 781 { |
788 if (!checkEnabled(errorString)) | 782 if (!checkEnabled(errorString)) |
789 return; | 783 return; |
790 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI
d); | 784 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI
d); |
791 if (!remoteId) | 785 if (!remoteId) |
792 return; | 786 return; |
793 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(errorString, remoteId.get()); | 787 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(errorString, remoteId.get()); |
794 if (!injectedScript) | 788 if (!injectedScript) |
795 return; | 789 return; |
796 injectedScript->getCollectionEntries(errorString, objectId, entries); | 790 |
| 791 v8::HandleScope scope(m_isolate); |
| 792 v8::Local<v8::Context> context = injectedScript->context(); |
| 793 v8::Context::Scope contextScope(context); |
| 794 |
| 795 v8::Local<v8::Value> value; |
| 796 if (!injectedScript->findObject(errorString, *remoteId, &value)) |
| 797 return; |
| 798 if (!value->IsObject()) { |
| 799 *errorString = "Object with given id is not a collection"; |
| 800 return; |
| 801 } |
| 802 v8::Local<v8::Object> object = value.As<v8::Object>(); |
| 803 v8::Local<v8::Value> entriesValue = m_debugger->collectionEntries(object); |
| 804 if (hasInternalError(errorString, entriesValue.IsEmpty())) |
| 805 return; |
| 806 if (entriesValue->IsUndefined()) { |
| 807 *errorString = "Object with given id is not a collection"; |
| 808 return; |
| 809 } |
| 810 if (hasInternalError(errorString, !entriesValue->IsArray())) |
| 811 return; |
| 812 String16 groupName = injectedScript->objectGroupName(*remoteId); |
| 813 v8::Local<v8::Array> entriesArray = entriesValue.As<v8::Array>(); |
| 814 if (!injectedScript->wrapPropertyInArray(errorString, entriesArray, toV8Stri
ngInternalized(injectedScript->isolate(), "key"), groupName)) |
| 815 return; |
| 816 if (!injectedScript->wrapPropertyInArray(errorString, entriesArray, toV8Stri
ngInternalized(injectedScript->isolate(), "value"), groupName)) |
| 817 return; |
| 818 protocol::ErrorSupport errors; |
| 819 OwnPtr<protocol::Array<CollectionEntry>> entries = protocol::Array<Collectio
nEntry>::parse(toProtocolValue(injectedScript->context(), entriesArray).get(), &
errors); |
| 820 if (hasInternalError(errorString, !entries)) |
| 821 return; |
| 822 *outEntries = entries.release(); |
797 } | 823 } |
798 | 824 |
799 void V8DebuggerAgentImpl::schedulePauseOnNextStatement(const String16& breakReas
on, PassOwnPtr<protocol::DictionaryValue> data) | 825 void V8DebuggerAgentImpl::schedulePauseOnNextStatement(const String16& breakReas
on, PassOwnPtr<protocol::DictionaryValue> data) |
800 { | 826 { |
801 ASSERT(enabled()); | 827 ASSERT(enabled()); |
802 if (m_scheduledDebuggerStep == StepInto || m_javaScriptPauseScheduled || isP
aused()) | 828 if (m_scheduledDebuggerStep == StepInto || m_javaScriptPauseScheduled || isP
aused()) |
803 return; | 829 return; |
804 m_breakReason = breakReason; | 830 m_breakReason = breakReason; |
805 m_breakAuxData = data; | 831 m_breakAuxData = data; |
806 m_pausingOnNativeEvent = true; | 832 m_pausingOnNativeEvent = true; |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 return; | 1649 return; |
1624 m_scheduledDebuggerStep = NoStep; | 1650 m_scheduledDebuggerStep = NoStep; |
1625 m_scripts.clear(); | 1651 m_scripts.clear(); |
1626 m_blackboxedPositions.clear(); | 1652 m_blackboxedPositions.clear(); |
1627 m_breakpointIdToDebuggerBreakpointIds.clear(); | 1653 m_breakpointIdToDebuggerBreakpointIds.clear(); |
1628 resetAsyncCallTracker(); | 1654 resetAsyncCallTracker(); |
1629 m_promiseTracker->clear(); | 1655 m_promiseTracker->clear(); |
1630 } | 1656 } |
1631 | 1657 |
1632 } // namespace blink | 1658 } // namespace blink |
OLD | NEW |