| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" | 31 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" |
| 32 | 32 |
| 33 #include "platform/inspector_protocol/Values.h" | 33 #include "platform/inspector_protocol/Values.h" |
| 34 #include "platform/v8_inspector/IgnoreExceptionsScope.h" | |
| 35 #include "platform/v8_inspector/InjectedScript.h" | 34 #include "platform/v8_inspector/InjectedScript.h" |
| 36 #include "platform/v8_inspector/InspectedContext.h" | 35 #include "platform/v8_inspector/InspectedContext.h" |
| 37 #include "platform/v8_inspector/MuteConsoleScope.h" | |
| 38 #include "platform/v8_inspector/RemoteObjectId.h" | 36 #include "platform/v8_inspector/RemoteObjectId.h" |
| 39 #include "platform/v8_inspector/V8DebuggerImpl.h" | 37 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 40 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 38 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
| 41 #include "platform/v8_inspector/V8StringUtil.h" | 39 #include "platform/v8_inspector/V8StringUtil.h" |
| 42 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 40 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
| 43 | 41 |
| 44 namespace blink { | 42 namespace blink { |
| 45 | 43 |
| 46 namespace V8RuntimeAgentImplState { | 44 namespace V8RuntimeAgentImplState { |
| 47 static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled
"; | 45 static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled
"; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 if (!contextId) { | 90 if (!contextId) { |
| 93 *errorString = "Cannot find default execution context"; | 91 *errorString = "Cannot find default execution context"; |
| 94 return; | 92 return; |
| 95 } | 93 } |
| 96 } | 94 } |
| 97 | 95 |
| 98 InjectedScript::ContextScope scope(errorString, m_debugger, m_session->conte
xtGroupId(), contextId); | 96 InjectedScript::ContextScope scope(errorString, m_debugger, m_session->conte
xtGroupId(), contextId); |
| 99 if (!scope.initialize()) | 97 if (!scope.initialize()) |
| 100 return; | 98 return; |
| 101 | 99 |
| 102 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon
sole.fromMaybe(false) ? m_debugger : nullptr); | 100 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 103 MuteConsoleScope muteConsoleScope(doNotPauseOnExceptionsAndMuteConsole.fromM
aybe(false) ? m_debugger : nullptr); | 101 scope.ignoreExceptionsAndMuteConsole(); |
| 104 | 102 |
| 105 if (includeCommandLineAPI.fromMaybe(false)) { | 103 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) |
| 106 v8::MaybeLocal<v8::Object> commandLineAPI = scope.injectedScript()->comm
andLineAPI(errorString); | 104 return; |
| 107 if (commandLineAPI.IsEmpty()) | |
| 108 return; | |
| 109 scope.installGlobalObjectExtension(commandLineAPI); | |
| 110 } | |
| 111 | 105 |
| 112 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed()
; | 106 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed()
; |
| 113 // Temporarily enable allow evals for inspector. | 107 // Temporarily enable allow evals for inspector. |
| 114 if (evalIsDisabled) | 108 if (evalIsDisabled) |
| 115 scope.context()->AllowCodeGenerationFromStrings(true); | 109 scope.context()->AllowCodeGenerationFromStrings(true); |
| 116 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->compileAndRunIntern
alScript(scope.context(), toV8String(m_debugger->isolate(), expression)); | 110 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->compileAndRunIntern
alScript(scope.context(), toV8String(m_debugger->isolate(), expression)); |
| 117 if (evalIsDisabled) | 111 if (evalIsDisabled) |
| 118 scope.context()->AllowCodeGenerationFromStrings(false); | 112 scope.context()->AllowCodeGenerationFromStrings(false); |
| 119 | 113 |
| 120 // Re-initialize after running client's code, as it could have destroyed con
text or session. | 114 // Re-initialize after running client's code, as it could have destroyed con
text or session. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 argc = arguments->length(); | 147 argc = arguments->length(); |
| 154 argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]); | 148 argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]); |
| 155 for (int i = 0; i < argc; ++i) { | 149 for (int i = 0; i < argc; ++i) { |
| 156 v8::Local<v8::Value> argumentValue; | 150 v8::Local<v8::Value> argumentValue; |
| 157 if (!scope.injectedScript()->resolveCallArgument(errorString, argume
nts->get(i)).ToLocal(&argumentValue)) | 151 if (!scope.injectedScript()->resolveCallArgument(errorString, argume
nts->get(i)).ToLocal(&argumentValue)) |
| 158 return; | 152 return; |
| 159 argv[i] = argumentValue; | 153 argv[i] = argumentValue; |
| 160 } | 154 } |
| 161 } | 155 } |
| 162 | 156 |
| 163 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon
sole.fromMaybe(false) ? m_debugger : nullptr); | 157 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 164 MuteConsoleScope muteConsoleScope(doNotPauseOnExceptionsAndMuteConsole.fromM
aybe(false) ? m_debugger : nullptr); | 158 scope.ignoreExceptionsAndMuteConsole(); |
| 165 | 159 |
| 166 v8::MaybeLocal<v8::Value> maybeFunctionValue = m_debugger->compileAndRunInte
rnalScript(scope.context(), toV8String(m_debugger->isolate(), "(" + expression +
")")); | 160 v8::MaybeLocal<v8::Value> maybeFunctionValue = m_debugger->compileAndRunInte
rnalScript(scope.context(), toV8String(m_debugger->isolate(), "(" + expression +
")")); |
| 167 // Re-initialize after running client's code, as it could have destroyed con
text or session. | 161 // Re-initialize after running client's code, as it could have destroyed con
text or session. |
| 168 if (!scope.initialize()) | 162 if (!scope.initialize()) |
| 169 return; | 163 return; |
| 170 | 164 |
| 171 if (scope.tryCatch().HasCaught()) { | 165 if (scope.tryCatch().HasCaught()) { |
| 172 scope.injectedScript()->wrapEvaluateResult(errorString, maybeFunctionVal
ue, scope.tryCatch(), scope.objectGroupName(), false, false, result, wasThrown,
nullptr); | 166 scope.injectedScript()->wrapEvaluateResult(errorString, maybeFunctionVal
ue, scope.tryCatch(), scope.objectGroupName(), false, false, result, wasThrown,
nullptr); |
| 173 return; | 167 return; |
| 174 } | 168 } |
| 175 | 169 |
| 176 v8::Local<v8::Value> functionValue; | 170 v8::Local<v8::Value> functionValue; |
| 177 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio
n()) { | 171 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio
n()) { |
| 178 *errorString = "Given expression does not evaluate to a function"; | 172 *errorString = "Given expression does not evaluate to a function"; |
| 179 return; | 173 return; |
| 180 } | 174 } |
| 181 | 175 |
| 182 v8::MaybeLocal<v8::Object> remoteObjectAPI = scope.injectedScript()->remoteO
bjectAPI(errorString, scope.objectGroupName()); | 176 if (!scope.installRemoteObjectAPI(scope.objectGroupName())) |
| 183 if (remoteObjectAPI.IsEmpty()) | |
| 184 return; | 177 return; |
| 185 scope.installGlobalObjectExtension(remoteObjectAPI); | |
| 186 | 178 |
| 187 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->callFunction(functi
onValue.As<v8::Function>(), scope.context(), scope.object(), argc, argv.get()); | 179 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->callFunction(functi
onValue.As<v8::Function>(), scope.context(), scope.object(), argc, argv.get()); |
| 188 // Re-initialize after running client's code, as it could have destroyed con
text or session. | 180 // Re-initialize after running client's code, as it could have destroyed con
text or session. |
| 189 if (!scope.initialize()) | 181 if (!scope.initialize()) |
| 190 return; | 182 return; |
| 191 | 183 |
| 192 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc
ope.tryCatch(), scope.objectGroupName(), returnByValue.fromMaybe(false), generat
ePreview.fromMaybe(false), result, wasThrown, nullptr); | 184 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc
ope.tryCatch(), scope.objectGroupName(), returnByValue.fromMaybe(false), generat
ePreview.fromMaybe(false), result, wasThrown, nullptr); |
| 193 } | 185 } |
| 194 | 186 |
| 195 void V8RuntimeAgentImpl::getProperties( | 187 void V8RuntimeAgentImpl::getProperties( |
| 196 ErrorString* errorString, | 188 ErrorString* errorString, |
| 197 const String16& objectId, | 189 const String16& objectId, |
| 198 const Maybe<bool>& ownProperties, | 190 const Maybe<bool>& ownProperties, |
| 199 const Maybe<bool>& accessorPropertiesOnly, | 191 const Maybe<bool>& accessorPropertiesOnly, |
| 200 const Maybe<bool>& generatePreview, | 192 const Maybe<bool>& generatePreview, |
| 201 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, | 193 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, |
| 202 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter
nalProperties, | 194 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter
nalProperties, |
| 203 Maybe<ExceptionDetails>* exceptionDetails) | 195 Maybe<ExceptionDetails>* exceptionDetails) |
| 204 { | 196 { |
| 205 using protocol::Runtime::InternalPropertyDescriptor; | 197 using protocol::Runtime::InternalPropertyDescriptor; |
| 206 | 198 |
| 207 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex
tGroupId(), objectId); | 199 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex
tGroupId(), objectId); |
| 208 if (!scope.initialize()) | 200 if (!scope.initialize()) |
| 209 return; | 201 return; |
| 210 | 202 |
| 211 IgnoreExceptionsScope ignoreExceptionsScope(m_debugger); | 203 scope.ignoreExceptionsAndMuteConsole(); |
| 212 MuteConsoleScope muteConsoleScope(m_debugger); | |
| 213 | |
| 214 if (!scope.object()->IsObject()) { | 204 if (!scope.object()->IsObject()) { |
| 215 *errorString = "Value with given id is not an object"; | 205 *errorString = "Value with given id is not an object"; |
| 216 return; | 206 return; |
| 217 } | 207 } |
| 218 | 208 |
| 219 v8::Local<v8::Object> object = scope.object().As<v8::Object>(); | 209 v8::Local<v8::Object> object = scope.object().As<v8::Object>(); |
| 220 scope.injectedScript()->getProperties(errorString, object, scope.objectGroup
Name(), ownProperties.fromMaybe(false), accessorPropertiesOnly.fromMaybe(false),
generatePreview.fromMaybe(false), result, exceptionDetails); | 210 scope.injectedScript()->getProperties(errorString, object, scope.objectGroup
Name(), ownProperties.fromMaybe(false), accessorPropertiesOnly.fromMaybe(false),
generatePreview.fromMaybe(false), result, exceptionDetails); |
| 221 if (!errorString->isEmpty() || exceptionDetails->isJust() || accessorPropert
iesOnly.fromMaybe(false)) | 211 if (!errorString->isEmpty() || exceptionDetails->isJust() || accessorPropert
iesOnly.fromMaybe(false)) |
| 222 return; | 212 return; |
| 223 v8::Local<v8::Array> propertiesArray; | 213 v8::Local<v8::Array> propertiesArray; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 318 |
| 329 if (!m_compiledScripts.contains(scriptId)) { | 319 if (!m_compiledScripts.contains(scriptId)) { |
| 330 *errorString = "Script execution failed"; | 320 *errorString = "Script execution failed"; |
| 331 return; | 321 return; |
| 332 } | 322 } |
| 333 | 323 |
| 334 InjectedScript::ContextScope scope(errorString, m_debugger, m_session->conte
xtGroupId(), executionContextId); | 324 InjectedScript::ContextScope scope(errorString, m_debugger, m_session->conte
xtGroupId(), executionContextId); |
| 335 if (!scope.initialize()) | 325 if (!scope.initialize()) |
| 336 return; | 326 return; |
| 337 | 327 |
| 338 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon
sole.fromMaybe(false) ? m_debugger : nullptr); | 328 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 339 MuteConsoleScope muteConsoleScope(doNotPauseOnExceptionsAndMuteConsole.fromM
aybe(false) ? m_debugger : nullptr); | 329 scope.ignoreExceptionsAndMuteConsole(); |
| 340 | 330 |
| 341 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script
Id); | 331 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script
Id); |
| 342 v8::Local<v8::Script> script = scriptWrapper->Get(m_debugger->isolate()); | 332 v8::Local<v8::Script> script = scriptWrapper->Get(m_debugger->isolate()); |
| 343 if (script.IsEmpty()) { | 333 if (script.IsEmpty()) { |
| 344 *errorString = "Script execution failed"; | 334 *errorString = "Script execution failed"; |
| 345 return; | 335 return; |
| 346 } | 336 } |
| 347 | 337 |
| 348 if (includeCommandLineAPI.fromMaybe(false)) { | 338 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) |
| 349 v8::MaybeLocal<v8::Object> commandLineAPI = scope.injectedScript()->comm
andLineAPI(errorString); | 339 return; |
| 350 if (commandLineAPI.IsEmpty()) | |
| 351 return; | |
| 352 scope.installGlobalObjectExtension(commandLineAPI); | |
| 353 } | |
| 354 | 340 |
| 355 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->runCompiledScript(s
cope.context(), script); | 341 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->runCompiledScript(s
cope.context(), script); |
| 356 | 342 |
| 357 // Re-initialize after running client's code, as it could have destroyed con
text or session. | 343 // Re-initialize after running client's code, as it could have destroyed con
text or session. |
| 358 if (!scope.initialize()) | 344 if (!scope.initialize()) |
| 359 return; | 345 return; |
| 360 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc
ope.tryCatch(), objectGroup.fromMaybe(""), false, false, result, nullptr, except
ionDetails); | 346 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc
ope.tryCatch(), objectGroup.fromMaybe(""), false, false, result, nullptr, except
ionDetails); |
| 361 } | 347 } |
| 362 | 348 |
| 363 void V8RuntimeAgentImpl::setInspectorState(protocol::DictionaryValue* state) | 349 void V8RuntimeAgentImpl::setInspectorState(protocol::DictionaryValue* state) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 } | 475 } |
| 490 } | 476 } |
| 491 | 477 |
| 492 void V8RuntimeAgentImpl::inspect(PassOwnPtr<protocol::Runtime::RemoteObject> obj
ectToInspect, PassOwnPtr<protocol::DictionaryValue> hints) | 478 void V8RuntimeAgentImpl::inspect(PassOwnPtr<protocol::Runtime::RemoteObject> obj
ectToInspect, PassOwnPtr<protocol::DictionaryValue> hints) |
| 493 { | 479 { |
| 494 if (m_enabled) | 480 if (m_enabled) |
| 495 m_frontend->inspectRequested(objectToInspect, hints); | 481 m_frontend->inspectRequested(objectToInspect, hints); |
| 496 } | 482 } |
| 497 | 483 |
| 498 } // namespace blink | 484 } // namespace blink |
| OLD | NEW |