Commit 0965b9b5 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

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