Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Unified Diff: src/inspector/injected-script.cc

Issue 2467853003: [inspector] migrate Runtime to new style (Closed)
Patch Set: addressed comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/inspector/injected-script.h ('k') | src/inspector/injected-script-source.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/inspector/injected-script.cc
diff --git a/src/inspector/injected-script.cc b/src/inspector/injected-script.cc
index d966d60bc6c1acb3590e3750fe8b7981f62ef9e9..d605227222da50eb24c482557578c9a74b961034 100644
--- a/src/inspector/injected-script.cc
+++ b/src/inspector/injected-script.cc
@@ -54,11 +54,6 @@ using protocol::Runtime::InternalPropertyDescriptor;
using protocol::Runtime::RemoteObject;
using protocol::Maybe;
-static bool hasInternalError(ErrorString* errorString, bool hasError) {
- if (hasError) *errorString = "Internal error";
- return hasError;
-}
-
std::unique_ptr<InjectedScript> InjectedScript::create(
InspectedContext* inspectedContext) {
v8::Isolate* isolate = inspectedContext->isolate();
@@ -124,10 +119,9 @@ InjectedScript::InjectedScript(
InjectedScript::~InjectedScript() {}
-void InjectedScript::getProperties(
- ErrorString* errorString, v8::Local<v8::Object> object,
- const String16& groupName, bool ownProperties, bool accessorPropertiesOnly,
- bool generatePreview,
+Response InjectedScript::getProperties(
+ v8::Local<v8::Object> object, const String16& groupName, bool ownProperties,
+ bool accessorPropertiesOnly, bool generatePreview,
std::unique_ptr<Array<PropertyDescriptor>>* properties,
Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) {
v8::HandleScope handles(m_context->isolate());
@@ -143,21 +137,23 @@ void InjectedScript::getProperties(
v8::TryCatch tryCatch(m_context->isolate());
v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling();
if (tryCatch.HasCaught()) {
- *exceptionDetails = createExceptionDetails(errorString, tryCatch, groupName,
- generatePreview);
+ Response response = createExceptionDetails(
+ tryCatch, groupName, generatePreview, exceptionDetails);
+ if (!response.isSuccess()) return response;
// FIXME: make properties optional
*properties = Array<PropertyDescriptor>::create();
- return;
+ return Response::OK();
}
- if (hasInternalError(errorString, resultValue.IsEmpty())) return;
- std::unique_ptr<protocol::Value> protocolValue =
- toProtocolValue(errorString, context, resultValue);
- if (!protocolValue) return;
- protocol::ErrorSupport errors(errorString);
+ if (resultValue.IsEmpty()) return Response::InternalError();
+ std::unique_ptr<protocol::Value> protocolValue;
+ Response response = toProtocolValue(context, resultValue, &protocolValue);
+ if (!response.isSuccess()) return response;
+ protocol::ErrorSupport errors;
std::unique_ptr<Array<PropertyDescriptor>> result =
Array<PropertyDescriptor>::parse(protocolValue.get(), &errors);
- if (!hasInternalError(errorString, errors.hasErrors()))
- *properties = std::move(result);
+ if (errors.hasErrors()) return Response::Error(errors.errors());
+ *properties = std::move(result);
+ return Response::OK();
}
void InjectedScript::releaseObject(const String16& objectId) {
@@ -172,55 +168,52 @@ void InjectedScript::releaseObject(const String16& objectId) {
m_native->unbind(boundId);
}
-std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(
- ErrorString* errorString, v8::Local<v8::Value> value,
- const String16& groupName, bool forceValueType,
- bool generatePreview) const {
+Response InjectedScript::wrapObject(
+ v8::Local<v8::Value> value, const String16& groupName, bool forceValueType,
+ bool generatePreview,
+ std::unique_ptr<protocol::Runtime::RemoteObject>* result) const {
v8::HandleScope handles(m_context->isolate());
v8::Local<v8::Value> wrappedObject;
v8::Local<v8::Context> context = m_context->context();
- if (!wrapValue(errorString, value, groupName, forceValueType, generatePreview)
- .ToLocal(&wrappedObject))
- return nullptr;
+ Response response = wrapValue(value, groupName, forceValueType,
+ generatePreview, &wrappedObject);
+ if (!response.isSuccess()) return response;
protocol::ErrorSupport errors;
- std::unique_ptr<protocol::Value> protocolValue =
- toProtocolValue(errorString, context, wrappedObject);
- if (!protocolValue) return nullptr;
- std::unique_ptr<protocol::Runtime::RemoteObject> remoteObject =
+ std::unique_ptr<protocol::Value> protocolValue;
+ response = toProtocolValue(context, wrappedObject, &protocolValue);
+ if (!response.isSuccess()) return response;
+
+ *result =
protocol::Runtime::RemoteObject::parse(protocolValue.get(), &errors);
- if (!remoteObject) *errorString = errors.errors();
- return remoteObject;
+ if (!result->get()) return Response::Error(errors.errors());
+ return Response::OK();
}
-bool InjectedScript::wrapObjectProperty(ErrorString* errorString,
- v8::Local<v8::Object> object,
- v8::Local<v8::Name> key,
- const String16& groupName,
- bool forceValueType,
- bool generatePreview) const {
+Response InjectedScript::wrapObjectProperty(v8::Local<v8::Object> object,
+ v8::Local<v8::Name> key,
+ const String16& groupName,
+ bool forceValueType,
+ bool generatePreview) const {
v8::Local<v8::Value> property;
v8::Local<v8::Context> context = m_context->context();
- if (hasInternalError(errorString,
- !object->Get(context, key).ToLocal(&property)))
- return false;
+ if (!object->Get(context, key).ToLocal(&property))
+ return Response::InternalError();
v8::Local<v8::Value> wrappedProperty;
- if (!wrapValue(errorString, property, groupName, forceValueType,
- generatePreview)
- .ToLocal(&wrappedProperty))
- return false;
+ Response response = wrapValue(property, groupName, forceValueType,
+ generatePreview, &wrappedProperty);
+ if (!response.isSuccess()) return response;
v8::Maybe<bool> success =
createDataProperty(context, object, key, wrappedProperty);
- if (hasInternalError(errorString, success.IsNothing() || !success.FromJust()))
- return false;
- return true;
+ if (success.IsNothing() || !success.FromJust())
+ return Response::InternalError();
+ return Response::OK();
}
-bool InjectedScript::wrapPropertyInArray(ErrorString* errorString,
- v8::Local<v8::Array> array,
- v8::Local<v8::String> property,
- const String16& groupName,
- bool forceValueType,
- bool generatePreview) const {
+Response InjectedScript::wrapPropertyInArray(v8::Local<v8::Array> array,
+ v8::Local<v8::String> property,
+ const String16& groupName,
+ bool forceValueType,
+ bool generatePreview) const {
V8FunctionCall function(m_context->inspector(), m_context->context(),
v8Value(), "wrapPropertyInArray");
function.appendArgument(array);
@@ -230,29 +223,13 @@ bool InjectedScript::wrapPropertyInArray(ErrorString* errorString,
function.appendArgument(generatePreview);
bool hadException = false;
function.call(hadException);
- return !hasInternalError(errorString, hadException);
+ return hadException ? Response::InternalError() : Response::OK();
}
-bool InjectedScript::wrapObjectsInArray(ErrorString* errorString,
- v8::Local<v8::Array> array,
- const String16& groupName,
- bool forceValueType,
- bool generatePreview) const {
- V8FunctionCall function(m_context->inspector(), m_context->context(),
- v8Value(), "wrapObjectsInArray");
- function.appendArgument(array);
- function.appendArgument(groupName);
- function.appendArgument(forceValueType);
- function.appendArgument(generatePreview);
- bool hadException = false;
- function.call(hadException);
- return !hasInternalError(errorString, hadException);
-}
-
-v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(
- ErrorString* errorString, v8::Local<v8::Value> value,
- const String16& groupName, bool forceValueType,
- bool generatePreview) const {
+Response InjectedScript::wrapValue(v8::Local<v8::Value> value,
+ const String16& groupName,
+ bool forceValueType, bool generatePreview,
+ v8::Local<v8::Value>* result) const {
V8FunctionCall function(m_context->inspector(), m_context->context(),
v8Value(), "wrapObject");
function.appendArgument(value);
@@ -260,10 +237,9 @@ v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(
function.appendArgument(forceValueType);
function.appendArgument(generatePreview);
bool hadException = false;
- v8::Local<v8::Value> r = function.call(hadException);
- if (hasInternalError(errorString, hadException || r.IsEmpty()))
- return v8::MaybeLocal<v8::Value>();
- return r;
+ *result = function.call(hadException);
+ if (hadException || result->IsEmpty()) return Response::InternalError();
+ return Response::OK();
}
std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(
@@ -280,21 +256,19 @@ std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(
bool hadException = false;
v8::Local<v8::Value> r = function.call(hadException);
if (hadException || r.IsEmpty()) return nullptr;
- protocol::ErrorString errorString;
- std::unique_ptr<protocol::Value> protocolValue =
- toProtocolValue(&errorString, context, r);
- if (!protocolValue) return nullptr;
+ std::unique_ptr<protocol::Value> protocolValue;
+ Response response = toProtocolValue(context, r, &protocolValue);
+ if (!response.isSuccess()) return nullptr;
protocol::ErrorSupport errors;
return protocol::Runtime::RemoteObject::parse(protocolValue.get(), &errors);
}
-bool InjectedScript::findObject(ErrorString* errorString,
- const RemoteObjectId& objectId,
- v8::Local<v8::Value>* outObject) const {
+Response InjectedScript::findObject(const RemoteObjectId& objectId,
+ v8::Local<v8::Value>* outObject) const {
*outObject = m_native->objectForId(objectId.id());
if (outObject->IsEmpty())
- *errorString = "Could not find object with given id";
- return !outObject->IsEmpty();
+ return Response::Error("Could not find object with given id");
+ return Response::OK();
}
String16 InjectedScript::objectGroupName(const RemoteObjectId& objectId) const {
@@ -326,47 +300,41 @@ v8::Local<v8::Value> InjectedScript::lastEvaluationResult() const {
return m_lastEvaluationResult.Get(m_context->isolate());
}
-v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(
- ErrorString* errorString, protocol::Runtime::CallArgument* callArgument) {
+Response InjectedScript::resolveCallArgument(
+ protocol::Runtime::CallArgument* callArgument,
+ v8::Local<v8::Value>* result) {
if (callArgument->hasObjectId()) {
- std::unique_ptr<RemoteObjectId> remoteObjectId =
- RemoteObjectId::parse(errorString, callArgument->getObjectId(""));
- if (!remoteObjectId) return v8::MaybeLocal<v8::Value>();
- if (remoteObjectId->contextId() != m_context->contextId()) {
- *errorString =
+ std::unique_ptr<RemoteObjectId> remoteObjectId;
+ Response response =
+ RemoteObjectId::parse(callArgument->getObjectId(""), &remoteObjectId);
+ if (!response.isSuccess()) return response;
+ if (remoteObjectId->contextId() != m_context->contextId())
+ return Response::Error(
"Argument should belong to the same JavaScript world as target "
- "object";
- return v8::MaybeLocal<v8::Value>();
- }
- v8::Local<v8::Value> object;
- if (!findObject(errorString, *remoteObjectId, &object))
- return v8::MaybeLocal<v8::Value>();
- return object;
+ "object");
+ return findObject(*remoteObjectId, result);
}
if (callArgument->hasValue() || callArgument->hasUnserializableValue()) {
String16 value =
callArgument->hasValue()
? callArgument->getValue(nullptr)->toJSONString()
: "Number(\"" + callArgument->getUnserializableValue("") + "\")";
- v8::Local<v8::Value> object;
if (!m_context->inspector()
->compileAndRunInternalScript(
m_context->context(), toV8String(m_context->isolate(), value))
- .ToLocal(&object)) {
- *errorString = "Couldn't parse value object in call argument";
- return v8::MaybeLocal<v8::Value>();
+ .ToLocal(result)) {
+ return Response::Error("Couldn't parse value object in call argument");
}
- return object;
+ return Response::OK();
}
- return v8::Undefined(m_context->isolate());
+ *result = v8::Undefined(m_context->isolate());
+ return Response::OK();
}
-std::unique_ptr<protocol::Runtime::ExceptionDetails>
-InjectedScript::createExceptionDetails(ErrorString* errorString,
- const v8::TryCatch& tryCatch,
- const String16& objectGroup,
- bool generatePreview) {
- if (!tryCatch.HasCaught()) return nullptr;
+Response InjectedScript::createExceptionDetails(
+ const v8::TryCatch& tryCatch, const String16& objectGroup,
+ bool generatePreview, Maybe<protocol::Runtime::ExceptionDetails>* result) {
+ if (!tryCatch.HasCaught()) return Response::InternalError();
v8::Local<v8::Message> message = tryCatch.Message();
v8::Local<v8::Value> exception = tryCatch.Exception();
String16 messageText =
@@ -396,43 +364,44 @@ InjectedScript::createExceptionDetails(ErrorString* errorString,
->buildInspectorObjectImpl());
}
if (!exception.IsEmpty()) {
- std::unique_ptr<protocol::Runtime::RemoteObject> wrapped = wrapObject(
- errorString, exception, objectGroup, false /* forceValueType */,
- generatePreview && !exception->IsNativeError());
- if (!wrapped) return nullptr;
+ std::unique_ptr<protocol::Runtime::RemoteObject> wrapped;
+ Response response =
+ wrapObject(exception, objectGroup, false /* forceValueType */,
+ generatePreview && !exception->IsNativeError(), &wrapped);
+ if (!response.isSuccess()) return response;
exceptionDetails->setException(std::move(wrapped));
}
- return exceptionDetails;
+ *result = std::move(exceptionDetails);
+ return Response::OK();
}
-void InjectedScript::wrapEvaluateResult(
- ErrorString* errorString, v8::MaybeLocal<v8::Value> maybeResultValue,
- const v8::TryCatch& tryCatch, const String16& objectGroup,
- bool returnByValue, bool generatePreview,
+Response InjectedScript::wrapEvaluateResult(
+ v8::MaybeLocal<v8::Value> maybeResultValue, const v8::TryCatch& tryCatch,
+ const String16& objectGroup, bool returnByValue, bool generatePreview,
std::unique_ptr<protocol::Runtime::RemoteObject>* result,
Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) {
v8::Local<v8::Value> resultValue;
if (!tryCatch.HasCaught()) {
- if (hasInternalError(errorString, !maybeResultValue.ToLocal(&resultValue)))
- return;
- std::unique_ptr<RemoteObject> remoteObject = wrapObject(
- errorString, resultValue, objectGroup, returnByValue, generatePreview);
- if (!remoteObject) return;
+ if (!maybeResultValue.ToLocal(&resultValue))
+ return Response::InternalError();
+ Response response = wrapObject(resultValue, objectGroup, returnByValue,
+ generatePreview, result);
+ if (!response.isSuccess()) return response;
if (objectGroup == "console")
m_lastEvaluationResult.Reset(m_context->isolate(), resultValue);
- *result = std::move(remoteObject);
} else {
v8::Local<v8::Value> exception = tryCatch.Exception();
- std::unique_ptr<RemoteObject> remoteObject =
- wrapObject(errorString, exception, objectGroup, false,
- generatePreview && !exception->IsNativeError());
- if (!remoteObject) return;
+ Response response =
+ wrapObject(exception, objectGroup, false,
+ generatePreview && !exception->IsNativeError(), result);
+ if (!response.isSuccess()) return response;
// We send exception in result for compatibility reasons, even though it's
// accessible through exceptionDetails.exception.
- *result = std::move(remoteObject);
- *exceptionDetails = createExceptionDetails(errorString, tryCatch,
- objectGroup, generatePreview);
+ response = createExceptionDetails(tryCatch, objectGroup, generatePreview,
+ exceptionDetails);
+ if (!response.isSuccess()) return response;
}
+ return Response::OK();
}
v8::Local<v8::Object> InjectedScript::commandLineAPI() {
@@ -442,10 +411,8 @@ v8::Local<v8::Object> InjectedScript::commandLineAPI() {
return m_commandLineAPI.Get(m_context->isolate());
}
-InjectedScript::Scope::Scope(ErrorString* errorString,
- V8InspectorImpl* inspector, int contextGroupId)
- : m_errorString(errorString),
- m_inspector(inspector),
+InjectedScript::Scope::Scope(V8InspectorImpl* inspector, int contextGroupId)
+ : m_inspector(inspector),
m_contextGroupId(contextGroupId),
m_injectedScript(nullptr),
m_handleScope(inspector->isolate()),
@@ -454,29 +421,25 @@ InjectedScript::Scope::Scope(ErrorString* errorString,
m_previousPauseOnExceptionsState(v8::DebugInterface::NoBreakOnException),
m_userGesture(false) {}
-bool InjectedScript::Scope::initialize() {
+Response InjectedScript::Scope::initialize() {
cleanup();
// TODO(dgozman): what if we reattach to the same context group during
// evaluate? Introduce a session id?
V8InspectorSessionImpl* session =
m_inspector->sessionForContextGroup(m_contextGroupId);
- if (!session) {
- *m_errorString = "Internal error";
- return false;
- }
- findInjectedScript(session);
- if (!m_injectedScript) return false;
+ if (!session) return Response::InternalError();
+ Response response = findInjectedScript(session);
+ if (!response.isSuccess()) return response;
m_context = m_injectedScript->context()->context();
m_context->Enter();
- return true;
+ return Response::OK();
}
-bool InjectedScript::Scope::installCommandLineAPI() {
+void InjectedScript::Scope::installCommandLineAPI() {
DCHECK(m_injectedScript && !m_context.IsEmpty() &&
!m_commandLineAPIScope.get());
m_commandLineAPIScope.reset(new V8Console::CommandLineAPIScope(
m_context, m_injectedScript->commandLineAPI(), m_context->Global()));
- return true;
}
void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() {
@@ -523,59 +486,57 @@ InjectedScript::Scope::~Scope() {
cleanup();
}
-InjectedScript::ContextScope::ContextScope(ErrorString* errorString,
- V8InspectorImpl* inspector,
+InjectedScript::ContextScope::ContextScope(V8InspectorImpl* inspector,
int contextGroupId,
int executionContextId)
- : InjectedScript::Scope(errorString, inspector, contextGroupId),
+ : InjectedScript::Scope(inspector, contextGroupId),
m_executionContextId(executionContextId) {}
InjectedScript::ContextScope::~ContextScope() {}
-void InjectedScript::ContextScope::findInjectedScript(
+Response InjectedScript::ContextScope::findInjectedScript(
V8InspectorSessionImpl* session) {
- m_injectedScript =
- session->findInjectedScript(m_errorString, m_executionContextId);
+ return session->findInjectedScript(m_executionContextId, m_injectedScript);
}
-InjectedScript::ObjectScope::ObjectScope(ErrorString* errorString,
- V8InspectorImpl* inspector,
+InjectedScript::ObjectScope::ObjectScope(V8InspectorImpl* inspector,
int contextGroupId,
const String16& remoteObjectId)
- : InjectedScript::Scope(errorString, inspector, contextGroupId),
+ : InjectedScript::Scope(inspector, contextGroupId),
m_remoteObjectId(remoteObjectId) {}
InjectedScript::ObjectScope::~ObjectScope() {}
-void InjectedScript::ObjectScope::findInjectedScript(
+Response InjectedScript::ObjectScope::findInjectedScript(
V8InspectorSessionImpl* session) {
- std::unique_ptr<RemoteObjectId> remoteId =
- RemoteObjectId::parse(m_errorString, m_remoteObjectId);
- if (!remoteId) return;
- InjectedScript* injectedScript =
- session->findInjectedScript(m_errorString, remoteId.get());
- if (!injectedScript) return;
+ std::unique_ptr<RemoteObjectId> remoteId;
+ Response response = RemoteObjectId::parse(m_remoteObjectId, &remoteId);
+ if (!response.isSuccess()) return response;
+ InjectedScript* injectedScript = nullptr;
+ response = session->findInjectedScript(remoteId.get(), injectedScript);
+ if (!response.isSuccess()) return response;
m_objectGroupName = injectedScript->objectGroupName(*remoteId);
- if (!injectedScript->findObject(m_errorString, *remoteId, &m_object)) return;
+ response = injectedScript->findObject(*remoteId, &m_object);
+ if (!response.isSuccess()) return response;
m_injectedScript = injectedScript;
+ return Response::OK();
}
-InjectedScript::CallFrameScope::CallFrameScope(ErrorString* errorString,
- V8InspectorImpl* inspector,
+InjectedScript::CallFrameScope::CallFrameScope(V8InspectorImpl* inspector,
int contextGroupId,
const String16& remoteObjectId)
- : InjectedScript::Scope(errorString, inspector, contextGroupId),
+ : InjectedScript::Scope(inspector, contextGroupId),
m_remoteCallFrameId(remoteObjectId) {}
InjectedScript::CallFrameScope::~CallFrameScope() {}
-void InjectedScript::CallFrameScope::findInjectedScript(
+Response InjectedScript::CallFrameScope::findInjectedScript(
V8InspectorSessionImpl* session) {
- std::unique_ptr<RemoteCallFrameId> remoteId =
- RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId);
- if (!remoteId) return;
+ std::unique_ptr<RemoteCallFrameId> remoteId;
+ Response response = RemoteCallFrameId::parse(m_remoteCallFrameId, &remoteId);
+ if (!response.isSuccess()) return response;
m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal());
- m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get());
+ return session->findInjectedScript(remoteId.get(), m_injectedScript);
}
} // namespace v8_inspector
« no previous file with comments | « src/inspector/injected-script.h ('k') | src/inspector/injected-script-source.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698