Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1205)

Unified Diff: third_party/WebKit/Source/platform/inspector_protocol/Values.cpp

Issue 1767883002: DevTools: generate string16-based handlers for v8_inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
diff --git a/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp b/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
index 4f7a6a427392cf5d00fa71368fddd46443c2975e..f5f8c8642a32115d8f63ba9460585d546184e73c 100644
--- a/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
+++ b/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
@@ -6,7 +6,7 @@
#include "platform/Decimal.h"
#include "platform/inspector_protocol/Parser.h"
-#include "wtf/text/StringBuilder.h"
+#include "platform/inspector_protocol/String16.h"
#include <cmath>
namespace blink {
@@ -18,23 +18,34 @@ const char* const nullString = "null";
const char* const trueString = "true";
const char* const falseString = "false";
-inline bool escapeChar(UChar c, StringBuilder* dst)
+inline bool escapeChar(UChar c, String16Builder* dst)
{
switch (c) {
- case '\b': dst->appendLiteral("\\b"); break;
- case '\f': dst->appendLiteral("\\f"); break;
- case '\n': dst->appendLiteral("\\n"); break;
- case '\r': dst->appendLiteral("\\r"); break;
- case '\t': dst->appendLiteral("\\t"); break;
- case '\\': dst->appendLiteral("\\\\"); break;
- case '"': dst->appendLiteral("\\\""); break;
+ 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;
default:
return false;
}
return true;
}
-void escapeStringForJSON(const String& str, StringBuilder* dst)
+const LChar hexDigits[17] = "0123456789ABCDEF";
+
+void appendUnsignedAsHex(unsigned number, String16Builder* dst)
dgozman 2016/03/08 01:35:12 UChar number
+{
+ dst->append("\\u");
+ for (size_t i = 0; i < 4; ++i) {
+ dst->append(hexDigits[(number & 0xF000) >> 12]);
+ number <<= 4;
+ }
+}
+
+void escapeStringForJSON(const String16& str, String16Builder* dst)
{
for (unsigned i = 0; i < str.length(); ++i) {
UChar c = str[i];
@@ -43,9 +54,7 @@ void escapeStringForJSON(const String& str, StringBuilder* dst)
// 1. Escaping <, > to prevent script execution.
// 2. Technically, we could also pass through c > 126 as UTF8, but this
// is also optional. It would also be a pain to implement here.
- unsigned symbol = static_cast<unsigned>(c);
- String symbolCode = String::format("\\u%04X", symbol);
- dst->append(symbolCode);
+ appendUnsignedAsHex(static_cast<unsigned>(c), dst);
} else {
dst->append(c);
}
@@ -53,7 +62,7 @@ void escapeStringForJSON(const String& str, StringBuilder* dst)
}
}
-void doubleQuoteStringForJSON(const String& str, StringBuilder* dst)
+void doubleQuoteStringForJSON(const String16& str, String16Builder* dst)
{
dst->append('"');
escapeStringForJSON(str, dst);
@@ -77,20 +86,20 @@ bool Value::asNumber(int*) const
return false;
}
-bool Value::asString(String*) const
+bool Value::asString(String16*) const
{
return false;
}
-String Value::toJSONString() const
+String16 Value::toJSONString() const
{
- StringBuilder result;
+ String16Builder result;
result.reserveCapacity(512);
writeJSON(&result);
return result.toString();
}
-void Value::writeJSON(StringBuilder* output) const
+void Value::writeJSON(String16Builder* output) const
{
ASSERT(m_type == TypeNull);
output->append(nullString, 4);
@@ -125,7 +134,7 @@ bool FundamentalValue::asNumber(int* output) const
return true;
}
-void FundamentalValue::writeJSON(StringBuilder* output) const
+void FundamentalValue::writeJSON(String16Builder* output) const
{
ASSERT(type() == TypeBoolean || type() == TypeNumber);
if (type() == TypeBoolean) {
@@ -147,13 +156,13 @@ PassOwnPtr<Value> FundamentalValue::clone() const
return type() == TypeNumber ? FundamentalValue::create(m_doubleValue) : FundamentalValue::create(m_boolValue);
}
-bool StringValue::asString(String* output) const
+bool StringValue::asString(String16* output) const
{
*output = m_stringValue;
return true;
}
-void StringValue::writeJSON(StringBuilder* output) const
+void StringValue::writeJSON(String16Builder* output) const
{
ASSERT(type() == TypeString);
doubleQuoteStringForJSON(m_stringValue, output);
@@ -168,43 +177,43 @@ DictionaryValue::~DictionaryValue()
{
}
-void DictionaryValue::setBoolean(const String& name, bool value)
+void DictionaryValue::setBoolean(const String16& name, bool value)
{
setValue(name, FundamentalValue::create(value));
}
-void DictionaryValue::setNumber(const String& name, double value)
+void DictionaryValue::setNumber(const String16& name, double value)
{
setValue(name, FundamentalValue::create(value));
}
-void DictionaryValue::setString(const String& name, const String& value)
+void DictionaryValue::setString(const String16& name, const String16& value)
{
setValue(name, StringValue::create(value));
}
-void DictionaryValue::setValue(const String& name, PassOwnPtr<Value> value)
+void DictionaryValue::setValue(const String16& name, PassOwnPtr<Value> value)
{
ASSERT(value);
if (m_data.set(name, value))
m_order.append(name);
}
-void DictionaryValue::setObject(const String& name, PassOwnPtr<DictionaryValue> value)
+void DictionaryValue::setObject(const String16& name, PassOwnPtr<DictionaryValue> value)
{
ASSERT(value);
if (m_data.set(name, value))
m_order.append(name);
}
-void DictionaryValue::setArray(const String& name, PassOwnPtr<ListValue> value)
+void DictionaryValue::setArray(const String16& name, PassOwnPtr<ListValue> value)
{
ASSERT(value);
if (m_data.set(name, value))
m_order.append(name);
}
-bool DictionaryValue::getBoolean(const String& name, bool* output) const
+bool DictionaryValue::getBoolean(const String16& name, bool* output) const
{
protocol::Value* value = get(name);
if (!value)
@@ -212,7 +221,7 @@ bool DictionaryValue::getBoolean(const String& name, bool* output) const
return value->asBoolean(output);
}
-bool DictionaryValue::getString(const String& name, String* output) const
+bool DictionaryValue::getString(const String16& name, String16* output) const
{
protocol::Value* value = get(name);
if (!value)
@@ -220,17 +229,17 @@ bool DictionaryValue::getString(const String& name, String* output) const
return value->asString(output);
}
-DictionaryValue* DictionaryValue::getObject(const String& name) const
+DictionaryValue* DictionaryValue::getObject(const String16& name) const
{
return DictionaryValue::cast(get(name));
}
-protocol::ListValue* DictionaryValue::getArray(const String& name) const
+protocol::ListValue* DictionaryValue::getArray(const String16& name) const
{
return ListValue::cast(get(name));
}
-protocol::Value* DictionaryValue::get(const String& name) const
+protocol::Value* DictionaryValue::get(const String16& name) const
{
Dictionary::const_iterator it = m_data.find(name);
if (it == m_data.end())
@@ -240,18 +249,18 @@ protocol::Value* DictionaryValue::get(const String& name) const
DictionaryValue::Entry DictionaryValue::at(size_t index) const
{
- String key = m_order[index];
+ String16 key = m_order[index];
return std::make_pair(key, m_data.get(key));
}
-bool DictionaryValue::booleanProperty(const String& name, bool defaultValue) const
+bool DictionaryValue::booleanProperty(const String16& name, bool defaultValue) const
{
bool result = defaultValue;
getBoolean(name, &result);
return result;
}
-void DictionaryValue::remove(const String& name)
+void DictionaryValue::remove(const String16& name)
{
m_data.remove(name);
for (size_t i = 0; i < m_order.size(); ++i) {
@@ -262,7 +271,7 @@ void DictionaryValue::remove(const String& name)
}
}
-void DictionaryValue::writeJSON(StringBuilder* output) const
+void DictionaryValue::writeJSON(String16Builder* output) const
{
output->append('{');
for (size_t i = 0; i < m_order.size(); ++i) {
@@ -281,7 +290,7 @@ PassOwnPtr<Value> DictionaryValue::clone() const
{
OwnPtr<DictionaryValue> result = DictionaryValue::create();
for (size_t i = 0; i < m_order.size(); ++i) {
- String key = m_order[i];
+ String16 key = m_order[i];
Value* value = m_data.get(key);
ASSERT(value);
result->setValue(key, value->clone());
@@ -298,7 +307,7 @@ ListValue::~ListValue()
{
}
-void ListValue::writeJSON(StringBuilder* output) const
+void ListValue::writeJSON(String16Builder* output) const
{
output->append('[');
for (Vector<OwnPtr<protocol::Value>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it) {

Powered by Google App Engine
This is Rietveld 408576698