| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 v8::HandleScope scope(injectedScript->isolate()); | 102 v8::HandleScope scope(injectedScript->isolate()); |
| 103 v8::Local<v8::Context> localContext = injectedScript->context(); | 103 v8::Local<v8::Context> localContext = injectedScript->context(); |
| 104 v8::Context::Scope contextScope(localContext); | 104 v8::Context::Scope contextScope(localContext); |
| 105 | 105 |
| 106 if (!injectedScript->canAccessInspectedWindow()) { | 106 if (!injectedScript->canAccessInspectedWindow()) { |
| 107 *errorString = "Can not access given context"; | 107 *errorString = "Can not access given context"; |
| 108 return; | 108 return; |
| 109 } | 109 } |
| 110 | 110 |
| 111 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon
sole.fromMaybe(false) ? m_debugger : nullptr); |
| 112 v8::TryCatch tryCatch(injectedScript->isolate()); |
| 113 |
| 111 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe(
false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object
>(); | 114 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe(
false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object
>(); |
| 112 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty()) | 115 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty()) |
| 113 return; | 116 return; |
| 117 InjectedScript::ScopedGlobalObjectExtension scopeExtension(injectedScript, c
ommandLineAPI); |
| 114 | 118 |
| 115 v8::TryCatch tryCatch(injectedScript->isolate()); | 119 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->compileAndRunIntern
alScript(injectedScript->context(), toV8String(injectedScript->isolate(), expres
sion)); |
| 116 v8::MaybeLocal<v8::Value> maybeResultValue = evaluateInternal(injectedScript
, doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false), expression, commandLine
API); | |
| 117 | 120 |
| 118 // InjectedScript may be gone after any evaluate call - find it again. | 121 // InjectedScript may be gone after any evaluate call - find it again. |
| 119 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, ex
ecutionContextId.fromJust()); | 122 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, ex
ecutionContextId.fromJust()); |
| 120 if (!injectedScript) | 123 if (!injectedScript) |
| 121 return; | 124 return; |
| 122 | 125 |
| 123 injectedScript->wrapEvaluateResult(errorString, | 126 injectedScript->wrapEvaluateResult(errorString, |
| 124 maybeResultValue, | 127 maybeResultValue, |
| 125 tryCatch, | 128 tryCatch, |
| 126 objectGroup.fromMaybe(""), | 129 objectGroup.fromMaybe(""), |
| 127 returnByValue.fromMaybe(false), | 130 returnByValue.fromMaybe(false), |
| 128 generatePreview.fromMaybe(false), | 131 generatePreview.fromMaybe(false), |
| 129 result, | 132 result, |
| 130 wasThrown, | 133 wasThrown, |
| 131 exceptionDetails); | 134 exceptionDetails); |
| 132 } | 135 } |
| 133 | 136 |
| 134 v8::MaybeLocal<v8::Value> V8RuntimeAgentImpl::evaluateInternal(InjectedScript* i
njectedScript, bool doNotPauseOnExceptionsAndMuteConsole, const String& expressi
on, v8::MaybeLocal<v8::Object> extension) | |
| 135 { | |
| 136 InjectedScript::ScopedGlobalObjectExtension scopeExtension(injectedScript, e
xtension); | |
| 137 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon
sole ? m_debugger : nullptr); | |
| 138 return m_debugger->compileAndRunInternalScript(injectedScript->context(), to
V8String(injectedScript->isolate(), expression)); | |
| 139 } | |
| 140 | |
| 141 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, | 137 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, |
| 142 const String16& objectId, | 138 const String16& objectId, |
| 143 const String16& expression, | 139 const String16& expression, |
| 144 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum
ents, | 140 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum
ents, |
| 145 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 141 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 146 const Maybe<bool>& returnByValue, | 142 const Maybe<bool>& returnByValue, |
| 147 const Maybe<bool>& generatePreview, | 143 const Maybe<bool>& generatePreview, |
| 148 const Maybe<bool>& userGesture, | 144 const Maybe<bool>& userGesture, |
| 149 OwnPtr<RemoteObject>* result, | 145 OwnPtr<RemoteObject>* result, |
| 150 Maybe<bool>* wasThrown) | 146 Maybe<bool>* wasThrown) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 177 argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]); | 173 argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]); |
| 178 for (int i = 0; i < argc; ++i) { | 174 for (int i = 0; i < argc; ++i) { |
| 179 v8::Local<v8::Value> argumentValue; | 175 v8::Local<v8::Value> argumentValue; |
| 180 if (!injectedScript->resolveCallArgument(errorString, arguments->get
(i)).ToLocal(&argumentValue)) | 176 if (!injectedScript->resolveCallArgument(errorString, arguments->get
(i)).ToLocal(&argumentValue)) |
| 181 return; | 177 return; |
| 182 argv[i] = argumentValue; | 178 argv[i] = argumentValue; |
| 183 } | 179 } |
| 184 } | 180 } |
| 185 | 181 |
| 186 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon
sole.fromMaybe(false) ? m_debugger : nullptr); | 182 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon
sole.fromMaybe(false) ? m_debugger : nullptr); |
| 183 v8::TryCatch tryCatch(injectedScript->isolate()); |
| 187 | 184 |
| 188 v8::MaybeLocal<v8::Object> remoteObjectAPI = injectedScript->remoteObjectAPI
(errorString, objectGroupName); | 185 v8::MaybeLocal<v8::Value> maybeFunctionValue = m_debugger->compileAndRunInte
rnalScript(injectedScript->context(), toV8String(injectedScript->isolate(), "("
+ expression + ")")); |
| 189 if (remoteObjectAPI.IsEmpty()) | |
| 190 return; | |
| 191 | |
| 192 v8::TryCatch tryCatch(injectedScript->isolate()); | |
| 193 v8::MaybeLocal<v8::Value> maybeFunctionValue = evaluateInternal(injectedScri
pt, doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false), "(" + expression + ")
", remoteObjectAPI); | |
| 194 // InjectedScript may be gone after any evaluate call - find it again. | 186 // InjectedScript may be gone after any evaluate call - find it again. |
| 195 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re
moteId.get()); | 187 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re
moteId.get()); |
| 196 if (!injectedScript) | 188 if (!injectedScript) |
| 197 return; | 189 return; |
| 198 | 190 |
| 199 if (tryCatch.HasCaught()) { | 191 if (tryCatch.HasCaught()) { |
| 200 injectedScript->wrapEvaluateResult(errorString, maybeFunctionValue, tryC
atch, objectGroupName, false, false, result, wasThrown, nullptr); | 192 injectedScript->wrapEvaluateResult(errorString, maybeFunctionValue, tryC
atch, objectGroupName, false, false, result, wasThrown, nullptr); |
| 201 return; | 193 return; |
| 202 } | 194 } |
| 203 | 195 |
| 204 v8::Local<v8::Value> functionValue; | 196 v8::Local<v8::Value> functionValue; |
| 205 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio
n()) { | 197 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio
n()) { |
| 206 *errorString = "Given expression does not evaluate to a function"; | 198 *errorString = "Given expression does not evaluate to a function"; |
| 207 return; | 199 return; |
| 208 } | 200 } |
| 209 | 201 |
| 202 v8::MaybeLocal<v8::Object> remoteObjectAPI = injectedScript->remoteObjectAPI
(errorString, objectGroupName); |
| 203 if (remoteObjectAPI.IsEmpty()) |
| 204 return; |
| 205 InjectedScript::ScopedGlobalObjectExtension scopeExtension(injectedScript, r
emoteObjectAPI); |
| 206 |
| 210 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->callFunction(functi
onValue.As<v8::Function>(), injectedScript->context(), object, argc, argv.get())
; | 207 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->callFunction(functi
onValue.As<v8::Function>(), injectedScript->context(), object, argc, argv.get())
; |
| 211 // InjectedScript may be gone after any evaluate call - find it again. | 208 // InjectedScript may be gone after any evaluate call - find it again. |
| 212 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re
moteId.get()); | 209 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re
moteId.get()); |
| 213 if (!injectedScript) | 210 if (!injectedScript) |
| 214 return; | 211 return; |
| 215 | 212 |
| 216 injectedScript->wrapEvaluateResult(errorString, maybeResultValue, tryCatch,
objectGroupName, returnByValue.fromMaybe(false), generatePreview.fromMaybe(false
), result, wasThrown, nullptr); | 213 injectedScript->wrapEvaluateResult(errorString, maybeResultValue, tryCatch,
objectGroupName, returnByValue.fromMaybe(false), generatePreview.fromMaybe(false
), result, wasThrown, nullptr); |
| 217 } | 214 } |
| 218 | 215 |
| 219 void V8RuntimeAgentImpl::getProperties( | 216 void V8RuntimeAgentImpl::getProperties( |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 } | 535 } |
| 539 | 536 |
| 540 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context>
context) | 537 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context>
context) |
| 541 { | 538 { |
| 542 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); | 539 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); |
| 543 if (m_enabled && contextId) | 540 if (m_enabled && contextId) |
| 544 m_frontend->executionContextDestroyed(contextId); | 541 m_frontend->executionContextDestroyed(contextId); |
| 545 } | 542 } |
| 546 | 543 |
| 547 } // namespace blink | 544 } // namespace blink |
| OLD | NEW |