Chromium Code Reviews| Index: third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp |
| diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp |
| index 090b8c13e63303a963a6375a3b12bb2b184dae91..92a07f912413dad829ec972e521368ee97c80f92 100644 |
| --- a/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp |
| +++ b/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp |
| @@ -50,6 +50,25 @@ static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled |
| using protocol::Runtime::ExceptionDetails; |
| using protocol::Runtime::RemoteObject; |
| +static PassOwnPtr<ExceptionDetails> createExceptionDetails(V8Debugger* debugger, v8::Local<v8::Context> context, v8::Local<v8::Message> message) |
| +{ |
| + OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetailsObject = protocol::Runtime::ExceptionDetails::create().setText(toProtocolString(message->Get())).build(); |
| + exceptionDetailsObject->setUrl(toProtocolStringWithTypeCheck(message->GetScriptResourceName())); |
| + exceptionDetailsObject->setScriptId(String16::number(message->GetScriptOrigin().ScriptID()->Value())); |
| + |
| + v8::Maybe<int> lineNumber = message->GetLineNumber(context); |
| + if (lineNumber.IsJust()) |
| + exceptionDetailsObject->setLine(lineNumber.FromJust()); |
| + v8::Maybe<int> columnNumber = message->GetStartColumn(context); |
| + if (columnNumber.IsJust()) |
| + exceptionDetailsObject->setColumn(columnNumber.FromJust()); |
| + |
| + v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace(); |
| + if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) |
| + exceptionDetailsObject->setStack(debugger->createStackTrace(stackTrace, stackTrace->GetFrameCount())->buildInspectorObject()); |
| + return exceptionDetailsObject.release(); |
| +} |
| + |
| PassOwnPtr<V8RuntimeAgent> V8RuntimeAgent::create(V8Debugger* debugger, int contextGroupId) |
| { |
| return adoptPtr(new V8RuntimeAgentImpl(static_cast<V8DebuggerImpl*>(debugger), contextGroupId)); |
| @@ -211,7 +230,7 @@ void V8RuntimeAgentImpl::compileScript(ErrorString* errorString, |
| if (script.IsEmpty()) { |
| v8::Local<v8::Message> message = tryCatch.Message(); |
| if (!message.IsEmpty()) |
| - *exceptionDetails = createExceptionDetails(isolate, message); |
| + *exceptionDetails = createExceptionDetails(m_debugger, injectedScript->context(), message); |
| else |
| *errorString = "Script compilation failed"; |
| return; |
| @@ -266,12 +285,17 @@ void V8RuntimeAgentImpl::runScript(ErrorString* errorString, |
| v8::TryCatch tryCatch(isolate); |
| v8::Local<v8::Value> value; |
| - v8::MaybeLocal<v8::Value> maybeValue = injectedScript->runCompiledScript(script, includeCommandLineAPI.fromMaybe(false)); |
| + |
| + InjectedScriptManager::InjectScopeExtensionByName scopeExtension(errorString, injectedScript, false, "commandLineAPI"); |
| + if (scopeExtension.hasError()) |
| + return; |
| + |
| + v8::MaybeLocal<v8::Value> maybeValue = m_debugger->runCompiledScript(context, script); |
| if (maybeValue.IsEmpty()) { |
| value = tryCatch.Exception(); |
| v8::Local<v8::Message> message = tryCatch.Message(); |
| if (!message.IsEmpty()) |
| - *exceptionDetails = createExceptionDetails(isolate, message); |
| + *exceptionDetails = createExceptionDetails(m_debugger, injectedScript->context(), message); |
| } else { |
| value = maybeValue.ToLocalChecked(); |
| } |
| @@ -281,7 +305,16 @@ void V8RuntimeAgentImpl::runScript(ErrorString* errorString, |
| return; |
| } |
| - *result = injectedScript->wrapObject(value, objectGroup.fromMaybe("")); |
| + injectedScript = m_injectedScriptManager->findInjectedScript(executionContextId); |
|
dgozman
2016/03/17 19:16:12
Same comment here.
kozy
2016/03/17 20:48:56
Done.
|
| + if (!injectedScript) { |
| + *errorString = "Inspected frame has gone during script running"; |
| + return; |
| + } |
| + |
| + 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.
|
| + if (!resultObject) |
| + return; |
| + *result = resultObject.release(); |
| } |
| void V8RuntimeAgentImpl::setInspectorState(protocol::DictionaryValue* state) |
| @@ -352,7 +385,8 @@ PassOwnPtr<RemoteObject> V8RuntimeAgentImpl::wrapObject(v8::Local<v8::Context> c |
| InjectedScript* injectedScript = m_injectedScriptManager->injectedScriptFor(context); |
| if (!injectedScript) |
| return nullptr; |
| - return injectedScript->wrapObject(value, groupName, generatePreview); |
| + ErrorString errorString; |
| + return injectedScript->wrapObject(&errorString, value, groupName, false, generatePreview); |
| } |
| PassOwnPtr<RemoteObject> V8RuntimeAgentImpl::wrapTable(v8::Local<v8::Context> context, v8::Local<v8::Value> table, v8::Local<v8::Value> columns) |
| @@ -419,15 +453,34 @@ void V8RuntimeAgentImpl::reportExecutionContextDestroyed(v8::Local<v8::Context> |
| m_frontend->executionContextDestroyed(contextId); |
| } |
| -PassOwnPtr<ExceptionDetails> V8RuntimeAgentImpl::createExceptionDetails(v8::Isolate* isolate, v8::Local<v8::Message> message) |
| +void V8RuntimeAgentImpl::wrapEvaluateResult(ErrorString* errorString, V8Debugger* debugger, InjectedScript* injectedScript, v8::Local<v8::Value> resultValue, v8::TryCatch& tryCatch, const String16& objectGroup, bool returnByValue, bool generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) |
| { |
| - OwnPtr<ExceptionDetails> exceptionDetails = ExceptionDetails::create().setText(toProtocolStringWithTypeCheck(message->Get())).build(); |
| - exceptionDetails->setLine(message->GetLineNumber()); |
| - exceptionDetails->setColumn(message->GetStartColumn()); |
| - v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace(); |
| - if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount() > 0) |
| - exceptionDetails->setStack(m_debugger->createStackTrace(messageStackTrace, messageStackTrace->GetFrameCount())->buildInspectorObject()); |
| - return exceptionDetails.release(); |
| + if (!tryCatch.HasCaught()) { |
| + if (resultValue.IsEmpty()) { |
| + *errorString = "Internal error"; |
| + return; |
| + } |
| + OwnPtr<RemoteObject> remoteObject = injectedScript->wrapObject(errorString, resultValue, objectGroup, returnByValue, generatePreview); |
| + if (!remoteObject) |
| + return; |
| + if (objectGroup == "console" && !injectedScript->setLastEvaluationResult(errorString, resultValue)) |
| + return; |
| + *result = remoteObject.release(); |
| + *wasThrown = false; |
| + } else { |
| + v8::Local<v8::Value> exception = tryCatch.Exception(); |
| + OwnPtr<RemoteObject> remoteObject = injectedScript->wrapObject(errorString, exception, objectGroup, false, generatePreview && !exception->IsNativeError()); |
| + if (!remoteObject) |
| + return; |
| + *result = remoteObject.release(); |
|
dgozman
2016/03/17 19:16:12
Move after error checking.
kozy
2016/03/17 20:48:56
Done.
|
| + OwnPtr<ExceptionDetails> exceptionDetailsObject = createExceptionDetails(debugger, injectedScript->context(), tryCatch.Message()); |
| + if (!exceptionDetailsObject) { |
|
dgozman
2016/03/17 19:16:12
It always returns something.
kozy
2016/03/17 20:48:56
Done.
|
| + *errorString = "Internal error"; |
| + return; |
| + } |
| + *exceptionDetails = exceptionDetailsObject.release(); |
| + *wasThrown = true; |
| + } |
| } |
| } // namespace blink |