Chromium Code Reviews| 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 checkInternalError(ErrorString* errorString, bool success) | |
|
dgozman
2016/03/19 05:39:21
I saw this one already.
kozy
2016/03/21 05:18:28
I've moved it to V8RuntimeAgentImpl. In followup p
| |
| 147 { | |
| 148 if (!success) | |
| 149 *errorString = "Internal error"; | |
| 150 return success; | |
| 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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 701 } | 708 } |
| 702 v8::Local<v8::Function> function = value.As<v8::Function>(); | 709 v8::Local<v8::Function> function = value.As<v8::Function>(); |
| 703 | 710 |
| 704 v8::Local<v8::Value> scopesValue; | 711 v8::Local<v8::Value> scopesValue; |
| 705 v8::Local<v8::Array> scopes; | 712 v8::Local<v8::Array> scopes; |
| 706 String16 objectGroupName = injectedScript->objectGroupName(*remoteId); | 713 String16 objectGroupName = injectedScript->objectGroupName(*remoteId); |
| 707 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu e->IsArray()) { | 714 if (m_debugger->functionScopes(function).ToLocal(&scopesValue) && scopesValu e->IsArray()) { |
| 708 scopes = scopesValue.As<v8::Array>(); | 715 scopes = scopesValue.As<v8::Array>(); |
| 709 for (size_t i = 0; i < scopes->Length(); ++i) { | 716 for (size_t i = 0; i < scopes->Length(); ++i) { |
| 710 v8::Local<v8::Value> scope; | 717 v8::Local<v8::Value> scope; |
| 711 if (!scopes->Get(injectedScript->context(), i).ToLocal(&scope) || !s cope->IsObject()) { | 718 if (!checkInternalError(errorString, scopes->Get(injectedScript->con text(), i).ToLocal(&scope) && scope->IsObject())) |
| 712 *errorString = "Internal error"; | |
| 713 return; | 719 return; |
| 714 } | |
| 715 if (!injectedScript->wrapObjectProperty(errorString, scope.As<v8::Ob ject>(), toV8String(injectedScript->isolate(), "object"), objectGroupName)) | 720 if (!injectedScript->wrapObjectProperty(errorString, scope.As<v8::Ob ject>(), toV8String(injectedScript->isolate(), "object"), objectGroupName)) |
| 716 return; | 721 return; |
| 717 } | 722 } |
| 718 } | 723 } |
| 719 | 724 |
| 720 OwnPtr<protocol::Debugger::Location> location = protocol::Debugger::Location ::create() | 725 OwnPtr<protocol::Debugger::Location> location = protocol::Debugger::Location ::create() |
| 721 .setScriptId(String16::number(function->ScriptId())) | 726 .setScriptId(String16::number(function->ScriptId())) |
| 722 .setLineNumber(function->GetScriptLineNumber()) | 727 .setLineNumber(function->GetScriptLineNumber()) |
| 723 .setColumnNumber(function->GetScriptColumnNumber()).build(); | 728 .setColumnNumber(function->GetScriptColumnNumber()).build(); |
| 724 | 729 |
| 725 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create() | 730 OwnPtr<FunctionDetails> functionDetails = FunctionDetails::create() |
| 726 .setLocation(location.release()) | 731 .setLocation(location.release()) |
| 727 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName()) ) | 732 .setFunctionName(toProtocolStringWithTypeCheck(function->GetDebugName()) ) |
| 728 .setIsGenerator(function->IsGeneratorFunction()).build(); | 733 .setIsGenerator(function->IsGeneratorFunction()).build(); |
| 729 | 734 |
| 730 if (!scopes.IsEmpty()) { | 735 if (!scopes.IsEmpty()) { |
| 731 protocol::ErrorSupport errorSupport; | 736 protocol::ErrorSupport errorSupport; |
| 732 OwnPtr<protocol::Array<protocol::Debugger::Scope>> scopeChain = protocol ::Array<protocol::Debugger::Scope>::parse(toProtocolValue(injectedScript->contex t(), scopes).get(), &errorSupport); | 737 OwnPtr<protocol::Array<protocol::Debugger::Scope>> scopeChain = protocol ::Array<protocol::Debugger::Scope>::parse(toProtocolValue(injectedScript->contex t(), scopes).get(), &errorSupport); |
| 733 if (errorSupport.hasErrors()) { | 738 if (!checkInternalError(errorString, !errorSupport.hasErrors())) |
|
dgozman
2016/03/19 05:39:21
Perhaps we should rename this to hasInternalError
kozy
2016/03/21 05:18:28
Done.
| |
| 734 *errorString = "Internal error"; | |
| 735 return; | 739 return; |
| 736 } | |
| 737 functionDetails->setScopeChain(scopeChain.release()); | 740 functionDetails->setScopeChain(scopeChain.release()); |
| 738 } | 741 } |
| 739 | 742 |
| 740 *details = functionDetails.release(); | 743 *details = functionDetails.release(); |
| 741 } | 744 } |
| 742 | 745 |
| 743 void V8DebuggerAgentImpl::getGeneratorObjectDetails(ErrorString* errorString, co nst String16& objectId, OwnPtr<GeneratorObjectDetails>* outDetails) | 746 void V8DebuggerAgentImpl::getGeneratorObjectDetails(ErrorString* errorString, co nst String16& objectId, OwnPtr<GeneratorObjectDetails>* outDetails) |
| 744 { | 747 { |
| 745 if (!checkEnabled(errorString)) | 748 if (!checkEnabled(errorString)) |
| 746 return; | 749 return; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 759 v8::Local<v8::Value> value; | 762 v8::Local<v8::Value> value; |
| 760 if (!injectedScript->findObject(errorString, *remoteId, &value)) | 763 if (!injectedScript->findObject(errorString, *remoteId, &value)) |
| 761 return; | 764 return; |
| 762 if (!value->IsObject() || !value->ToObject(context).ToLocal(&object)) { | 765 if (!value->IsObject() || !value->ToObject(context).ToLocal(&object)) { |
| 763 *errorString = "Value with given id is not an Object"; | 766 *errorString = "Value with given id is not an Object"; |
| 764 return; | 767 return; |
| 765 } | 768 } |
| 766 | 769 |
| 767 v8::Local<v8::Object> detailsObject; | 770 v8::Local<v8::Object> detailsObject; |
| 768 v8::Local<v8::Value> detailsValue = debugger().generatorObjectDetails(object ); | 771 v8::Local<v8::Value> detailsValue = debugger().generatorObjectDetails(object ); |
| 769 if (!detailsValue->IsObject() || !detailsValue->ToObject(context).ToLocal(&d etailsObject)) { | 772 if (!checkInternalError(errorString, detailsValue->IsObject() && detailsValu e->ToObject(context).ToLocal(&detailsObject))) |
| 770 *errorString = "Internal error"; | |
| 771 return; | 773 return; |
| 772 } | |
| 773 | 774 |
| 774 String16 groupName = injectedScript->objectGroupName(*remoteId); | 775 String16 groupName = injectedScript->objectGroupName(*remoteId); |
| 775 if (!injectedScript->wrapObjectProperty(errorString, detailsObject, toV8Stri ng(m_isolate, "function"), groupName)) | 776 if (!injectedScript->wrapObjectProperty(errorString, detailsObject, toV8Stri ng(m_isolate, "function"), groupName)) |
| 776 return; | 777 return; |
| 777 | 778 |
| 778 protocol::ErrorSupport errors; | 779 protocol::ErrorSupport errors; |
| 779 OwnPtr<GeneratorObjectDetails> protocolDetails = GeneratorObjectDetails::par se(toProtocolValue(context, detailsObject).get(), &errors); | 780 OwnPtr<GeneratorObjectDetails> protocolDetails = GeneratorObjectDetails::par se(toProtocolValue(context, detailsObject).get(), &errors); |
| 780 if (!protocolDetails) { | 781 if (!checkInternalError(errorString, protocolDetails)) |
| 781 *errorString = "Internal error"; | |
| 782 return; | 782 return; |
| 783 } | |
| 784 *outDetails = protocolDetails.release(); | 783 *outDetails = protocolDetails.release(); |
| 785 } | 784 } |
| 786 | 785 |
| 787 void V8DebuggerAgentImpl::getCollectionEntries(ErrorString* errorString, const S tring16& objectId, OwnPtr<protocol::Array<CollectionEntry>>* entries) | 786 void V8DebuggerAgentImpl::getCollectionEntries(ErrorString* errorString, const S tring16& objectId, OwnPtr<protocol::Array<CollectionEntry>>* outEntries) |
| 788 { | 787 { |
| 789 if (!checkEnabled(errorString)) | 788 if (!checkEnabled(errorString)) |
| 790 return; | 789 return; |
| 791 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI d); | 790 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI d); |
| 792 if (!remoteId) | 791 if (!remoteId) |
| 793 return; | 792 return; |
| 794 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); | 793 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); |
| 795 if (!injectedScript) | 794 if (!injectedScript) |
| 796 return; | 795 return; |
| 797 injectedScript->getCollectionEntries(errorString, objectId, entries); | 796 |
| 797 v8::HandleScope scope(m_isolate); | |
| 798 v8::Local<v8::Context> context = injectedScript->context(); | |
| 799 v8::Context::Scope contextScope(context); | |
| 800 | |
| 801 v8::Local<v8::Object> object; | |
| 802 v8::Local<v8::Value> value; | |
| 803 if (!injectedScript->findObject(errorString, *remoteId, &value)) | |
| 804 return; | |
| 805 if (!value->IsObject() || !value->ToObject(context).ToLocal(&object)) { | |
|
dgozman
2016/03/19 05:39:21
Use value.As<v8::Object>
kozy
2016/03/21 05:18:28
Done.
| |
| 806 *errorString = "Object with given id is not a collection"; | |
| 807 return; | |
| 808 } | |
| 809 v8::Local<v8::Value> entriesValue = m_debugger->collectionEntries(object); | |
| 810 if (!checkInternalError(errorString, !entriesValue.IsEmpty())) | |
| 811 return; | |
| 812 if (entriesValue->IsUndefined()) { | |
| 813 *errorString = "Object with given id is not a collection"; | |
| 814 return; | |
| 815 } | |
| 816 if (!checkInternalError(errorString, entriesValue->IsArray())) | |
| 817 return; | |
| 818 String16 groupName = injectedScript->objectGroupName(*remoteId); | |
| 819 v8::Local<v8::Array> entriesArray = entriesValue.As<v8::Array>(); | |
| 820 for (size_t i = 0; i < entriesArray->Length(); ++i) { | |
| 821 v8::Local<v8::Value> entry; | |
| 822 if (!checkInternalError(errorString, entriesArray->Get(injectedScript->c ontext(), i).ToLocal(&entry)) && entry->IsObject()) | |
|
dgozman
2016/03/19 05:39:21
entry->IsObject() should be inside checkInternalEr
kozy
2016/03/21 05:18:28
Removed.
| |
| 823 return; | |
| 824 v8::Local<v8::Object> entryObject = entry.As<v8::Object>(); | |
| 825 v8::Local<v8::String> keyString = toV8String(injectedScript->isolate(), "key"); | |
|
dgozman
2016/03/19 05:39:21
toV8StringInternalized
I think there are more lit
kozy
2016/03/21 05:18:28
Done.
| |
| 826 if (entryObject->Has(injectedScript->context(), keyString).FromMaybe(fal se)) { | |
| 827 if (!injectedScript->wrapObjectProperty(errorString, entryObject, ke yString, groupName)) | |
| 828 return; | |
| 829 } | |
| 830 if (!injectedScript->wrapObjectProperty(errorString, entryObject, toV8St ring(injectedScript->isolate(), "value"), groupName)) | |
|
dgozman
2016/03/19 05:39:21
I'm worried that many calls into V8 like this coul
kozy
2016/03/21 05:18:28
I compare perfomance of different options and intr
| |
| 831 return; | |
| 832 } | |
| 833 protocol::ErrorSupport errors; | |
| 834 OwnPtr<protocol::Array<CollectionEntry>> entries = protocol::Array<Collectio nEntry>::parse(toProtocolValue(injectedScript->context(), entriesArray).get(), & errors); | |
| 835 if (!checkInternalError(errorString, entries)) | |
|
dgozman
2016/03/19 05:39:21
I'd rather use !errors.hasErrors()
kozy
2016/03/21 05:18:28
I'd like to check pointer because null pointer wil
| |
| 836 return; | |
| 837 *outEntries = entries.release(); | |
| 798 } | 838 } |
| 799 | 839 |
| 800 void V8DebuggerAgentImpl::schedulePauseOnNextStatement(const String16& breakReas on, PassOwnPtr<protocol::DictionaryValue> data) | 840 void V8DebuggerAgentImpl::schedulePauseOnNextStatement(const String16& breakReas on, PassOwnPtr<protocol::DictionaryValue> data) |
| 801 { | 841 { |
| 802 ASSERT(enabled()); | 842 ASSERT(enabled()); |
| 803 if (m_scheduledDebuggerStep == StepInto || m_javaScriptPauseScheduled || isP aused()) | 843 if (m_scheduledDebuggerStep == StepInto || m_javaScriptPauseScheduled || isP aused()) |
| 804 return; | 844 return; |
| 805 m_breakReason = breakReason; | 845 m_breakReason = breakReason; |
| 806 m_breakAuxData = data; | 846 m_breakAuxData = data; |
| 807 m_pausingOnNativeEvent = true; | 847 m_pausingOnNativeEvent = true; |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1624 m_scripts.clear(); | 1664 m_scripts.clear(); |
| 1625 m_blackboxedPositions.clear(); | 1665 m_blackboxedPositions.clear(); |
| 1626 m_breakpointIdToDebuggerBreakpointIds.clear(); | 1666 m_breakpointIdToDebuggerBreakpointIds.clear(); |
| 1627 resetAsyncCallTracker(); | 1667 resetAsyncCallTracker(); |
| 1628 m_promiseTracker->clear(); | 1668 m_promiseTracker->clear(); |
| 1629 if (m_frontend) | 1669 if (m_frontend) |
| 1630 m_frontend->globalObjectCleared(); | 1670 m_frontend->globalObjectCleared(); |
| 1631 } | 1671 } |
| 1632 | 1672 |
| 1633 } // namespace blink | 1673 } // namespace blink |
| OLD | NEW |