| Index: third_party/WebKit/Source/platform/inspector_protocol/TypeBuilder_cpp.template
|
| diff --git a/third_party/WebKit/Source/platform/inspector_protocol/TypeBuilder_cpp.template b/third_party/WebKit/Source/platform/inspector_protocol/TypeBuilder_cpp.template
|
| index 674e7a8737b846b84d88bc147d9560cc5b23595a..5e83a6cd1cb494172fc64adea2cd1ffbd5e573a6 100644
|
| --- a/third_party/WebKit/Source/platform/inspector_protocol/TypeBuilder_cpp.template
|
| +++ b/third_party/WebKit/Source/platform/inspector_protocol/TypeBuilder_cpp.template
|
| @@ -9,6 +9,82 @@
|
| namespace blink {
|
| namespace protocol {
|
|
|
| +ErrorSupport::ErrorSupport() : m_errorString(nullptr) { }
|
| +ErrorSupport::ErrorSupport(String* errorString) : m_errorString(errorString) { }
|
| +ErrorSupport::~ErrorSupport()
|
| +{
|
| + if (m_errorString && hasErrors())
|
| + *m_errorString = "Internal error(s): " + errors();
|
| +}
|
| +
|
| +void ErrorSupport::setName(const String& name)
|
| +{
|
| + ASSERT(m_path.size());
|
| + m_path[m_path.size() - 1] = name;
|
| +}
|
| +
|
| +void ErrorSupport::push()
|
| +{
|
| + m_path.append(String());
|
| +}
|
| +
|
| +void ErrorSupport::pop()
|
| +{
|
| + m_path.removeLast();
|
| +}
|
| +
|
| +void ErrorSupport::addError(const String& error)
|
| +{
|
| + StringBuilder builder;
|
| + for (size_t i = 0; i < m_path.size(); ++i) {
|
| + if (i)
|
| + builder.append(".");
|
| + builder.append(m_path[i]);
|
| + }
|
| + builder.append(": ");
|
| + builder.append(error);
|
| + m_errors.append(builder.toString());
|
| +}
|
| +
|
| +bool ErrorSupport::hasErrors()
|
| +{
|
| + return m_errors.size();
|
| +}
|
| +
|
| +String ErrorSupport::errors()
|
| +{
|
| + StringBuilder builder;
|
| + for (size_t i = 0; i < m_errors.size(); ++i) {
|
| + if (i)
|
| + builder.append("; ");
|
| + builder.append(m_errors[i]);
|
| + }
|
| + return builder.toString();
|
| +}
|
| +
|
| +PassOwnPtr<Object> Object::parse(PassRefPtr<JSONValue> value, ErrorSupport* errors)
|
| +{
|
| + RefPtr<JSONObject> object = JSONObject::cast(value);
|
| + if (!object) {
|
| + errors->addError("object expected");
|
| + return nullptr;
|
| + }
|
| + return adoptPtr(new Object(object.release()));
|
| +}
|
| +
|
| +PassRefPtr<JSONObject> Object::serialize() const
|
| +{
|
| + return m_object;
|
| +}
|
| +
|
| +PassOwnPtr<Object> Object::clone() const
|
| +{
|
| + return adoptPtr(new Object(m_object));
|
| +}
|
| +
|
| +Object::Object(PassRefPtr<JSONObject> object) : m_object(object) { }
|
| +Object::~Object() { }
|
| +
|
| PassRefPtr<JSONValue> toValue(int value) { return JSONBasicValue::create(value); }
|
| PassRefPtr<JSONValue> toValue(double value) { return JSONBasicValue::create(value); }
|
| PassRefPtr<JSONValue> toValue(bool value) { return JSONBasicValue::create(value); }
|
| @@ -16,27 +92,76 @@ PassRefPtr<JSONValue> toValue(const String& param) { return JSONString::create(p
|
|
|
| // ------------- Enum values from types.
|
| {% for domain in api.domains %}
|
| +
|
| +namespace {{domain.domain}} {
|
| {% for type in domain.types %}
|
| {% if "enum" in type %}
|
|
|
| -namespace {{domain.domain}} {
|
| namespace {{type.id}}Enum {
|
| {% for literal in type.enum %}
|
| const char* {{ literal | dash_to_camelcase}} = "{{literal}}";
|
| {% endfor %}
|
| } // {{type.id}}Enum
|
| -} // {{domain.domain}}
|
| {% endif %}
|
| {% for property in type.properties %}
|
| {% if "enum" in property %}
|
| -namespace {{domain.domain}} {
|
| +
|
| {% for literal in property.enum %}
|
| const char* {{type.id}}::{{property.name | to_title_case}}Enum::{{ literal | dash_to_camelcase}} = "{{literal}}";
|
| {% endfor %}
|
| -} // {{domain.domain}}
|
| {% endif %}
|
| {% endfor %}
|
| + {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
|
| +
|
| +PassOwnPtr<{{type.id}}> {{type.id}}::parse(PassRefPtr<JSONValue> value, ErrorSupport* errors)
|
| +{
|
| + if (!value || value->type() != JSONValue::TypeObject) {
|
| + errors->addError("object expected");
|
| + return nullptr;
|
| + }
|
| +
|
| + OwnPtr<{{type.id}}> result = adoptPtr(new {{type.id}}());
|
| + RefPtr<JSONObject> object = JSONObject::cast(value);
|
| + errors->push();
|
| + {% for property in type.properties %}
|
| + RefPtr<JSONValue> {{property.name}}Value = object->get("{{property.name}}");
|
| + {% if property.optional %}
|
| + if ({{property.name}}Value) {
|
| + errors->setName("{{property.name}}");
|
| + result->m_{{property.name}} = FromValue<{{resolve_type(property).raw_type}}>::parse({{property.name}}Value, errors);
|
| + }
|
| + {% else %}
|
| + errors->setName("{{property.name}}");
|
| + result->m_{{property.name}} = FromValue<{{resolve_type(property).raw_type}}>::parse({{property.name}}Value, errors);
|
| + {% endif %}
|
| + {% endfor %}
|
| + errors->pop();
|
| + if (errors->hasErrors())
|
| + return nullptr;
|
| + return result.release();
|
| +}
|
| +
|
| +PassRefPtr<JSONObject> {{type.id}}::serialize() const
|
| +{
|
| + RefPtr<JSONObject> result = JSONObject::create();
|
| + {% for property in type.properties %}
|
| + {% if property.optional %}
|
| + if (m_{{property.name}}.isJust())
|
| + result->setValue("{{property.name}}", toValue(m_{{property.name}}.fromJust()));
|
| + {% else %}
|
| + result->setValue("{{property.name}}", toValue(m_{{property.name}}));
|
| + {% endif %}
|
| + {% endfor %}
|
| + return result.release();
|
| +}
|
| +
|
| +PassOwnPtr<{{type.id}}> {{type.id}}::clone() const
|
| +{
|
| + ErrorSupport errors;
|
| + return parse(serialize().get(), &errors);
|
| +}
|
| {% endfor %}
|
| +} // {{domain.domain}}
|
| {% endfor %}
|
|
|
| // ------------- Enum values from params.
|
|
|