Chromium Code Reviews| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 | 98 |
| 99 if (!injectedScript->canAccessInspectedWindow()) { | 99 if (!injectedScript->canAccessInspectedWindow()) { |
| 100 *errorString = "Can not access given context"; | 100 *errorString = "Can not access given context"; |
| 101 return; | 101 return; |
| 102 } | 102 } |
| 103 | 103 |
| 104 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe( false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object >(); | 104 v8::MaybeLocal<v8::Object> commandLineAPI = includeCommandLineAPI.fromMaybe( false) ? injectedScript->commandLineAPI(errorString) : v8::MaybeLocal<v8::Object >(); |
| 105 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty()) | 105 if (includeCommandLineAPI.fromMaybe(false) && commandLineAPI.IsEmpty()) |
| 106 return; | 106 return; |
| 107 | 107 |
| 108 InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedSc ript, nullptr, commandLineAPI); | |
| 109 | |
| 110 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); | |
| 111 | |
| 112 v8::TryCatch tryCatch(injectedScript->isolate()); | 108 v8::TryCatch tryCatch(injectedScript->isolate()); |
| 113 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->compileAndRunIntern alScript(localContext, toV8String(injectedScript->isolate(), expression)); | 109 v8::MaybeLocal<v8::Value> maybeResultValue = evaluateInternal(injectedScript , doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false), expression, commandLine API); |
| 114 | 110 |
| 115 // InjectedScript may be gone after any evaluate call - find it again. | 111 // InjectedScript may be gone after any evaluate call - find it again. |
| 116 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, ex ecutionContextId.fromJust()); | 112 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, ex ecutionContextId.fromJust()); |
| 117 if (!injectedScript) | 113 if (!injectedScript) |
| 118 return; | 114 return; |
| 119 | 115 |
| 120 injectedScript->wrapEvaluateResult(errorString, | 116 injectedScript->wrapEvaluateResult(errorString, |
| 121 maybeResultValue, | 117 maybeResultValue, |
| 122 tryCatch, | 118 tryCatch, |
| 123 objectGroup.fromMaybe(""), | 119 objectGroup.fromMaybe(""), |
| 124 returnByValue.fromMaybe(false), | 120 returnByValue.fromMaybe(false), |
| 125 generatePreview.fromMaybe(false), | 121 generatePreview.fromMaybe(false), |
| 126 result, | 122 result, |
| 127 wasThrown, | 123 wasThrown, |
| 128 exceptionDetails); | 124 exceptionDetails); |
| 129 } | 125 } |
| 130 | 126 |
| 127 v8::MaybeLocal<v8::Value> V8RuntimeAgentImpl::evaluateInternal(InjectedScript* i njectedScript, bool doNotPauseOnExceptionsAndMuteConsole, const String& expressi on, v8::MaybeLocal<v8::Object> extension) | |
| 128 { | |
| 129 InjectedScriptManager::ScopedGlobalObjectExtension scopeExtension(injectedSc ript, nullptr, extension); | |
| 130 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole ? m_debugger : nullptr); | |
| 131 return m_debugger->compileAndRunInternalScript(injectedScript->context(), to V8String(injectedScript->isolate(), expression)); | |
| 132 } | |
| 133 | |
| 131 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, | 134 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, |
| 132 const String16& objectId, | 135 const String16& objectId, |
| 133 const String16& expression, | 136 const String16& expression, |
| 134 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents, | 137 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents, |
| 135 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 138 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 136 const Maybe<bool>& returnByValue, | 139 const Maybe<bool>& returnByValue, |
| 137 const Maybe<bool>& generatePreview, | 140 const Maybe<bool>& generatePreview, |
| 138 const Maybe<bool>& userGesture, | 141 const Maybe<bool>& userGesture, |
| 139 OwnPtr<RemoteObject>* result, | 142 OwnPtr<RemoteObject>* result, |
| 140 Maybe<bool>* wasThrown) | 143 Maybe<bool>* wasThrown) |
| 141 { | 144 { |
| 142 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI d); | 145 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI d); |
| 143 if (!remoteId) | 146 if (!remoteId) |
| 144 return; | 147 return; |
| 145 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); | 148 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, remoteId.get()); |
| 146 if (!injectedScript) | 149 if (!injectedScript) |
| 147 return; | 150 return; |
| 148 String16 arguments; | 151 |
| 149 if (optionalArguments.isJust()) | 152 v8::HandleScope scope(injectedScript->isolate()); |
| 150 arguments = protocol::toValue(optionalArguments.fromJust())->toJSONStrin g(); | 153 v8::Local<v8::Context> localContext = injectedScript->context(); |
| 154 v8::Context::Scope contextScope(localContext); | |
| 155 | |
| 156 if (!injectedScript->canAccessInspectedWindow()) { | |
| 157 *errorString = "Can not access given context"; | |
| 158 return; | |
| 159 } | |
| 160 | |
| 161 String16 objectGroupName = injectedScript->objectGroupName(*remoteId); | |
| 162 v8::Local<v8::Value> object = injectedScript->findObject(*remoteId); | |
| 163 if (object.IsEmpty()) { | |
| 164 *errorString = "Could not find object with given id"; | |
| 165 return; | |
| 166 } | |
| 167 OwnPtr<v8::Local<v8::Value>[]> argv = nullptr; | |
| 168 int argc = 0; | |
| 169 if (optionalArguments.isJust()) { | |
| 170 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr guments.fromJust(); | |
| 171 argc = arguments->length(); | |
| 172 argv = adoptArrayPtr(new v8::Local<v8::Value>[argc]); | |
| 173 for (int i = 0; i < argc; ++i) { | |
| 174 v8::Local<v8::Value> argumentValue; | |
| 175 if (!injectedScript->resolveCallArgument(errorString, arguments->get (i)).ToLocal(&argumentValue)) | |
| 176 return; | |
| 177 argv[i] = argumentValue; | |
| 178 } | |
| 179 } | |
| 151 | 180 |
| 152 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); | 181 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); |
| 153 injectedScript->callFunctionOn(errorString, objectId, expression, arguments, returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), result, wasTh rown); | 182 |
| 183 v8::MaybeLocal<v8::Object> remoteObjectAPI = injectedScript->remoteObjectAPI (errorString, objectGroupName); | |
| 184 if (remoteObjectAPI.IsEmpty()) | |
| 185 return; | |
| 186 | |
| 187 v8::TryCatch tryCatch(injectedScript->isolate()); | |
| 188 v8::MaybeLocal<v8::Value> maybeFunctionValue = evaluateInternal(injectedScri pt, doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false), "(" + expression + ") ", remoteObjectAPI); | |
|
dgozman
2016/03/18 19:51:28
Let's refetch injectedScript after this evaluate.
kozy
2016/03/18 22:14:39
Done.
| |
| 189 | |
| 190 if (tryCatch.HasCaught()) { | |
| 191 injectedScript->wrapEvaluateResult(errorString, maybeFunctionValue, tryC atch, objectGroupName, false, false, result, wasThrown, nullptr); | |
| 192 return; | |
| 193 } | |
| 194 | |
| 195 v8::Local<v8::Value> functionValue; | |
| 196 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio n()) { | |
| 197 *errorString = "Given expression does not evaluate to a function"; | |
| 198 return; | |
| 199 } | |
| 200 | |
| 201 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->callFunction(functi onValue.As<v8::Function>(), injectedScript->context(), object, argc, argv.get()) ; | |
| 202 // InjectedScript may be gone after any evaluate call - find it again. | |
| 203 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, re moteId.get()); | |
| 204 if (!injectedScript) | |
| 205 return; | |
| 206 | |
| 207 injectedScript->wrapEvaluateResult(errorString, maybeResultValue, tryCatch, objectGroupName, returnByValue.fromMaybe(false), generatePreview.fromMaybe(false ), result, wasThrown, nullptr); | |
| 154 } | 208 } |
| 155 | 209 |
| 156 void V8RuntimeAgentImpl::getProperties( | 210 void V8RuntimeAgentImpl::getProperties( |
| 157 ErrorString* errorString, | 211 ErrorString* errorString, |
| 158 const String16& objectId, | 212 const String16& objectId, |
| 159 const Maybe<bool>& ownProperties, | 213 const Maybe<bool>& ownProperties, |
| 160 const Maybe<bool>& accessorPropertiesOnly, | 214 const Maybe<bool>& accessorPropertiesOnly, |
| 161 const Maybe<bool>& generatePreview, | 215 const Maybe<bool>& generatePreview, |
| 162 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, | 216 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, |
| 163 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter nalProperties, | 217 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter nalProperties, |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 | 491 |
| 438 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> context) | 492 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> context) |
| 439 { | 493 { |
| 440 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); | 494 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); |
| 441 if (!m_enabled) | 495 if (!m_enabled) |
| 442 return; | 496 return; |
| 443 m_frontend->executionContextDestroyed(contextId); | 497 m_frontend->executionContextDestroyed(contextId); |
| 444 } | 498 } |
| 445 | 499 |
| 446 } // namespace blink | 500 } // namespace blink |
| OLD | NEW |