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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 namespace V8RuntimeAgentImplState { | 46 namespace V8RuntimeAgentImplState { |
| 47 static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled "; | 47 static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled "; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 using protocol::Runtime::ExceptionDetails; | 50 using protocol::Runtime::ExceptionDetails; |
| 51 using protocol::Runtime::RemoteObject; | 51 using protocol::Runtime::RemoteObject; |
| 52 | 52 |
| 53 static PassOwnPtr<ExceptionDetails> createExceptionDetails(V8Debugger* debugger, v8::Local<v8::Context> context, v8::Local<v8::Message> message) | |
| 54 { | |
| 55 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetailsObject = protoco l::Runtime::ExceptionDetails::create().setText(toProtocolString(message->Get())) .build(); | |
| 56 exceptionDetailsObject->setUrl(toProtocolStringWithTypeCheck(message->GetScr iptResourceName())); | |
| 57 exceptionDetailsObject->setScriptId(String16::number(message->GetScriptOrigi n().ScriptID()->Value())); | |
| 58 | |
| 59 v8::Maybe<int> lineNumber = message->GetLineNumber(context); | |
| 60 if (lineNumber.IsJust()) | |
| 61 exceptionDetailsObject->setLine(lineNumber.FromJust()); | |
| 62 v8::Maybe<int> columnNumber = message->GetStartColumn(context); | |
| 63 if (columnNumber.IsJust()) | |
| 64 exceptionDetailsObject->setColumn(columnNumber.FromJust()); | |
| 65 | |
| 66 v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace(); | |
| 67 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) | |
| 68 exceptionDetailsObject->setStack(debugger->createStackTrace(stackTrace, stackTrace->GetFrameCount())->buildInspectorObject()); | |
| 69 return exceptionDetailsObject.release(); | |
| 70 } | |
| 71 | |
| 53 PassOwnPtr<V8RuntimeAgent> V8RuntimeAgent::create(V8Debugger* debugger, int cont extGroupId) | 72 PassOwnPtr<V8RuntimeAgent> V8RuntimeAgent::create(V8Debugger* debugger, int cont extGroupId) |
| 54 { | 73 { |
| 55 return adoptPtr(new V8RuntimeAgentImpl(static_cast<V8DebuggerImpl*>(debugger ), contextGroupId)); | 74 return adoptPtr(new V8RuntimeAgentImpl(static_cast<V8DebuggerImpl*>(debugger ), contextGroupId)); |
| 56 } | 75 } |
| 57 | 76 |
| 58 V8RuntimeAgentImpl::V8RuntimeAgentImpl(V8DebuggerImpl* debugger, int contextGrou pId) | 77 V8RuntimeAgentImpl::V8RuntimeAgentImpl(V8DebuggerImpl* debugger, int contextGrou pId) |
| 59 : m_contextGroupId(contextGroupId) | 78 : m_contextGroupId(contextGroupId) |
| 60 , m_state(nullptr) | 79 , m_state(nullptr) |
| 61 , m_frontend(nullptr) | 80 , m_frontend(nullptr) |
| 62 , m_injectedScriptManager(InjectedScriptManager::create(debugger)) | 81 , m_injectedScriptManager(InjectedScriptManager::create(debugger)) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 } | 223 } |
| 205 | 224 |
| 206 v8::Isolate* isolate = injectedScript->isolate(); | 225 v8::Isolate* isolate = injectedScript->isolate(); |
| 207 v8::HandleScope handles(isolate); | 226 v8::HandleScope handles(isolate); |
| 208 v8::Context::Scope scope(injectedScript->context()); | 227 v8::Context::Scope scope(injectedScript->context()); |
| 209 v8::TryCatch tryCatch(isolate); | 228 v8::TryCatch tryCatch(isolate); |
| 210 v8::Local<v8::Script> script = m_debugger->compileInternalScript(injectedScr ipt->context(), toV8String(isolate, expression), sourceURL); | 229 v8::Local<v8::Script> script = m_debugger->compileInternalScript(injectedScr ipt->context(), toV8String(isolate, expression), sourceURL); |
| 211 if (script.IsEmpty()) { | 230 if (script.IsEmpty()) { |
| 212 v8::Local<v8::Message> message = tryCatch.Message(); | 231 v8::Local<v8::Message> message = tryCatch.Message(); |
| 213 if (!message.IsEmpty()) | 232 if (!message.IsEmpty()) |
| 214 *exceptionDetails = createExceptionDetails(isolate, message); | 233 *exceptionDetails = createExceptionDetails(m_debugger, injectedScrip t->context(), message); |
| 215 else | 234 else |
| 216 *errorString = "Script compilation failed"; | 235 *errorString = "Script compilation failed"; |
| 217 return; | 236 return; |
| 218 } | 237 } |
| 219 | 238 |
| 220 if (!persistScript) | 239 if (!persistScript) |
| 221 return; | 240 return; |
| 222 | 241 |
| 223 String16 scriptValueId = String16::number(script->GetUnboundScript()->GetId( )); | 242 String16 scriptValueId = String16::number(script->GetUnboundScript()->GetId( )); |
| 224 OwnPtr<v8::Global<v8::Script>> global = adoptPtr(new v8::Global<v8::Script>( isolate, script)); | 243 OwnPtr<v8::Global<v8::Script>> global = adoptPtr(new v8::Global<v8::Script>( isolate, script)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script Id); | 278 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script Id); |
| 260 v8::Local<v8::Script> script = scriptWrapper->Get(isolate); | 279 v8::Local<v8::Script> script = scriptWrapper->Get(isolate); |
| 261 | 280 |
| 262 if (script.IsEmpty()) { | 281 if (script.IsEmpty()) { |
| 263 *errorString = "Script execution failed"; | 282 *errorString = "Script execution failed"; |
| 264 return; | 283 return; |
| 265 } | 284 } |
| 266 v8::TryCatch tryCatch(isolate); | 285 v8::TryCatch tryCatch(isolate); |
| 267 | 286 |
| 268 v8::Local<v8::Value> value; | 287 v8::Local<v8::Value> value; |
| 269 v8::MaybeLocal<v8::Value> maybeValue = injectedScript->runCompiledScript(scr ipt, includeCommandLineAPI.fromMaybe(false)); | 288 |
| 289 InjectedScriptManager::InjectScopeExtensionByName scopeExtension(errorString , injectedScript, false, "commandLineAPI"); | |
| 290 if (scopeExtension.hasError()) | |
| 291 return; | |
| 292 | |
| 293 v8::MaybeLocal<v8::Value> maybeValue = m_debugger->runCompiledScript(context , script); | |
| 270 if (maybeValue.IsEmpty()) { | 294 if (maybeValue.IsEmpty()) { |
| 271 value = tryCatch.Exception(); | 295 value = tryCatch.Exception(); |
| 272 v8::Local<v8::Message> message = tryCatch.Message(); | 296 v8::Local<v8::Message> message = tryCatch.Message(); |
| 273 if (!message.IsEmpty()) | 297 if (!message.IsEmpty()) |
| 274 *exceptionDetails = createExceptionDetails(isolate, message); | 298 *exceptionDetails = createExceptionDetails(m_debugger, injectedScrip t->context(), message); |
| 275 } else { | 299 } else { |
| 276 value = maybeValue.ToLocalChecked(); | 300 value = maybeValue.ToLocalChecked(); |
| 277 } | 301 } |
| 278 | 302 |
| 279 if (value.IsEmpty()) { | 303 if (value.IsEmpty()) { |
| 280 *errorString = "Script execution failed"; | 304 *errorString = "Script execution failed"; |
| 281 return; | 305 return; |
| 282 } | 306 } |
| 283 | 307 |
| 284 *result = injectedScript->wrapObject(value, objectGroup.fromMaybe("")); | 308 injectedScript = m_injectedScriptManager->findInjectedScript(executionContex tId); |
|
dgozman
2016/03/17 19:16:12
Same comment here.
kozy
2016/03/17 20:48:56
Done.
| |
| 309 if (!injectedScript) { | |
| 310 *errorString = "Inspected frame has gone during script running"; | |
| 311 return; | |
| 312 } | |
| 313 | |
| 314 OwnPtr<RemoteObject> resultObject = injectedScript->wrapObject(errorString, value, objectGroup.fromMaybe("")); | |
|
dgozman
2016/03/17 19:16:12
Just return.
kozy
2016/03/17 20:48:56
Done.
| |
| 315 if (!resultObject) | |
| 316 return; | |
| 317 *result = resultObject.release(); | |
| 285 } | 318 } |
| 286 | 319 |
| 287 void V8RuntimeAgentImpl::setInspectorState(protocol::DictionaryValue* state) | 320 void V8RuntimeAgentImpl::setInspectorState(protocol::DictionaryValue* state) |
| 288 { | 321 { |
| 289 m_state = state; | 322 m_state = state; |
| 290 } | 323 } |
| 291 | 324 |
| 292 void V8RuntimeAgentImpl::setFrontend(protocol::Frontend::Runtime* frontend) | 325 void V8RuntimeAgentImpl::setFrontend(protocol::Frontend::Runtime* frontend) |
| 293 { | 326 { |
| 294 m_frontend = frontend; | 327 m_frontend = frontend; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 void V8RuntimeAgentImpl::setInspectObjectCallback(PassOwnPtr<V8RuntimeAgent::Ins pectCallback> callback) | 378 void V8RuntimeAgentImpl::setInspectObjectCallback(PassOwnPtr<V8RuntimeAgent::Ins pectCallback> callback) |
| 346 { | 379 { |
| 347 m_injectedScriptManager->injectedScriptHost()->setInspectObjectCallback(call back); | 380 m_injectedScriptManager->injectedScriptHost()->setInspectObjectCallback(call back); |
| 348 } | 381 } |
| 349 | 382 |
| 350 PassOwnPtr<RemoteObject> V8RuntimeAgentImpl::wrapObject(v8::Local<v8::Context> c ontext, v8::Local<v8::Value> value, const String16& groupName, bool generatePrev iew) | 383 PassOwnPtr<RemoteObject> V8RuntimeAgentImpl::wrapObject(v8::Local<v8::Context> c ontext, v8::Local<v8::Value> value, const String16& groupName, bool generatePrev iew) |
| 351 { | 384 { |
| 352 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( context); | 385 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( context); |
| 353 if (!injectedScript) | 386 if (!injectedScript) |
| 354 return nullptr; | 387 return nullptr; |
| 355 return injectedScript->wrapObject(value, groupName, generatePreview); | 388 ErrorString errorString; |
| 389 return injectedScript->wrapObject(&errorString, value, groupName, false, gen eratePreview); | |
| 356 } | 390 } |
| 357 | 391 |
| 358 PassOwnPtr<RemoteObject> V8RuntimeAgentImpl::wrapTable(v8::Local<v8::Context> co ntext, v8::Local<v8::Value> table, v8::Local<v8::Value> columns) | 392 PassOwnPtr<RemoteObject> V8RuntimeAgentImpl::wrapTable(v8::Local<v8::Context> co ntext, v8::Local<v8::Value> table, v8::Local<v8::Value> columns) |
| 359 { | 393 { |
| 360 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( context); | 394 InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor( context); |
| 361 if (!injectedScript) | 395 if (!injectedScript) |
| 362 return nullptr; | 396 return nullptr; |
| 363 return injectedScript->wrapTable(table, columns); | 397 return injectedScript->wrapTable(table, columns); |
| 364 } | 398 } |
| 365 | 399 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 } | 446 } |
| 413 | 447 |
| 414 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> context) | 448 void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> context) |
| 415 { | 449 { |
| 416 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); | 450 int contextId = m_injectedScriptManager->discardInjectedScriptFor(context); |
| 417 if (!m_enabled) | 451 if (!m_enabled) |
| 418 return; | 452 return; |
| 419 m_frontend->executionContextDestroyed(contextId); | 453 m_frontend->executionContextDestroyed(contextId); |
| 420 } | 454 } |
| 421 | 455 |
| 422 PassOwnPtr<ExceptionDetails> V8RuntimeAgentImpl::createExceptionDetails(v8::Isol ate* isolate, v8::Local<v8::Message> message) | 456 void V8RuntimeAgentImpl::wrapEvaluateResult(ErrorString* errorString, V8Debugger * debugger, InjectedScript* injectedScript, v8::Local<v8::Value> resultValue, v8 ::TryCatch& tryCatch, const String16& objectGroup, bool returnByValue, bool gene ratePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, Maybe<bool>* wasTh rown, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) |
| 423 { | 457 { |
| 424 OwnPtr<ExceptionDetails> exceptionDetails = ExceptionDetails::create().setTe xt(toProtocolStringWithTypeCheck(message->Get())).build(); | 458 if (!tryCatch.HasCaught()) { |
| 425 exceptionDetails->setLine(message->GetLineNumber()); | 459 if (resultValue.IsEmpty()) { |
| 426 exceptionDetails->setColumn(message->GetStartColumn()); | 460 *errorString = "Internal error"; |
| 427 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace(); | 461 return; |
| 428 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount() > 0) | 462 } |
| 429 exceptionDetails->setStack(m_debugger->createStackTrace(messageStackTrac e, messageStackTrace->GetFrameCount())->buildInspectorObject()); | 463 OwnPtr<RemoteObject> remoteObject = injectedScript->wrapObject(errorStri ng, resultValue, objectGroup, returnByValue, generatePreview); |
| 430 return exceptionDetails.release(); | 464 if (!remoteObject) |
| 465 return; | |
| 466 if (objectGroup == "console" && !injectedScript->setLastEvaluationResult (errorString, resultValue)) | |
| 467 return; | |
| 468 *result = remoteObject.release(); | |
| 469 *wasThrown = false; | |
| 470 } else { | |
| 471 v8::Local<v8::Value> exception = tryCatch.Exception(); | |
| 472 OwnPtr<RemoteObject> remoteObject = injectedScript->wrapObject(errorStri ng, exception, objectGroup, false, generatePreview && !exception->IsNativeError( )); | |
| 473 if (!remoteObject) | |
| 474 return; | |
| 475 *result = remoteObject.release(); | |
|
dgozman
2016/03/17 19:16:12
Move after error checking.
kozy
2016/03/17 20:48:56
Done.
| |
| 476 OwnPtr<ExceptionDetails> exceptionDetailsObject = createExceptionDetails (debugger, injectedScript->context(), tryCatch.Message()); | |
| 477 if (!exceptionDetailsObject) { | |
|
dgozman
2016/03/17 19:16:12
It always returns something.
kozy
2016/03/17 20:48:56
Done.
| |
| 478 *errorString = "Internal error"; | |
| 479 return; | |
| 480 } | |
| 481 *exceptionDetails = exceptionDetailsObject.release(); | |
| 482 *wasThrown = true; | |
| 483 } | |
| 431 } | 484 } |
| 432 | 485 |
| 433 } // namespace blink | 486 } // namespace blink |
| OLD | NEW |