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 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 *errorString = "Invalid call frame id"; | 642 *errorString = "Invalid call frame id"; |
| 643 return; | 643 return; |
| 644 } | 644 } |
| 645 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (remoteId.get()); | 645 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (remoteId.get()); |
| 646 if (!injectedScript) { | 646 if (!injectedScript) { |
| 647 *errorString = "Inspected frame has gone"; | 647 *errorString = "Inspected frame has gone"; |
| 648 return; | 648 return; |
| 649 } | 649 } |
| 650 | 650 |
| 651 v8::HandleScope scope(m_isolate); | 651 v8::HandleScope scope(m_isolate); |
| 652 v8::Local<v8::Object> callStack = m_currentCallStack.Get(m_isolate); | 652 v8::Local<v8::Context> localContext = injectedScript->context(); |
| 653 injectedScript->restartFrame(errorString, callStack, callFrameId); | 653 v8::Context::Scope contextScope(localContext); |
|
pfeldman
2016/03/15 19:12:22
Why do you have to enter context here?
kozy
2016/03/16 02:15:15
Removed!
| |
| 654 | |
| 655 v8::TryCatch tryCatch(m_isolate); | |
| 656 | |
| 657 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrameNoScop es(remoteId->frameOrdinal()); | |
| 658 if (!javaScriptCallFrame) { | |
| 659 *errorString = "Could not find call frame with given id"; | |
| 660 return; | |
| 661 } | |
| 662 v8::Local<v8::Value> resultValue; | |
| 663 v8::Local<v8::Boolean> result; | |
| 664 if (!javaScriptCallFrame->restart().ToLocal(&resultValue) || tryCatch.HasCau ght() || !resultValue->ToBoolean(localContext).ToLocal(&result) || !result->Valu e()) { | |
| 665 *errorString = "Internal error"; | |
| 666 return; | |
| 667 } | |
| 668 | |
| 654 m_currentCallStack.Reset(m_isolate, debugger().currentCallFrames()); | 669 m_currentCallStack.Reset(m_isolate, debugger().currentCallFrames()); |
| 670 | |
| 655 *newCallFrames = currentCallFrames(); | 671 *newCallFrames = currentCallFrames(); |
| 656 *asyncStackTrace = currentAsyncStackTrace(); | 672 *asyncStackTrace = currentAsyncStackTrace(); |
| 657 } | 673 } |
| 658 | 674 |
| 659 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource) | 675 void V8DebuggerAgentImpl::getScriptSource(ErrorString* error, const String16& sc riptId, String16* scriptSource) |
| 660 { | 676 { |
| 661 if (!checkEnabled(error)) | 677 if (!checkEnabled(error)) |
| 662 return; | 678 return; |
| 663 ScriptsMap::iterator it = m_scripts.find(scriptId); | 679 ScriptsMap::iterator it = m_scripts.find(scriptId); |
| 664 if (it == m_scripts.end()) { | 680 if (it == m_scripts.end()) { |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 v8::HandleScope scope(m_isolate); | 923 v8::HandleScope scope(m_isolate); |
| 908 v8::Local<v8::Object> callStack = m_currentCallStack.Get(m_isolate); | 924 v8::Local<v8::Object> callStack = m_currentCallStack.Get(m_isolate); |
| 909 | 925 |
| 910 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); | 926 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); |
| 911 injectedScript->evaluateOnCallFrame(errorString, callStack, callFrameId, exp ression, objectGroup.fromMaybe(""), includeCommandLineAPI.fromMaybe(false), retu rnByValue.fromMaybe(false), generatePreview.fromMaybe(false), result, wasThrown, exceptionDetails); | 927 injectedScript->evaluateOnCallFrame(errorString, callStack, callFrameId, exp ression, objectGroup.fromMaybe(""), includeCommandLineAPI.fromMaybe(false), retu rnByValue.fromMaybe(false), generatePreview.fromMaybe(false), result, wasThrown, exceptionDetails); |
| 912 } | 928 } |
| 913 | 929 |
| 914 void V8DebuggerAgentImpl::setVariableValue(ErrorString* errorString, | 930 void V8DebuggerAgentImpl::setVariableValue(ErrorString* errorString, |
| 915 int scopeNumber, | 931 int scopeNumber, |
| 916 const String16& variableName, | 932 const String16& variableName, |
| 917 PassOwnPtr<protocol::Runtime::CallArgument> newValue, | 933 PassOwnPtr<protocol::Runtime::CallArgument> newValueArgument, |
| 918 const Maybe<String16>& callFrameId, | 934 const String16& callFrameId) |
| 919 const Maybe<String16>& functionObjectId) | |
| 920 { | 935 { |
| 921 if (!checkEnabled(errorString)) | 936 if (!checkEnabled(errorString)) |
| 922 return; | 937 return; |
| 923 InjectedScript* injectedScript = nullptr; | 938 if (!isPaused() || m_currentCallStack.IsEmpty()) { |
| 924 if (callFrameId.isJust()) { | 939 *errorString = "Attempt to access callframe when debugger is not on paus e"; |
| 925 if (!isPaused() || m_currentCallStack.IsEmpty()) { | |
| 926 *errorString = "Attempt to access callframe when debugger is not on pause"; | |
| 927 return; | |
| 928 } | |
| 929 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(callFrameI d.fromJust()); | |
| 930 if (!remoteId) { | |
| 931 *errorString = "Invalid call frame id"; | |
| 932 return; | |
| 933 } | |
| 934 injectedScript = m_injectedScriptManager->findInjectedScript(remoteId.ge t()); | |
| 935 if (!injectedScript) { | |
| 936 *errorString = "Inspected frame has gone"; | |
| 937 return; | |
| 938 } | |
| 939 } else if (functionObjectId.isJust()) { | |
| 940 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(functionObjectId .fromJust()); | |
| 941 if (!remoteId) { | |
| 942 *errorString = "Invalid object id"; | |
| 943 return; | |
| 944 } | |
| 945 injectedScript = m_injectedScriptManager->findInjectedScript(remoteId.ge t()); | |
| 946 if (!injectedScript) { | |
| 947 *errorString = "Function object id cannot be resolved"; | |
| 948 return; | |
| 949 } | |
| 950 } else { | |
| 951 *errorString = "Either call frame or function object must be specified"; | |
| 952 return; | 940 return; |
| 953 } | 941 } |
| 954 String16 newValueString = protocol::toValue(newValue.get())->toJSONString(); | 942 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(callFrameId); |
| 943 if (!remoteId) { | |
| 944 *errorString = "Invalid call frame id"; | |
| 945 return; | |
| 946 } | |
| 947 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (remoteId.get()); | |
| 948 if (!injectedScript) { | |
| 949 *errorString = "Inspected frame has gone"; | |
| 950 return; | |
| 951 } | |
| 952 | |
| 955 v8::HandleScope scope(m_isolate); | 953 v8::HandleScope scope(m_isolate); |
| 956 v8::Local<v8::Object> currentCallStack = m_currentCallStack.Get(m_isolate); | 954 v8::Local<v8::Context> localContext = injectedScript->context(); |
| 957 injectedScript->setVariableValue(errorString, currentCallStack, callFrameId, functionObjectId, scopeNumber, variableName, newValueString); | 955 v8::Context::Scope contextScope(localContext); |
|
pfeldman
2016/03/15 19:12:22
ditto
kozy
2016/03/16 02:15:15
Nice catch! Removed!
| |
| 956 | |
| 957 v8::TryCatch tryCatch(m_isolate); | |
| 958 | |
| 959 v8::Local<v8::Value> newValue; | |
| 960 if (!injectedScript->resolveCallArgument(errorString, newValueArgument.get() ).ToLocal(&newValue)) | |
| 961 return; | |
| 962 | |
| 963 OwnPtr<JavaScriptCallFrame> javaScriptCallFrame = debugger().callFrameNoScop es(remoteId->frameOrdinal()); | |
| 964 if (!javaScriptCallFrame) { | |
| 965 *errorString = "Could not find call frame with given id"; | |
| 966 return; | |
| 967 } | |
| 968 v8::MaybeLocal<v8::Value> result = javaScriptCallFrame->setVariableValue(sco peNumber, toV8String(m_isolate, variableName), newValue); | |
| 969 if (tryCatch.HasCaught() || result.IsEmpty()) { | |
| 970 *errorString = "Internal error"; | |
| 971 return; | |
| 972 } | |
| 958 } | 973 } |
| 959 | 974 |
| 960 void V8DebuggerAgentImpl::setAsyncCallStackDepth(ErrorString* errorString, int d epth) | 975 void V8DebuggerAgentImpl::setAsyncCallStackDepth(ErrorString* errorString, int d epth) |
| 961 { | 976 { |
| 962 if (!checkEnabled(errorString)) | 977 if (!checkEnabled(errorString)) |
| 963 return; | 978 return; |
| 964 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, depth); | 979 m_state->setNumber(DebuggerAgentState::asyncCallStackDepth, depth); |
| 965 internalSetAsyncCallStackDepth(depth); | 980 internalSetAsyncCallStackDepth(depth); |
| 966 } | 981 } |
| 967 | 982 |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1529 m_scripts.clear(); | 1544 m_scripts.clear(); |
| 1530 m_blackboxedPositions.clear(); | 1545 m_blackboxedPositions.clear(); |
| 1531 m_breakpointIdToDebuggerBreakpointIds.clear(); | 1546 m_breakpointIdToDebuggerBreakpointIds.clear(); |
| 1532 resetAsyncCallTracker(); | 1547 resetAsyncCallTracker(); |
| 1533 m_promiseTracker->clear(); | 1548 m_promiseTracker->clear(); |
| 1534 if (m_frontend) | 1549 if (m_frontend) |
| 1535 m_frontend->globalObjectCleared(); | 1550 m_frontend->globalObjectCleared(); |
| 1536 } | 1551 } |
| 1537 | 1552 |
| 1538 } // namespace blink | 1553 } // namespace blink |
| OLD | NEW |