[DevTools] Roll inspector_protocol (V8)

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

Also, remove builderAppendQuotedString from string-util.h in v8 since it's
unused now and it relies on the jinja template code I'm deleting.

"Upon encountering a byte that's unexpectedly not ..."
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/2013764

New Rev: a84e91f6696a0b76e1a73286c9c2765154de9889

Change-Id: I26805c47950d880b5be2cfb9bdcb41a3f51218b6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2013561
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65940}
This commit is contained in:
Johannes Henkel 2020-01-22 11:45:16 -08:00 committed by Commit Bot
parent 53cf5df499
commit 9c934d3487
13 changed files with 37 additions and 188 deletions

View File

@ -124,19 +124,6 @@ std::unique_ptr<protocol::Value> StringUtil::parseJSON(const String16& string) {
return parseJSONCharacters(string.characters16(),
static_cast<int>(string.length()));
}
// static
void StringUtil::builderAppendQuotedString(StringBuilder& builder,
const String& str) {
builder.append('"');
if (!str.isEmpty()) {
escapeWideStringForJSON(
reinterpret_cast<const uint16_t*>(str.characters16()),
static_cast<int>(str.length()), &builder);
}
builder.append('"');
}
} // namespace protocol
// static

View File

@ -56,7 +56,6 @@ class StringUtil {
const char* s, size_t len) {
builder.append(s, len);
}
static void builderAppendQuotedString(StringBuilder&, const String&);
static void builderReserve(
StringBuilder& builder, // NOLINT(runtime/references)
size_t capacity) {

View File

@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: ac6919eb836521a96cc18931f0bf270d8c1b53a1
Revision: a84e91f6696a0b76e1a73286c9c2765154de9889
License: BSD
License File: LICENSE
Security Critical: no

View File

@ -225,14 +225,17 @@ class JSONEncoder : public ParserHandler {
// belonging to this Unicode character into |codepoint|.
if (ii + num_bytes_left >= chars.size())
continue;
bool invalid_byte_seen = false;
while (num_bytes_left > 0) {
c = chars[++ii];
--num_bytes_left;
// Check the next byte is a continuation byte, that is 10xx xxxx.
if ((c & 0xc0) != 0x80)
continue;
invalid_byte_seen = true;
codepoint = (codepoint << 6) | (c & 0x3f);
}
if (invalid_byte_seen)
continue;
// Disallow overlong encodings for ascii characters, as these
// would include " and other characters significant to JSON

View File

@ -49,6 +49,38 @@ TEST(JsonEncoder, OverlongEncodings) {
EXPECT_EQ("\"\"", out); // Empty string means that 0x7f was rejected (good).
}
TEST(JsonEncoder, NotAContinuationByte) {
std::string out;
Status status;
std::unique_ptr<ParserHandler> writer = NewJSONEncoder(&out, &status);
// |world| encodes the globe as a 4 byte UTF8 sequence. So, naturally, it'll
// have a start byte, followed by three continuation bytes.
std::string world = "🌎";
ASSERT_EQ(4u, world.size());
ASSERT_EQ(world[1] & 0xc0, 0x80); // checks for continuation byte
ASSERT_EQ(world[2] & 0xc0, 0x80);
ASSERT_EQ(world[3] & 0xc0, 0x80);
// Now create a corrupted UTF8 string, starting with the first two bytes from
// |world|, followed by an ASCII message. Upon encountering '!', our decoder
// will realize that it's not a continuation byte; it'll skip to the end of
// this UTF8 sequence and continue with the next character. In this case, the
// 'H', of "Hello".
std::vector<uint8_t> chars;
chars.push_back(world[0]);
chars.push_back(world[1]);
chars.push_back('!');
chars.push_back('?');
chars.push_back('H');
chars.push_back('e');
chars.push_back('l');
chars.push_back('l');
chars.push_back('o');
writer->HandleString8(SpanFrom(chars));
EXPECT_EQ("\"Hello\"", out); // "Hello" shows we restarted at 'H'.
}
TEST(JsonEncoder, IncompleteUtf8Sequence) {
std::string out;
Status status;

View File

@ -13,55 +13,6 @@ namespace {{namespace}} {
{% endfor %}
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
// to this constant.
static constexpr int kStackLimitValues = 1000;
@ -275,12 +226,6 @@ bool Value::asBinary(Binary*) const
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 {
DCHECK(m_type == TypeNull);
bytes->push_back(cbor::EncodeNull());
@ -291,14 +236,6 @@ std::unique_ptr<Value> Value::clone() const
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
{
if (type() != TypeBoolean)
@ -328,25 +265,6 @@ bool FundamentalValue::asInteger(int* output) const
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 {
switch (type()) {
case TypeDouble:
@ -381,12 +299,6 @@ bool StringValue::asString(String* output) const
return true;
}
void StringValue::writeJSON(StringBuilder* output) const
{
DCHECK(type() == TypeString);
StringUtil::builderAppendQuotedString(*output, m_stringValue);
}
namespace {
// This routine distinguishes between the current encoding for a given
// string |s|, and calls encoding routines that will
@ -431,12 +343,6 @@ bool BinaryValue::asBinary(Binary* output) const
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 {
cbor::EncodeBinary(span<uint8_t>(m_binaryValue.data(),
m_binaryValue.size()), bytes);
@ -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());
}
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 {
cbor::EnvelopeEncoder encoder;
encoder.EncodeStart(bytes);
@ -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 {
cbor::EnvelopeEncoder encoder;
encoder.EncodeStart(bytes);
@ -670,16 +548,6 @@ protocol::Value* ListValue::at(size_t index)
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 %}
} // namespace {{namespace}}
{% endfor %}

View File

@ -52,10 +52,8 @@ public:
virtual bool asString(String* 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 std::unique_ptr<Value> clone() const;
String toJSONString() const;
protected:
Value() : m_type(TypeNull) { }
@ -88,7 +86,6 @@ public:
bool asBoolean(bool* output) const override;
bool asDouble(double* output) const override;
bool asInteger(int* output) const override;
void writeJSON(StringBuilder* output) const override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override;
@ -117,7 +114,6 @@ public:
}
bool asString(String* output) const override;
void writeJSON(StringBuilder* output) const override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override;
@ -136,7 +132,6 @@ public:
}
bool asBinary(Binary* output) const override;
void writeJSON(StringBuilder* output) const override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override;
@ -166,7 +161,6 @@ public:
return std::unique_ptr<DictionaryValue>(DictionaryValue::cast(value.release()));
}
void writeJSON(StringBuilder* output) const override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override;
@ -235,7 +229,6 @@ public:
~ListValue() override;
void writeJSON(StringBuilder* output) const override;
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
std::unique_ptr<Value> clone() const override;
@ -250,9 +243,6 @@ private:
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 %}
} // namespace {{namespace}}
{% endfor %}

View File

@ -145,16 +145,6 @@ void StringBuilder::append(const char* characters, size_t 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() {
return string_;
}

View File

@ -84,8 +84,6 @@ class {{config.lib.export_macro}} StringUtil {
static void builderAppend(StringBuilder& builder, const char* s, size_t len) {
builder.append(s, len);
}
static void builderAppendQuotedString(StringBuilder& builder,
const String& str);
static void builderReserve(StringBuilder& builder, unsigned capacity) {
builder.reserveCapacity(capacity);
}

View File

@ -20,8 +20,6 @@ namespace {{namespace}} {
#define {{"_".join(config.protocol.namespace)}}_exported_api_h
class {{config.exported.export_macro}} Exported {
public:
virtual {{config.exported.string_out}} toJSONString() const = 0;
virtual void AppendSerialized(std::vector<uint8_t>* out) const = 0;
virtual ~Exported() { }

View File

@ -29,12 +29,6 @@ public:
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 {
m_exported->AppendSerialized(output);
}

View File

@ -114,12 +114,6 @@ std::unique_ptr<{{type.id}}> {{type.id}}::clone() const
}
{% 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
std::unique_ptr<API::{{type.id}}> API::{{type.id}}::fromBinary(const uint8_t* data, size_t length)
{

View File

@ -101,11 +101,7 @@ public:
std::unique_ptr<protocol::DictionaryValue> toValue() const;
void AppendSerialized(std::vector<uint8_t>* out) const override;
String toJSON() const { return toValue()->toJSONString(); }
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>
class {{type.id}}Builder {