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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 const Maybe<bool>& generatePreview, | 101 const Maybe<bool>& generatePreview, |
| 102 const Maybe<bool>& userGesture, | 102 const Maybe<bool>& userGesture, |
| 103 OwnPtr<RemoteObject>* result, | 103 OwnPtr<RemoteObject>* result, |
| 104 Maybe<bool>* wasThrown, | 104 Maybe<bool>* wasThrown, |
| 105 Maybe<ExceptionDetails>* exceptionDetails) | 105 Maybe<ExceptionDetails>* exceptionDetails) |
| 106 { | 106 { |
| 107 if (!executionContextId.isJust()) { | 107 if (!executionContextId.isJust()) { |
| 108 *errorString = "Cannot find default execution context"; | 108 *errorString = "Cannot find default execution context"; |
| 109 return; | 109 return; |
| 110 } | 110 } |
| 111 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (executionContextId.fromJust()); | 111 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, executionContextId.fromJust()); |
| 112 if (!injectedScript) { | 112 if (!injectedScript) |
| 113 *errorString = "Cannot find execution context with given id"; | 113 return; |
| 114 | |
| 115 v8::HandleScope scope(injectedScript->isolate()); | |
| 116 v8::Local<v8::Context> localContext = injectedScript->context(); | |
| 117 v8::Context::Scope contextScope(localContext); | |
| 118 | |
| 119 if (!injectedScript->canAccessInspectedWindow()) { | |
| 120 *errorString = "Can not access given context"; | |
| 121 return; | |
| 122 } | |
| 123 InjectedScriptManager::InjectScopeExtensionByName scopeExtension(errorString , injectedScript, false, includeCommandLineAPI.fromMaybe(false) ? "commandLineAP I" : String16()); | |
| 124 if (scopeExtension.hasError()) { | |
| 125 *errorString = "Internal error"; | |
| 114 return; | 126 return; |
| 115 } | 127 } |
| 116 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); | 128 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); |
| 117 injectedScript->evaluate(errorString, expression, objectGroup.fromMaybe(""), includeCommandLineAPI.fromMaybe(false), returnByValue.fromMaybe(false), generat ePreview.fromMaybe(false), result, wasThrown, exceptionDetails); | 129 |
| 130 v8::TryCatch tryCatch(injectedScript->isolate()); | |
| 131 | |
| 132 v8::Local<v8::Value> resultValue; | |
| 133 bool success = m_debugger->compileAndRunInternalScript(localContext, toV8Str ing(injectedScript->isolate(), expression)).ToLocal(&resultValue); | |
| 134 ALLOW_UNUSED_LOCAL(success); | |
| 135 | |
| 136 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, ex ecutionContextId.fromJust()); | |
|
pfeldman
2016/03/17 21:24:22
Is there a chance m_injectedScriptManager no longe
kozy
2016/03/17 21:27:58
We keep OwnPtr to manager in this agent.
| |
| 137 if (!injectedScript) | |
| 138 return; | |
| 139 | |
| 140 V8RuntimeAgentImpl::wrapEvaluateResult(errorString, | |
| 141 m_debugger, | |
| 142 injectedScript, | |
| 143 resultValue, | |
| 144 tryCatch, | |
| 145 objectGroup.fromMaybe(""), | |
| 146 returnByValue.fromMaybe(false), | |
| 147 generatePreview.fromMaybe(false), | |
| 148 result, | |
| 149 wasThrown, | |
| 150 exceptionDetails); | |
| 118 } | 151 } |
| 119 | 152 |
| 120 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, | 153 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, |
| 121 const String16& objectId, | 154 const String16& objectId, |
| 122 const String16& expression, | 155 const String16& expression, |
| 123 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents, | 156 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents, |
| 124 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 157 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 125 const Maybe<bool>& returnByValue, | 158 const Maybe<bool>& returnByValue, |
| 126 const Maybe<bool>& generatePreview, | 159 const Maybe<bool>& generatePreview, |
| 127 const Maybe<bool>& userGesture, | 160 const Maybe<bool>& userGesture, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 const String16& sourceURL, | 242 const String16& sourceURL, |
| 210 bool persistScript, | 243 bool persistScript, |
| 211 int executionContextId, | 244 int executionContextId, |
| 212 Maybe<String16>* scriptId, | 245 Maybe<String16>* scriptId, |
| 213 Maybe<ExceptionDetails>* exceptionDetails) | 246 Maybe<ExceptionDetails>* exceptionDetails) |
| 214 { | 247 { |
| 215 if (!m_enabled) { | 248 if (!m_enabled) { |
| 216 *errorString = "Runtime agent is not enabled"; | 249 *errorString = "Runtime agent is not enabled"; |
| 217 return; | 250 return; |
| 218 } | 251 } |
| 219 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (executionContextId); | 252 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, executionContextId); |
| 220 if (!injectedScript) { | 253 if (!injectedScript) |
| 221 *errorString = "Inspected frame has gone"; | |
| 222 return; | 254 return; |
| 223 } | |
| 224 | 255 |
| 225 v8::Isolate* isolate = injectedScript->isolate(); | 256 v8::Isolate* isolate = injectedScript->isolate(); |
| 226 v8::HandleScope handles(isolate); | 257 v8::HandleScope handles(isolate); |
| 227 v8::Context::Scope scope(injectedScript->context()); | 258 v8::Context::Scope scope(injectedScript->context()); |
| 228 v8::TryCatch tryCatch(isolate); | 259 v8::TryCatch tryCatch(isolate); |
| 229 v8::Local<v8::Script> script = m_debugger->compileInternalScript(injectedScr ipt->context(), toV8String(isolate, expression), sourceURL); | 260 v8::Local<v8::Script> script = m_debugger->compileInternalScript(injectedScr ipt->context(), toV8String(isolate, expression), sourceURL); |
| 230 if (script.IsEmpty()) { | 261 if (script.IsEmpty()) { |
| 231 v8::Local<v8::Message> message = tryCatch.Message(); | 262 v8::Local<v8::Message> message = tryCatch.Message(); |
| 232 if (!message.IsEmpty()) | 263 if (!message.IsEmpty()) |
| 233 *exceptionDetails = createExceptionDetails(m_debugger, injectedScrip t->context(), message); | 264 *exceptionDetails = createExceptionDetails(m_debugger, injectedScrip t->context(), message); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 251 const Maybe<String16>& objectGroup, | 282 const Maybe<String16>& objectGroup, |
| 252 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 283 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 253 const Maybe<bool>& includeCommandLineAPI, | 284 const Maybe<bool>& includeCommandLineAPI, |
| 254 OwnPtr<RemoteObject>* result, | 285 OwnPtr<RemoteObject>* result, |
| 255 Maybe<ExceptionDetails>* exceptionDetails) | 286 Maybe<ExceptionDetails>* exceptionDetails) |
| 256 { | 287 { |
| 257 if (!m_enabled) { | 288 if (!m_enabled) { |
| 258 *errorString = "Runtime agent is not enabled"; | 289 *errorString = "Runtime agent is not enabled"; |
| 259 return; | 290 return; |
| 260 } | 291 } |
| 261 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (executionContextId); | 292 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript (errorString, executionContextId); |
| 262 if (!injectedScript) { | 293 if (!injectedScript) |
| 263 *errorString = "Inspected frame has gone"; | |
| 264 return; | 294 return; |
| 265 } | |
| 266 | 295 |
| 267 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); | 296 IgnoreExceptionsScope ignoreExceptionsScope(doNotPauseOnExceptionsAndMuteCon sole.fromMaybe(false) ? m_debugger : nullptr); |
| 268 | 297 |
| 269 if (!m_compiledScripts.contains(scriptId)) { | 298 if (!m_compiledScripts.contains(scriptId)) { |
| 270 *errorString = "Script execution failed"; | 299 *errorString = "Script execution failed"; |
| 271 return; | 300 return; |
| 272 } | 301 } |
| 273 | 302 |
| 274 v8::Isolate* isolate = injectedScript->isolate(); | 303 v8::Isolate* isolate = injectedScript->isolate(); |
| 275 v8::HandleScope handles(isolate); | 304 v8::HandleScope handles(isolate); |
| 276 v8::Local<v8::Context> context = injectedScript->context(); | 305 v8::Local<v8::Context> context = injectedScript->context(); |
| 277 v8::Context::Scope scope(context); | 306 v8::Context::Scope scope(context); |
| 278 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script Id); | 307 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script Id); |
| 279 v8::Local<v8::Script> script = scriptWrapper->Get(isolate); | 308 v8::Local<v8::Script> script = scriptWrapper->Get(isolate); |
| 280 | 309 |
| 281 if (script.IsEmpty()) { | 310 if (script.IsEmpty()) { |
| 282 *errorString = "Script execution failed"; | 311 *errorString = "Script execution failed"; |
| 283 return; | 312 return; |
| 284 } | 313 } |
| 285 v8::TryCatch tryCatch(isolate); | 314 v8::TryCatch tryCatch(isolate); |
| 286 | 315 |
| 287 v8::Local<v8::Value> value; | |
| 288 | |
| 289 InjectedScriptManager::InjectScopeExtensionByName scopeExtension(errorString , injectedScript, false, "commandLineAPI"); | 316 InjectedScriptManager::InjectScopeExtensionByName scopeExtension(errorString , injectedScript, false, "commandLineAPI"); |
| 290 if (scopeExtension.hasError()) | 317 if (scopeExtension.hasError()) |
| 291 return; | 318 return; |
| 292 | 319 |
| 293 v8::MaybeLocal<v8::Value> maybeValue = m_debugger->runCompiledScript(context , script); | 320 v8::Local<v8::Value> resultValue; |
| 294 if (maybeValue.IsEmpty()) { | 321 bool success = m_debugger->runCompiledScript(context, script).ToLocal(&resul tValue); |
| 295 value = tryCatch.Exception(); | 322 ALLOW_UNUSED_LOCAL(success); |
| 296 v8::Local<v8::Message> message = tryCatch.Message(); | |
| 297 if (!message.IsEmpty()) | |
| 298 *exceptionDetails = createExceptionDetails(m_debugger, injectedScrip t->context(), message); | |
| 299 } else { | |
| 300 value = maybeValue.ToLocalChecked(); | |
| 301 } | |
| 302 | 323 |
| 303 if (value.IsEmpty()) { | 324 injectedScript = m_injectedScriptManager->findInjectedScript(errorString, ex ecutionContextId); |
| 304 *errorString = "Script execution failed"; | 325 if (!injectedScript) |
| 305 return; | 326 return; |
| 306 } | |
| 307 | 327 |
| 308 injectedScript = m_injectedScriptManager->findInjectedScript(executionContex tId); | 328 V8RuntimeAgentImpl::wrapEvaluateResult(errorString, |
| 309 if (!injectedScript) { | 329 m_debugger, |
| 310 *errorString = "Inspected frame has gone during script running"; | 330 injectedScript, |
| 311 return; | 331 resultValue, |
| 312 } | 332 tryCatch, |
| 313 | 333 objectGroup.fromMaybe(""), |
| 314 OwnPtr<RemoteObject> resultObject = injectedScript->wrapObject(errorString, value, objectGroup.fromMaybe("")); | 334 false, |
| 315 if (!resultObject) | 335 false, |
| 316 return; | 336 result, |
| 317 *result = resultObject.release(); | 337 nullptr, |
| 338 exceptionDetails); | |
| 318 } | 339 } |
| 319 | 340 |
| 320 void V8RuntimeAgentImpl::setInspectorState(protocol::DictionaryValue* state) | 341 void V8RuntimeAgentImpl::setInspectorState(protocol::DictionaryValue* state) |
| 321 { | 342 { |
| 322 m_state = state; | 343 m_state = state; |
| 323 } | 344 } |
| 324 | 345 |
| 325 void V8RuntimeAgentImpl::setFrontend(protocol::Frontend::Runtime* frontend) | 346 void V8RuntimeAgentImpl::setFrontend(protocol::Frontend::Runtime* frontend) |
| 326 { | 347 { |
| 327 m_frontend = frontend; | 348 m_frontend = frontend; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 if (resultValue.IsEmpty()) { | 480 if (resultValue.IsEmpty()) { |
| 460 *errorString = "Internal error"; | 481 *errorString = "Internal error"; |
| 461 return; | 482 return; |
| 462 } | 483 } |
| 463 OwnPtr<RemoteObject> remoteObject = injectedScript->wrapObject(errorStri ng, resultValue, objectGroup, returnByValue, generatePreview); | 484 OwnPtr<RemoteObject> remoteObject = injectedScript->wrapObject(errorStri ng, resultValue, objectGroup, returnByValue, generatePreview); |
| 464 if (!remoteObject) | 485 if (!remoteObject) |
| 465 return; | 486 return; |
| 466 if (objectGroup == "console" && !injectedScript->setLastEvaluationResult (errorString, resultValue)) | 487 if (objectGroup == "console" && !injectedScript->setLastEvaluationResult (errorString, resultValue)) |
| 467 return; | 488 return; |
| 468 *result = remoteObject.release(); | 489 *result = remoteObject.release(); |
| 469 *wasThrown = false; | 490 if (wasThrown) |
| 491 *wasThrown = false; | |
| 470 } else { | 492 } else { |
| 471 v8::Local<v8::Value> exception = tryCatch.Exception(); | 493 v8::Local<v8::Value> exception = tryCatch.Exception(); |
| 472 OwnPtr<RemoteObject> remoteObject = injectedScript->wrapObject(errorStri ng, exception, objectGroup, false, generatePreview && !exception->IsNativeError( )); | 494 OwnPtr<RemoteObject> remoteObject = injectedScript->wrapObject(errorStri ng, exception, objectGroup, false, generatePreview && !exception->IsNativeError( )); |
| 473 if (!remoteObject) | 495 if (!remoteObject) |
| 474 return; | 496 return; |
| 475 *result = remoteObject.release(); | |
| 476 OwnPtr<ExceptionDetails> exceptionDetailsObject = createExceptionDetails (debugger, injectedScript->context(), tryCatch.Message()); | 497 OwnPtr<ExceptionDetails> exceptionDetailsObject = createExceptionDetails (debugger, injectedScript->context(), tryCatch.Message()); |
| 477 if (!exceptionDetailsObject) { | 498 if (!exceptionDetailsObject) { |
| 478 *errorString = "Internal error"; | 499 *errorString = "Internal error"; |
| 479 return; | 500 return; |
| 480 } | 501 } |
| 502 *result = remoteObject.release(); | |
| 481 *exceptionDetails = exceptionDetailsObject.release(); | 503 *exceptionDetails = exceptionDetailsObject.release(); |
| 482 *wasThrown = true; | 504 if (wasThrown) |
| 505 *wasThrown = true; | |
| 483 } | 506 } |
| 484 } | 507 } |
| 485 | 508 |
| 486 } // namespace blink | 509 } // namespace blink |
| OLD | NEW |