Commit c0d1afa2 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] provide more usefull error message for non serializable value

Runtime.evaluate can return result by value. We need to provide more details why method call was failed.

BUG=chromium:645640
R=dgozman@chromium.org,alph@chromium.org

Committed: https://crrev.com/0965b9b5df532d3aa0583966ca60794b54f56943
Review-Url: https://codereview.chromium.org/2345263003
Cr-Original-Commit-Position: refs/heads/master@{#39574}
Cr-Commit-Position: refs/heads/master@{#39606}
parent ff8101d8
......@@ -143,10 +143,10 @@ void InjectedScript::getProperties(
*properties = Array<PropertyDescriptor>::create();
return;
}
if (hasInternalError(errorString, resultValue.IsEmpty())) return;
std::unique_ptr<protocol::Value> protocolValue =
toProtocolValue(context, resultValue);
if (hasInternalError(errorString, !protocolValue)) return;
toProtocolValue(errorString, context, resultValue);
if (!protocolValue) return;
protocol::ErrorSupport errors(errorString);
std::unique_ptr<Array<PropertyDescriptor>> result =
Array<PropertyDescriptor>::parse(protocolValue.get(), &errors);
......@@ -177,10 +177,12 @@ std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(
.ToLocal(&wrappedObject))
return nullptr;
protocol::ErrorSupport errors;
std::unique_ptr<protocol::Value> protocolValue =
toProtocolValue(errorString, context, wrappedObject);
if (!protocolValue) return nullptr;
std::unique_ptr<protocol::Runtime::RemoteObject> remoteObject =
protocol::Runtime::RemoteObject::parse(
toProtocolValue(context, wrappedObject).get(), &errors);
if (!remoteObject) *errorString = "Object has too long reference chain";
protocol::Runtime::RemoteObject::parse(protocolValue.get(), &errors);
if (!remoteObject) *errorString = errors.errors();
return remoteObject;
}
......@@ -271,10 +273,13 @@ std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(
function.appendArgument(columns);
bool hadException = false;
v8::Local<v8::Value> r = function.call(hadException);
if (hadException) return nullptr;
if (hadException || r.IsEmpty()) return nullptr;
protocol::ErrorString errorString;
std::unique_ptr<protocol::Value> protocolValue =
toProtocolValue(&errorString, context, r);
if (!protocolValue) return nullptr;
protocol::ErrorSupport errors;
return protocol::Runtime::RemoteObject::parse(
toProtocolValue(context, r).get(), &errors);
return protocol::Runtime::RemoteObject::parse(protocolValue.get(), &errors);
}
bool InjectedScript::findObject(ErrorString* errorString,
......
......@@ -103,7 +103,8 @@ std::unique_ptr<protocol::Value> parseJSON(const String16& string) {
} // namespace protocol
std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context,
std::unique_ptr<protocol::Value> toProtocolValue(protocol::String* errorString,
v8::Local<v8::Context> context,
v8::Local<v8::Value> value,
int maxDepth) {
if (value.IsEmpty()) {
......@@ -111,7 +112,10 @@ std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context,
return nullptr;
}
if (!maxDepth) return nullptr;
if (!maxDepth) {
*errorString = "Object reference chain is too long";
return nullptr;
}
maxDepth--;
if (value->IsNull() || value->IsUndefined()) return protocol::Value::null();
......@@ -134,9 +138,12 @@ std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context,
uint32_t length = array->Length();
for (uint32_t i = 0; i < length; i++) {
v8::Local<v8::Value> value;
if (!array->Get(context, i).ToLocal(&value)) return nullptr;
if (!array->Get(context, i).ToLocal(&value)) {
*errorString = "Internal error";
return nullptr;
}
std::unique_ptr<protocol::Value> element =
toProtocolValue(context, value, maxDepth);
toProtocolValue(errorString, context, value, maxDepth);
if (!element) return nullptr;
inspectorArray->pushValue(std::move(element));
}
......@@ -147,12 +154,17 @@ std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context,
protocol::DictionaryValue::create();
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
v8::Local<v8::Array> propertyNames;
if (!object->GetPropertyNames(context).ToLocal(&propertyNames))
if (!object->GetPropertyNames(context).ToLocal(&propertyNames)) {
*errorString = "Internal error";
return nullptr;
}
uint32_t length = propertyNames->Length();
for (uint32_t i = 0; i < length; i++) {
v8::Local<v8::Value> name;
if (!propertyNames->Get(context, i).ToLocal(&name)) return nullptr;
if (!propertyNames->Get(context, i).ToLocal(&name)) {
*errorString = "Internal error";
return nullptr;
}
// FIXME(yurys): v8::Object should support GetOwnPropertyNames
if (name->IsString()) {
v8::Maybe<bool> hasRealNamedProperty = object->HasRealNamedProperty(
......@@ -163,16 +175,19 @@ std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context> context,
v8::Local<v8::String> propertyName;
if (!name->ToString(context).ToLocal(&propertyName)) continue;
v8::Local<v8::Value> property;
if (!object->Get(context, name).ToLocal(&property)) return nullptr;
if (!object->Get(context, name).ToLocal(&property)) {
*errorString = "Internal error";
return nullptr;
}
std::unique_ptr<protocol::Value> propertyValue =
toProtocolValue(context, property, maxDepth);
toProtocolValue(errorString, context, property, maxDepth);
if (!propertyValue) return nullptr;
jsonObject->setValue(toProtocolString(propertyName),
std::move(propertyValue));
}
return std::move(jsonObject);
}
UNREACHABLE();
*errorString = "Object couldn't be returned by value";
return nullptr;
}
......
......@@ -37,7 +37,8 @@ std::unique_ptr<protocol::Value> parseJSON(const String16& json);
} // namespace protocol
std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context>,
std::unique_ptr<protocol::Value> toProtocolValue(protocol::String* errorString,
v8::Local<v8::Context>,
v8::Local<v8::Value>,
int maxDepth = 1000);
......
......@@ -1012,9 +1012,12 @@ std::unique_ptr<Array<CallFrame>> V8DebuggerAgentImpl::currentCallFrames(
return Array<CallFrame>::create();
}
std::unique_ptr<protocol::Value> protocolValue =
toProtocolValue(errorString, debuggerContext, objects);
if (!protocolValue) return Array<CallFrame>::create();
protocol::ErrorSupport errorSupport;
std::unique_ptr<Array<CallFrame>> callFrames = Array<CallFrame>::parse(
toProtocolValue(debuggerContext, objects).get(), &errorSupport);
std::unique_ptr<Array<CallFrame>> callFrames =
Array<CallFrame>::parse(protocolValue.get(), &errorSupport);
if (hasInternalError(errorString, !callFrames))
return Array<CallFrame>::create();
return callFrames;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment