summaryrefslogtreecommitdiff
path: root/deps/v8/third_party/inspector_protocol/lib
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/third_party/inspector_protocol/lib')
-rw-r--r--deps/v8/third_party/inspector_protocol/lib/Forward_h.template3
-rw-r--r--deps/v8/third_party/inspector_protocol/lib/ValueConversions_cpp.template2
-rw-r--r--deps/v8/third_party/inspector_protocol/lib/Values_h.template13
-rw-r--r--deps/v8/third_party/inspector_protocol/lib/base_string_adapter_cc.template202
-rw-r--r--deps/v8/third_party/inspector_protocol/lib/base_string_adapter_h.template77
5 files changed, 63 insertions, 234 deletions
diff --git a/deps/v8/third_party/inspector_protocol/lib/Forward_h.template b/deps/v8/third_party/inspector_protocol/lib/Forward_h.template
index 54f25e1c9c..10b6c4ba2e 100644
--- a/deps/v8/third_party/inspector_protocol/lib/Forward_h.template
+++ b/deps/v8/third_party/inspector_protocol/lib/Forward_h.template
@@ -12,11 +12,8 @@
{% endif %}
#include {{format_include(config.lib.string_header)}}
-#include <cstddef>
#include <memory>
#include <vector>
-#include <unordered_map>
-#include <unordered_set>
#include "{{config.crdtp.dir}}/error_support.h"
#include "{{config.crdtp.dir}}/dispatch.h"
diff --git a/deps/v8/third_party/inspector_protocol/lib/ValueConversions_cpp.template b/deps/v8/third_party/inspector_protocol/lib/ValueConversions_cpp.template
index a16b522c38..998808be6c 100644
--- a/deps/v8/third_party/inspector_protocol/lib/ValueConversions_cpp.template
+++ b/deps/v8/third_party/inspector_protocol/lib/ValueConversions_cpp.template
@@ -18,7 +18,7 @@ namespace {{namespace}} {
{% endfor %}
{% for namespace in config.protocol.namespace %}
-} // namespce
+} // namespace
{% endfor %}
diff --git a/deps/v8/third_party/inspector_protocol/lib/Values_h.template b/deps/v8/third_party/inspector_protocol/lib/Values_h.template
index 8208009009..53087c914c 100644
--- a/deps/v8/third_party/inspector_protocol/lib/Values_h.template
+++ b/deps/v8/third_party/inspector_protocol/lib/Values_h.template
@@ -10,6 +10,11 @@
//#include "Allocator.h"
//#include "Forward.h"
+#include <memory>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
#include {{format_include(config.protocol.package, "Forward")}}
{% for namespace in config.protocol.namespace %}
@@ -165,7 +170,9 @@ public:
static std::unique_ptr<DictionaryValue> cast(std::unique_ptr<Value> value)
{
- return std::unique_ptr<DictionaryValue>(DictionaryValue::cast(value.release()));
+ DictionaryValue* dictionaryValue = cast(value.get());
+ if (dictionaryValue) value.release();
+ return std::unique_ptr<DictionaryValue>(dictionaryValue);
}
void AppendSerialized(std::vector<uint8_t>* bytes) const override;
@@ -231,7 +238,9 @@ public:
static std::unique_ptr<ListValue> cast(std::unique_ptr<Value> value)
{
- return std::unique_ptr<ListValue>(ListValue::cast(value.release()));
+ ListValue* listValue = cast(value.get());
+ if (listValue) value.release();
+ return std::unique_ptr<ListValue>(listValue);
}
~ListValue() override;
diff --git a/deps/v8/third_party/inspector_protocol/lib/base_string_adapter_cc.template b/deps/v8/third_party/inspector_protocol/lib/base_string_adapter_cc.template
index 96a0c8e3f3..4bb10dcc29 100644
--- a/deps/v8/third_party/inspector_protocol/lib/base_string_adapter_cc.template
+++ b/deps/v8/third_party/inspector_protocol/lib/base_string_adapter_cc.template
@@ -27,205 +27,97 @@ using {{"::".join(config.protocol.namespace)}}::StringUtil;
namespace {{namespace}} {
{% endfor %}
+// In Chromium, we do not support big endian architectures, so no conversion is needed
+// to interpret UTF16LE.
+// static
+String StringUtil::fromUTF16LE(const uint16_t* data, size_t length) {
+ std::string utf8;
+ base::UTF16ToUTF8(reinterpret_cast<const char16_t*>(data), length, &utf8);
+ return utf8;
+}
+
std::unique_ptr<protocol::Value> toProtocolValue(
- const base::Value* value, int depth) {
- if (!value || !depth)
+ const base::Value& value, int depth) {
+ if (!depth)
return nullptr;
- if (value->is_none())
+ if (value.is_none())
return protocol::Value::null();
- if (value->is_bool())
- return protocol::FundamentalValue::create(value->GetBool());
- if (value->is_int())
- return protocol::FundamentalValue::create(value->GetInt());
- if (value->is_double())
- return protocol::FundamentalValue::create(value->GetDouble());
- if (value->is_string())
- return protocol::StringValue::create(value->GetString());
- if (value->is_list()) {
- std::unique_ptr<protocol::ListValue> result = protocol::ListValue::create();
- for (const base::Value& item : value->GetList()) {
- std::unique_ptr<protocol::Value> converted =
- toProtocolValue(&item, depth - 1);
- if (converted)
+ if (value.is_bool())
+ return protocol::FundamentalValue::create(value.GetBool());
+ if (value.is_int())
+ return protocol::FundamentalValue::create(value.GetInt());
+ if (value.is_double())
+ return protocol::FundamentalValue::create(value.GetDouble());
+ if (value.is_string())
+ return protocol::StringValue::create(value.GetString());
+ if (value.is_list()) {
+ auto result = protocol::ListValue::create();
+ for (const base::Value& item : value.GetList()) {
+ if (auto converted = toProtocolValue(item, depth - 1)) {
result->pushValue(std::move(converted));
+ }
}
return result;
}
- if (value->is_dict()) {
- std::unique_ptr<protocol::DictionaryValue> result =
- protocol::DictionaryValue::create();
- for (const auto& it : value->DictItems()) {
- std::unique_ptr<protocol::Value> converted =
- toProtocolValue(&it.second, depth - 1);
- if (converted)
- result->setValue(it.first, std::move(converted));
+ if (value.is_dict()) {
+ auto result = protocol::DictionaryValue::create();
+ for (auto kv : value.DictItems()) {
+ if (auto converted = toProtocolValue(kv.second, depth - 1)) {
+ result->setValue(kv.first, std::move(converted));
+ }
}
return result;
}
return nullptr;
}
-std::unique_ptr<base::Value> toBaseValue(Value* value, int depth) {
+base::Value toBaseValue(Value* value, int depth) {
if (!value || !depth)
- return nullptr;
- if (value->type() == Value::TypeNull)
- return std::make_unique<base::Value>();
+ return base::Value();
if (value->type() == Value::TypeBoolean) {
bool inner;
value->asBoolean(&inner);
- return base::WrapUnique(new base::Value(inner));
+ return base::Value(inner);
}
if (value->type() == Value::TypeInteger) {
int inner;
value->asInteger(&inner);
- return base::WrapUnique(new base::Value(inner));
+ return base::Value(inner);
}
if (value->type() == Value::TypeDouble) {
double inner;
value->asDouble(&inner);
- return base::WrapUnique(new base::Value(inner));
+ return base::Value(inner);
}
if (value->type() == Value::TypeString) {
std::string inner;
value->asString(&inner);
- return base::WrapUnique(new base::Value(inner));
+ return base::Value(inner);
}
if (value->type() == Value::TypeArray) {
ListValue* list = ListValue::cast(value);
- std::unique_ptr<base::Value> result(new base::Value(
- base::Value::Type::LIST));
+ base::Value result(base::Value::Type::LIST);
for (size_t i = 0; i < list->size(); i++) {
- std::unique_ptr<base::Value> converted =
- toBaseValue(list->at(i), depth - 1);
- if (converted)
- result->Append(std::move(*converted));
+ base::Value converted = toBaseValue(list->at(i), depth - 1);
+ if (!converted.is_none())
+ result.Append(std::move(converted));
}
return result;
}
if (value->type() == Value::TypeObject) {
DictionaryValue* dict = DictionaryValue::cast(value);
- std::unique_ptr<base::Value> result(new base::Value(
- base::Value::Type::DICTIONARY));
+ base::Value result(base::Value::Type::DICTIONARY);
for (size_t i = 0; i < dict->size(); i++) {
DictionaryValue::Entry entry = dict->at(i);
- std::unique_ptr<base::Value> converted =
- toBaseValue(entry.second, depth - 1);
- if (converted)
- result->SetKey(entry.first, std::move(*converted));
+ base::Value converted = toBaseValue(entry.second, depth - 1);
+ if (!converted.is_none())
+ result.SetKey(entry.first, std::move(converted));
}
return result;
}
- return nullptr;
-}
-
-// In Chromium, we do not support big endian architectures, so no conversion is needed
-// to interpret UTF16LE.
-// static
-String StringUtil::fromUTF16LE(const uint16_t* data, size_t length) {
- std::string utf8;
- base::UTF16ToUTF8(reinterpret_cast<const char16_t*>(data), length, &utf8);
- return utf8;
-}
-
-bool StringUtil::ReadString(DeserializerState* state, String* value) {
- auto* tokenizer = state->tokenizer();
- if (tokenizer->TokenTag() == cbor::CBORTokenTag::STRING8) {
- const auto str = tokenizer->GetString8();
- *value = StringUtil::fromUTF8(str.data(), str.size());
- return true;
- }
- if (tokenizer->TokenTag() == cbor::CBORTokenTag::STRING16) {
- const auto str = tokenizer->GetString16WireRep();
- *value = StringUtil::fromUTF16LE(reinterpret_cast<const uint16_t*>(str.data()), str.size() / 2);
- return true;
- }
- state->RegisterError(Error::BINDINGS_STRING_VALUE_EXPECTED);
- return false;
-}
-
-void StringUtil::WriteString(const String& str, std::vector<uint8_t>* bytes) {
- cbor::EncodeString8(span<uint8_t>(StringUtil::CharactersUTF8(str),
- StringUtil::CharacterCount(str)),
- bytes);
-}
-
-Binary::Binary() : bytes_(new base::RefCountedBytes) {}
-Binary::Binary(const Binary& binary) : bytes_(binary.bytes_) {}
-Binary::Binary(scoped_refptr<base::RefCountedMemory> bytes) : bytes_(bytes) {}
-Binary::~Binary() {}
-
-void Binary::AppendSerialized(std::vector<uint8_t>* out) const {
- crdtp::cbor::EncodeBinary(crdtp::span<uint8_t>(data(), size()), out);
-}
-
-String Binary::toBase64() const {
- std::string encoded;
- base::Base64Encode(
- base::StringPiece(reinterpret_cast<const char*>(bytes_->front()),
- bytes_->size()),
- &encoded);
- return encoded;
-}
-
-// static
-Binary Binary::fromBase64(const String& base64, bool* success) {
- std::string decoded;
- *success = base::Base64Decode(base::StringPiece(base64), &decoded);
- if (*success) {
- return Binary::fromString(std::move(decoded));
- }
- return Binary();
-}
-
-// static
-Binary Binary::fromRefCounted(scoped_refptr<base::RefCountedMemory> memory) {
- return Binary(memory);
-}
-
-// static
-Binary Binary::fromVector(std::vector<uint8_t> data) {
- return Binary(base::RefCountedBytes::TakeVector(&data));
-}
-
-// static
-Binary Binary::fromString(std::string data) {
- return Binary(base::RefCountedString::TakeString(&data));
-}
-
-// static
-Binary Binary::fromSpan(const uint8_t* data, size_t size) {
- return Binary(scoped_refptr<base::RefCountedBytes>(
- new base::RefCountedBytes(data, size)));
+ return base::Value();
}
{% for namespace in config.protocol.namespace %}
-} // namespace {{namespace}}
+} // namespace {{namespace}} {
{% endfor %}
-
-namespace {{config.crdtp.namespace}} {
-
-// static
-bool ProtocolTypeTraits<Binary>::Deserialize(DeserializerState* state, Binary* value) {
- auto* tokenizer = state->tokenizer();
- if (tokenizer->TokenTag() == cbor::CBORTokenTag::BINARY) {
- const span<uint8_t> bin = tokenizer->GetBinary();
- *value = Binary::fromSpan(bin.data(), bin.size());
- return true;
- }
- if (tokenizer->TokenTag() == cbor::CBORTokenTag::STRING8) {
- const auto str_span = tokenizer->GetString8();
- String str = StringUtil::fromUTF8(str_span.data(), str_span.size());
- bool success = false;
- *value = Binary::fromBase64(str, &success);
- return success;
- }
- state->RegisterError(Error::BINDINGS_BINARY_VALUE_EXPECTED);
- return false;
-}
-
-// static
-void ProtocolTypeTraits<Binary>::Serialize(const Binary& value, std::vector<uint8_t>* bytes) {
- value.AppendSerialized(bytes);
-}
-
-} // namespace {{config.crdtp.namespace}}
diff --git a/deps/v8/third_party/inspector_protocol/lib/base_string_adapter_h.template b/deps/v8/third_party/inspector_protocol/lib/base_string_adapter_h.template
index 8c28ab033e..6e40de2b55 100644
--- a/deps/v8/third_party/inspector_protocol/lib/base_string_adapter_h.template
+++ b/deps/v8/third_party/inspector_protocol/lib/base_string_adapter_h.template
@@ -7,28 +7,12 @@
#ifndef {{"_".join(config.protocol.namespace)}}_BASE_STRING_ADAPTER_H
#define {{"_".join(config.protocol.namespace)}}_BASE_STRING_ADAPTER_H
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/memory/ref_counted_memory.h"
-#include "{{config.crdtp.dir}}/serializable.h"
-#include "{{config.crdtp.dir}}/protocol_core.h"
+#include "{{config.crdtp.dir}}/chromium/protocol_traits.h"
{% if config.lib.export_header %}
#include "{{config.lib.export_header}}"
{% endif %}
-namespace base {
-class Value;
-}
-
-namespace {{config.crdtp.namespace}} {
-class DeserializerState;
-}
-
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
@@ -36,6 +20,7 @@ namespace {{namespace}} {
class Value;
using String = std::string;
+using Binary = crdtp::Binary;
class {{config.lib.export_macro}} StringUtil {
public:
@@ -51,67 +36,13 @@ class {{config.lib.export_macro}} StringUtil {
}
static const uint16_t* CharactersUTF16(const String& s) { return nullptr; }
static size_t CharacterCount(const String& s) { return s.size(); }
-
- static bool ReadString({{config.crdtp.namespace}}::DeserializerState* state, String* str);
- static void WriteString(const String& str, std::vector<uint8_t>* bytes);
};
-// A read-only sequence of uninterpreted bytes with reference-counted storage.
-class {{config.lib.export_macro}} Binary : public {{config.crdtp.namespace}}::Serializable {
- public:
- Binary(const Binary&);
- Binary();
- ~Binary();
-
- // Implements Serializable.
- void AppendSerialized(std::vector<uint8_t>* out) const override;
-
- const uint8_t* data() const { return bytes_->front(); }
- size_t size() const { return bytes_->size(); }
- scoped_refptr<base::RefCountedMemory> bytes() const { return bytes_; }
-
- String toBase64() const;
-
- static Binary fromBase64(const String& base64, bool* success);
- static Binary fromRefCounted(scoped_refptr<base::RefCountedMemory> memory);
- static Binary fromVector(std::vector<uint8_t> data);
- static Binary fromString(std::string data);
- static Binary fromSpan(const uint8_t* data, size_t size);
-
- private:
- explicit Binary(scoped_refptr<base::RefCountedMemory> bytes);
- scoped_refptr<base::RefCountedMemory> bytes_;
-};
+std::unique_ptr<Value> toProtocolValue(const base::Value& value, int depth);
+base::Value toBaseValue(Value* value, int depth);
-std::unique_ptr<Value> toProtocolValue(const base::Value* value, int depth);
-std::unique_ptr<base::Value> toBaseValue(Value* value, int depth);
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
-namespace {{config.crdtp.namespace}} {
-
-template <>
-struct ProtocolTypeTraits<{{"::".join(config.protocol.namespace)}}::String> {
- static bool Deserialize(DeserializerState* state, {{"::".join(config.protocol.namespace)}}::String* value) {
- return {{"::".join(config.protocol.namespace)}}::StringUtil::ReadString(state, value);
- }
- static void Serialize(const {{"::".join(config.protocol.namespace)}}::String& value, std::vector<uint8_t>* bytes) {
- {{"::".join(config.protocol.namespace)}}::StringUtil::WriteString(value, bytes);
- }
-};
-
-template <>
-struct ProtocolTypeTraits<{{"::".join(config.protocol.namespace)}}::Binary> {
- static bool Deserialize(DeserializerState* state, {{"::".join(config.protocol.namespace)}}::Binary* value);
- static void Serialize(const {{"::".join(config.protocol.namespace)}}::Binary& value, std::vector<uint8_t>* bytes);
-};
-
-template <>
-struct {{config.crdtp.namespace}}::detail::MaybeTypedef<{{"::".join(config.protocol.namespace)}}::Binary> {
- typedef ValueMaybe<{{"::".join(config.protocol.namespace)}}::Binary> type;
-};
-
-} // {{config.crdtp.namespace}}
-
#endif // !defined({{"_".join(config.protocol.namespace)}}_BASE_STRING_ADAPTER_H)