Commit e0b333b6 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol (Chromium)

Upstream Review:
"Remove writeJSON / toJSONString from generated protocol types."
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/2013082

In addition, remove no longer used method builderAppendQuotedString
from v8_inspector_string.{h,cc}.

New Rev: 6361d066985aafcb5c7d7b4066da0a0ecaa5866d

Change-Id: I975ffa795b01cd44e16f9d8e42127a3c23528213
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2013314Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733925}
parent 95ba9759
...@@ -59,24 +59,6 @@ std::unique_ptr<protocol::Value> StringUtil::parseJSON(const String& string) { ...@@ -59,24 +59,6 @@ std::unique_ptr<protocol::Value> StringUtil::parseJSON(const String& string) {
string.length()); string.length());
} }
// static
void StringUtil::builderAppendQuotedString(StringBuilder& builder,
const String& str) {
builder.Append('"');
if (!str.IsEmpty()) {
if (str.Is8Bit()) {
escapeLatinStringForJSON(
reinterpret_cast<const uint8_t*>(str.Characters8()), str.length(),
&builder);
} else {
escapeWideStringForJSON(
reinterpret_cast<const uint16_t*>(str.Characters16()), str.length(),
&builder);
}
}
builder.Append('"');
}
// static // static
String StringUtil::fromUTF16LE(const uint16_t* data, size_t length) { String StringUtil::fromUTF16LE(const uint16_t* data, size_t length) {
// Chromium doesn't support big endian architectures, so it's OK to cast here. // Chromium doesn't support big endian architectures, so it's OK to cast here.
......
...@@ -73,7 +73,6 @@ class CORE_EXPORT StringUtil { ...@@ -73,7 +73,6 @@ class CORE_EXPORT StringUtil {
static void builderAppend(StringBuilder& builder, const char* s, size_t len) { static void builderAppend(StringBuilder& builder, const char* s, size_t len) {
builder.Append(s, static_cast<wtf_size_t>(len)); builder.Append(s, static_cast<wtf_size_t>(len));
} }
static void builderAppendQuotedString(StringBuilder&, const String&);
static void builderReserve(StringBuilder& builder, uint64_t capacity) { static void builderReserve(StringBuilder& builder, uint64_t capacity) {
builder.ReserveCapacity(static_cast<wtf_size_t>(capacity)); builder.ReserveCapacity(static_cast<wtf_size_t>(capacity));
} }
......
...@@ -2,7 +2,7 @@ Name: inspector protocol ...@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/ URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0 Version: 0
Revision: ac6919eb836521a96cc18931f0bf270d8c1b53a1 Revision: 6361d066985aafcb5c7d7b4066da0a0ecaa5866d
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: yes Security Critical: yes
......
...@@ -13,55 +13,6 @@ namespace {{namespace}} { ...@@ -13,55 +13,6 @@ namespace {{namespace}} {
{% endfor %} {% endfor %}
namespace { namespace {
const char* const nullValueString = "null";
const char* const trueValueString = "true";
const char* const falseValueString = "false";
inline bool escapeChar(uint16_t c, StringBuilder* dst)
{
switch (c) {
case '\b': StringUtil::builderAppend(*dst, "\\b"); break;
case '\f': StringUtil::builderAppend(*dst, "\\f"); break;
case '\n': StringUtil::builderAppend(*dst, "\\n"); break;
case '\r': StringUtil::builderAppend(*dst, "\\r"); break;
case '\t': StringUtil::builderAppend(*dst, "\\t"); break;
case '\\': StringUtil::builderAppend(*dst, "\\\\"); break;
case '"': StringUtil::builderAppend(*dst, "\\\""); break;
default:
return false;
}
return true;
}
const char hexDigits[17] = "0123456789ABCDEF";
void appendUnsignedAsHex(uint16_t number, StringBuilder* dst)
{
StringUtil::builderAppend(*dst, "\\u");
for (size_t i = 0; i < 4; ++i) {
uint16_t c = hexDigits[(number & 0xF000) >> 12];
StringUtil::builderAppend(*dst, c);
number <<= 4;
}
}
template <typename Char>
void escapeStringForJSONInternal(const Char* str, unsigned len,
StringBuilder* dst)
{
for (unsigned i = 0; i < len; ++i) {
Char c = str[i];
if (escapeChar(c, dst))
continue;
if (c < 32 || c > 126) {
appendUnsignedAsHex(c, dst);
} else {
StringUtil::builderAppend(*dst, c);
}
}
}
// When parsing CBOR, we limit recursion depth for objects and arrays // When parsing CBOR, we limit recursion depth for objects and arrays
// to this constant. // to this constant.
static constexpr int kStackLimitValues = 1000; static constexpr int kStackLimitValues = 1000;
...@@ -275,12 +226,6 @@ bool Value::asBinary(Binary*) const ...@@ -275,12 +226,6 @@ bool Value::asBinary(Binary*) const
return false; return false;
} }
void Value::writeJSON(StringBuilder* output) const
{
DCHECK(m_type == TypeNull);
StringUtil::builderAppend(*output, nullValueString, 4);
}
void Value::AppendSerialized(std::vector<uint8_t>* bytes) const { void Value::AppendSerialized(std::vector<uint8_t>* bytes) const {
DCHECK(m_type == TypeNull); DCHECK(m_type == TypeNull);
bytes->push_back(cbor::EncodeNull()); bytes->push_back(cbor::EncodeNull());
...@@ -291,14 +236,6 @@ std::unique_ptr<Value> Value::clone() const ...@@ -291,14 +236,6 @@ std::unique_ptr<Value> Value::clone() const
return Value::null(); return Value::null();
} }
String Value::toJSONString() const
{
StringBuilder result;
StringUtil::builderReserve(result, 512);
writeJSON(&result);
return StringUtil::builderToString(result);
}
bool FundamentalValue::asBoolean(bool* output) const bool FundamentalValue::asBoolean(bool* output) const
{ {
if (type() != TypeBoolean) if (type() != TypeBoolean)
...@@ -328,25 +265,6 @@ bool FundamentalValue::asInteger(int* output) const ...@@ -328,25 +265,6 @@ bool FundamentalValue::asInteger(int* output) const
return true; return true;
} }
void FundamentalValue::writeJSON(StringBuilder* output) const
{
DCHECK(type() == TypeBoolean || type() == TypeInteger || type() == TypeDouble);
if (type() == TypeBoolean) {
if (m_boolValue)
StringUtil::builderAppend(*output, trueValueString, 4);
else
StringUtil::builderAppend(*output, falseValueString, 5);
} else if (type() == TypeDouble) {
if (!std::isfinite(m_doubleValue)) {
StringUtil::builderAppend(*output, nullValueString, 4);
return;
}
StringUtil::builderAppend(*output, StringUtil::fromDouble(m_doubleValue));
} else if (type() == TypeInteger) {
StringUtil::builderAppend(*output, StringUtil::fromInteger(m_integerValue));
}
}
void FundamentalValue::AppendSerialized(std::vector<uint8_t>* bytes) const { void FundamentalValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
switch (type()) { switch (type()) {
case TypeDouble: case TypeDouble:
...@@ -381,12 +299,6 @@ bool StringValue::asString(String* output) const ...@@ -381,12 +299,6 @@ bool StringValue::asString(String* output) const
return true; return true;
} }
void StringValue::writeJSON(StringBuilder* output) const
{
DCHECK(type() == TypeString);
StringUtil::builderAppendQuotedString(*output, m_stringValue);
}
namespace { namespace {
// This routine distinguishes between the current encoding for a given // This routine distinguishes between the current encoding for a given
// string |s|, and calls encoding routines that will // string |s|, and calls encoding routines that will
...@@ -431,12 +343,6 @@ bool BinaryValue::asBinary(Binary* output) const ...@@ -431,12 +343,6 @@ bool BinaryValue::asBinary(Binary* output) const
return true; return true;
} }
void BinaryValue::writeJSON(StringBuilder* output) const
{
DCHECK(type() == TypeBinary);
StringUtil::builderAppendQuotedString(*output, m_binaryValue.toBase64());
}
void BinaryValue::AppendSerialized(std::vector<uint8_t>* bytes) const { void BinaryValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
cbor::EncodeBinary(span<uint8_t>(m_binaryValue.data(), cbor::EncodeBinary(span<uint8_t>(m_binaryValue.data(),
m_binaryValue.size()), bytes); m_binaryValue.size()), bytes);
...@@ -570,21 +476,6 @@ void DictionaryValue::remove(const String& name) ...@@ -570,21 +476,6 @@ void DictionaryValue::remove(const String& name)
m_order.erase(std::remove(m_order.begin(), m_order.end(), name), m_order.end()); m_order.erase(std::remove(m_order.begin(), m_order.end(), name), m_order.end());
} }
void DictionaryValue::writeJSON(StringBuilder* output) const
{
StringUtil::builderAppend(*output, '{');
for (size_t i = 0; i < m_order.size(); ++i) {
Dictionary::const_iterator it = m_data.find(m_order[i]);
CHECK(it != m_data.end());
if (i)
StringUtil::builderAppend(*output, ',');
StringUtil::builderAppendQuotedString(*output, it->first);
StringUtil::builderAppend(*output, ':');
it->second->writeJSON(output);
}
StringUtil::builderAppend(*output, '}');
}
void DictionaryValue::AppendSerialized(std::vector<uint8_t>* bytes) const { void DictionaryValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
cbor::EnvelopeEncoder encoder; cbor::EnvelopeEncoder encoder;
encoder.EncodeStart(bytes); encoder.EncodeStart(bytes);
...@@ -621,19 +512,6 @@ ListValue::~ListValue() ...@@ -621,19 +512,6 @@ ListValue::~ListValue()
{ {
} }
void ListValue::writeJSON(StringBuilder* output) const
{
StringUtil::builderAppend(*output, '[');
bool first = true;
for (const std::unique_ptr<protocol::Value>& value : m_data) {
if (!first)
StringUtil::builderAppend(*output, ',');
value->writeJSON(output);
first = false;
}
StringUtil::builderAppend(*output, ']');
}
void ListValue::AppendSerialized(std::vector<uint8_t>* bytes) const { void ListValue::AppendSerialized(std::vector<uint8_t>* bytes) const {
cbor::EnvelopeEncoder encoder; cbor::EnvelopeEncoder encoder;
encoder.EncodeStart(bytes); encoder.EncodeStart(bytes);
...@@ -670,16 +548,6 @@ protocol::Value* ListValue::at(size_t index) ...@@ -670,16 +548,6 @@ protocol::Value* ListValue::at(size_t index)
return m_data[index].get(); return m_data[index].get();
} }
void escapeLatinStringForJSON(const uint8_t* str, unsigned len, StringBuilder* dst)
{
escapeStringForJSONInternal<uint8_t>(str, len, dst);
}
void escapeWideStringForJSON(const uint16_t* str, unsigned len, StringBuilder* dst)
{
escapeStringForJSONInternal<uint16_t>(str, len, dst);
}
{% for namespace in config.protocol.namespace %} {% for namespace in config.protocol.namespace %}
} // namespace {{namespace}} } // namespace {{namespace}}
{% endfor %} {% endfor %}
...@@ -52,10 +52,8 @@ public: ...@@ -52,10 +52,8 @@ public:
virtual bool asString(String* output) const; virtual bool asString(String* output) const;
virtual bool asBinary(Binary* output) const; virtual bool asBinary(Binary* output) const;
virtual void writeJSON(StringBuilder* output) const;
virtual void AppendSerialized(std::vector<uint8_t>* bytes) const override; virtual void AppendSerialized(std::vector<uint8_t>* bytes) const override;
virtual std::unique_ptr<Value> clone() const; virtual std::unique_ptr<Value> clone() const;
String toJSONString() const;
protected: protected:
Value() : m_type(TypeNull) { } Value() : m_type(TypeNull) { }
...@@ -88,7 +86,6 @@ public: ...@@ -88,7 +86,6 @@ public:
bool asBoolean(bool* output) const override; bool asBoolean(bool* output) const override;
bool asDouble(double* output) const override; bool asDouble(double* output) const override;
bool asInteger(int* output) const override; bool asInteger(int* output) const override;
void writeJSON(StringBuilder* output) const override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override; void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
...@@ -117,7 +114,6 @@ public: ...@@ -117,7 +114,6 @@ public:
} }
bool asString(String* output) const override; bool asString(String* output) const override;
void writeJSON(StringBuilder* output) const override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override; void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
...@@ -136,7 +132,6 @@ public: ...@@ -136,7 +132,6 @@ public:
} }
bool asBinary(Binary* output) const override; bool asBinary(Binary* output) const override;
void writeJSON(StringBuilder* output) const override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override; void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
...@@ -166,7 +161,6 @@ public: ...@@ -166,7 +161,6 @@ public:
return std::unique_ptr<DictionaryValue>(DictionaryValue::cast(value.release())); return std::unique_ptr<DictionaryValue>(DictionaryValue::cast(value.release()));
} }
void writeJSON(StringBuilder* output) const override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override; void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
...@@ -235,7 +229,6 @@ public: ...@@ -235,7 +229,6 @@ public:
~ListValue() override; ~ListValue() override;
void writeJSON(StringBuilder* output) const override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override; void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override; std::unique_ptr<Value> clone() const override;
...@@ -250,9 +243,6 @@ private: ...@@ -250,9 +243,6 @@ private:
std::vector<std::unique_ptr<Value>> m_data; std::vector<std::unique_ptr<Value>> m_data;
}; };
void escapeLatinStringForJSON(const uint8_t* str, unsigned len, StringBuilder* dst);
void escapeWideStringForJSON(const uint16_t* str, unsigned len, StringBuilder* dst);
{% for namespace in config.protocol.namespace %} {% for namespace in config.protocol.namespace %}
} // namespace {{namespace}} } // namespace {{namespace}}
{% endfor %} {% endfor %}
......
...@@ -145,16 +145,6 @@ void StringBuilder::append(const char* characters, size_t length) { ...@@ -145,16 +145,6 @@ void StringBuilder::append(const char* characters, size_t length) {
string_.append(characters, length); string_.append(characters, length);
} }
// static
void StringUtil::builderAppendQuotedString(StringBuilder& builder,
const String& str) {
builder.append('"');
base::string16 str16 = base::UTF8ToUTF16(str);
escapeWideStringForJSON(reinterpret_cast<const uint16_t*>(&str16[0]),
str16.length(), &builder);
builder.append('"');
}
std::string StringBuilder::toString() { std::string StringBuilder::toString() {
return string_; return string_;
} }
......
...@@ -84,8 +84,6 @@ class {{config.lib.export_macro}} StringUtil { ...@@ -84,8 +84,6 @@ class {{config.lib.export_macro}} StringUtil {
static void builderAppend(StringBuilder& builder, const char* s, size_t len) { static void builderAppend(StringBuilder& builder, const char* s, size_t len) {
builder.append(s, len); builder.append(s, len);
} }
static void builderAppendQuotedString(StringBuilder& builder,
const String& str);
static void builderReserve(StringBuilder& builder, unsigned capacity) { static void builderReserve(StringBuilder& builder, unsigned capacity) {
builder.reserveCapacity(capacity); builder.reserveCapacity(capacity);
} }
......
...@@ -20,8 +20,6 @@ namespace {{namespace}} { ...@@ -20,8 +20,6 @@ namespace {{namespace}} {
#define {{"_".join(config.protocol.namespace)}}_exported_api_h #define {{"_".join(config.protocol.namespace)}}_exported_api_h
class {{config.exported.export_macro}} Exported { class {{config.exported.export_macro}} Exported {
public: public:
virtual {{config.exported.string_out}} toJSONString() const = 0;
virtual void AppendSerialized(std::vector<uint8_t>* out) const = 0; virtual void AppendSerialized(std::vector<uint8_t>* out) const = 0;
virtual ~Exported() { } virtual ~Exported() { }
......
...@@ -29,12 +29,6 @@ public: ...@@ -29,12 +29,6 @@ public:
return std::unique_ptr<ImportedValue>(new ImportedValue(value)); return std::unique_ptr<ImportedValue>(new ImportedValue(value));
} }
void writeJSON(StringBuilder* output) const override {
auto json = m_exported->toJSONString();
String local_json = ({{config.imported.from_imported_string % "std::move(json)"}});
StringUtil::builderAppend(*output, local_json);
}
void AppendSerialized(std::vector<uint8_t>* output) const override { void AppendSerialized(std::vector<uint8_t>* output) const override {
m_exported->AppendSerialized(output); m_exported->AppendSerialized(output);
} }
......
...@@ -114,12 +114,6 @@ std::unique_ptr<{{type.id}}> {{type.id}}::clone() const ...@@ -114,12 +114,6 @@ std::unique_ptr<{{type.id}}> {{type.id}}::clone() const
} }
{% if protocol.is_exported(domain.domain, type.id) %} {% if protocol.is_exported(domain.domain, type.id) %}
{{config.exported.string_out}} {{type.id}}::toJSONString() const
{
String json = toValue()->toJSONString();
return {{config.exported.to_string_out % "json"}};
}
// static // static
std::unique_ptr<API::{{type.id}}> API::{{type.id}}::fromBinary(const uint8_t* data, size_t length) std::unique_ptr<API::{{type.id}}> API::{{type.id}}::fromBinary(const uint8_t* data, size_t length)
{ {
......
...@@ -101,11 +101,7 @@ public: ...@@ -101,11 +101,7 @@ public:
std::unique_ptr<protocol::DictionaryValue> toValue() const; std::unique_ptr<protocol::DictionaryValue> toValue() const;
void AppendSerialized(std::vector<uint8_t>* out) const override; void AppendSerialized(std::vector<uint8_t>* out) const override;
String toJSON() const { return toValue()->toJSONString(); }
std::unique_ptr<{{type.id}}> clone() const; std::unique_ptr<{{type.id}}> clone() const;
{% if protocol.is_exported(domain.domain, type.id) %}
{{config.exported.string_out}} toJSONString() const override;
{% endif %}
template<int STATE> template<int STATE>
class {{type.id}}Builder { class {{type.id}}Builder {
......
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