diff --git a/src/inspector/string-util.h b/src/inspector/string-util.h index c484aab2ed..1936c11d00 100644 --- a/src/inspector/string-util.h +++ b/src/inspector/string-util.h @@ -33,9 +33,21 @@ class StringUtil { } static String fromDouble(double number) { return String::fromDouble(number); } static const size_t kNotFound = String::kNotFound; + static void builderAppend(StringBuilder& builder, const String& s) { + builder.append(s); + } + static void builderAppend(StringBuilder& builder, UChar c) { + builder.append(c); + } + static void builderAppend(StringBuilder& builder, const char* s, size_t len) { + builder.append(s, len); + } static void builderReserve(StringBuilder& builder, size_t capacity) { builder.reserveCapacity(capacity); } + static String builderToString(StringBuilder& builder) { + return builder.toString(); + } static std::unique_ptr parseJSON(const String16& json); static std::unique_ptr parseJSON(const StringView& json); }; diff --git a/third_party/inspector_protocol/README.v8 b/third_party/inspector_protocol/README.v8 index 178a1a75e3..68421ea189 100644 --- a/third_party/inspector_protocol/README.v8 +++ b/third_party/inspector_protocol/README.v8 @@ -2,7 +2,7 @@ Name: inspector protocol Short Name: inspector_protocol URL: https://chromium.googlesource.com/deps/inspector_protocol/ Version: 0 -Revision: 715b83a3cfb45ce6c67b6c6fdd2c16391b5db896 +Revision: 1a131872167f0f7653629326891aa3ec94417f27 License: BSD License File: LICENSE Security Critical: no diff --git a/third_party/inspector_protocol/lib/ErrorSupport_cpp.template b/third_party/inspector_protocol/lib/ErrorSupport_cpp.template index e4ae0c4e47..2108262a12 100644 --- a/third_party/inspector_protocol/lib/ErrorSupport_cpp.template +++ b/third_party/inspector_protocol/lib/ErrorSupport_cpp.template @@ -32,12 +32,12 @@ 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]); + StringUtil::builderAppend(builder, '.'); + StringUtil::builderAppend(builder, m_path[i]); } - builder.append(": "); - builder.append(error); - m_errors.push_back(builder.toString()); + StringUtil::builderAppend(builder, ": "); + StringUtil::builderAppend(builder, error); + m_errors.push_back(StringUtil::builderToString(builder)); } bool ErrorSupport::hasErrors() @@ -50,10 +50,10 @@ String ErrorSupport::errors() StringBuilder builder; for (size_t i = 0; i < m_errors.size(); ++i) { if (i) - builder.append("; "); - builder.append(m_errors[i]); + StringUtil::builderAppend(builder, "; "); + StringUtil::builderAppend(builder, m_errors[i]); } - return builder.toString(); + return StringUtil::builderToString(builder); } {% for namespace in config.protocol.namespace %} diff --git a/third_party/inspector_protocol/lib/Parser_cpp.template b/third_party/inspector_protocol/lib/Parser_cpp.template index 11a60639df..4bf6bebc46 100644 --- a/third_party/inspector_protocol/lib/Parser_cpp.template +++ b/third_party/inspector_protocol/lib/Parser_cpp.template @@ -337,7 +337,7 @@ bool decodeString(const Char* start, const Char* end, StringBuilder* output) while (start < end) { uint16_t c = *start++; if ('\\' != c) { - output->append(c); + StringUtil::builderAppend(*output, c); continue; } if (start == end) @@ -382,7 +382,7 @@ bool decodeString(const Char* start, const Char* end, StringBuilder* output) default: return false; } - output->append(c); + StringUtil::builderAppend(*output, c); } return true; } @@ -400,7 +400,7 @@ bool decodeString(const Char* start, const Char* end, String* output) StringUtil::builderReserve(buffer, end - start); if (!decodeString(start, end, &buffer)) return false; - *output = buffer.toString(); + *output = StringUtil::builderToString(buffer); return true; } diff --git a/third_party/inspector_protocol/lib/Values_cpp.template b/third_party/inspector_protocol/lib/Values_cpp.template index 8fe128ef48..6f8b14c16c 100644 --- a/third_party/inspector_protocol/lib/Values_cpp.template +++ b/third_party/inspector_protocol/lib/Values_cpp.template @@ -17,13 +17,13 @@ const char* const falseValueString = "false"; inline bool escapeChar(uint16_t c, StringBuilder* dst) { switch (c) { - case '\b': dst->append("\\b"); break; - case '\f': dst->append("\\f"); break; - case '\n': dst->append("\\n"); break; - case '\r': dst->append("\\r"); break; - case '\t': dst->append("\\t"); break; - case '\\': dst->append("\\\\"); break; - case '"': dst->append("\\\""); break; + 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; } @@ -34,10 +34,10 @@ const char hexDigits[17] = "0123456789ABCDEF"; void appendUnsignedAsHex(uint16_t number, StringBuilder* dst) { - dst->append("\\u"); + StringUtil::builderAppend(*dst, "\\u"); for (size_t i = 0; i < 4; ++i) { uint16_t c = hexDigits[(number & 0xF000) >> 12]; - dst->append(c); + StringUtil::builderAppend(*dst, c); number <<= 4; } } @@ -53,7 +53,7 @@ void escapeStringForJSON(const String& str, StringBuilder* dst) // is also optional. It would also be a pain to implement here. appendUnsignedAsHex(c, dst); } else { - dst->append(c); + StringUtil::builderAppend(*dst, c); } } } @@ -61,9 +61,9 @@ void escapeStringForJSON(const String& str, StringBuilder* dst) void doubleQuoteStringForJSON(const String& str, StringBuilder* dst) { - dst->append('"'); + StringUtil::builderAppend(*dst, '"'); escapeStringForJSON(str, dst); - dst->append('"'); + StringUtil::builderAppend(*dst, '"'); } } // anonymous namespace @@ -96,7 +96,7 @@ bool Value::asSerialized(String*) const void Value::writeJSON(StringBuilder* output) const { DCHECK(m_type == TypeNull); - output->append(nullValueString, 4); + StringUtil::builderAppend(*output, nullValueString, 4); } std::unique_ptr Value::clone() const @@ -109,7 +109,7 @@ String Value::serialize() StringBuilder result; StringUtil::builderReserve(result, 512); writeJSON(&result); - return result.toString(); + return StringUtil::builderToString(result); } bool FundamentalValue::asBoolean(bool* output) const @@ -146,17 +146,17 @@ void FundamentalValue::writeJSON(StringBuilder* output) const DCHECK(type() == TypeBoolean || type() == TypeInteger || type() == TypeDouble); if (type() == TypeBoolean) { if (m_boolValue) - output->append(trueValueString, 4); + StringUtil::builderAppend(*output, trueValueString, 4); else - output->append(falseValueString, 5); + StringUtil::builderAppend(*output, falseValueString, 5); } else if (type() == TypeDouble) { if (!std::isfinite(m_doubleValue)) { - output->append(nullValueString, 4); + StringUtil::builderAppend(*output, nullValueString, 4); return; } - output->append(StringUtil::fromDouble(m_doubleValue)); + StringUtil::builderAppend(*output, StringUtil::fromDouble(m_doubleValue)); } else if (type() == TypeInteger) { - output->append(StringUtil::fromInteger(m_integerValue)); + StringUtil::builderAppend(*output, StringUtil::fromInteger(m_integerValue)); } } @@ -198,7 +198,7 @@ bool SerializedValue::asSerialized(String* output) const void SerializedValue::writeJSON(StringBuilder* output) const { DCHECK(type() == TypeSerialized); - output->append(m_serializedValue); + StringUtil::builderAppend(*output, m_serializedValue); } std::unique_ptr SerializedValue::clone() const @@ -330,17 +330,17 @@ void DictionaryValue::remove(const String& name) void DictionaryValue::writeJSON(StringBuilder* output) const { - output->append('{'); + 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) - output->append(','); + StringUtil::builderAppend(*output, ','); doubleQuoteStringForJSON(it->first, output); - output->append(':'); + StringUtil::builderAppend(*output, ':'); it->second->writeJSON(output); } - output->append('}'); + StringUtil::builderAppend(*output, '}'); } std::unique_ptr DictionaryValue::clone() const @@ -366,15 +366,15 @@ ListValue::~ListValue() void ListValue::writeJSON(StringBuilder* output) const { - output->append('['); + StringUtil::builderAppend(*output, '['); bool first = true; for (const std::unique_ptr& value : m_data) { if (!first) - output->append(','); + StringUtil::builderAppend(*output, ','); value->writeJSON(output); first = false; } - output->append(']'); + StringUtil::builderAppend(*output, ']'); } std::unique_ptr ListValue::clone() const