Commit 3e177c79 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol (V8)

New revision: 3b0551d3904f7fc067e78905ce697002187fa7a5

Upstream reviews:
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1972474
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1967550

Change-Id: Ie9cec5faf410cc80ddb178da30cda66d801196f3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1972404Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65509}
parent 75fa5d42
......@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 726836d7317a4031f48af9960bab51d7a2ab2867
Revision: 3b0551d3904f7fc067e78905ce697002187fa7a5
License: BSD
License File: LICENSE
Security Critical: no
......
......@@ -10,7 +10,6 @@
#include <vector>
#include "cbor.h"
#include "glue.h"
#include "serializable.h"
#include "span.h"
namespace v8_crdtp {
......@@ -39,22 +38,18 @@ struct SerializerTraits {
// |Serializable| (defined in serializable.h) already knows how to serialize
// to CBOR, so we can just delegate. This covers domain specific types,
// protocol::Binary, etc.
static void Serialize(const Serializable& value, std::vector<uint8_t>* out) {
// However, we use duck-typing here, because Exported, which is part of the V8
// headers also comes with AppendSerialized, and logically it's the same type,
// but it lives in a different namespace (v8_inspector::protocol::Exported).
template <
typename LikeSerializable,
typename std::enable_if_t<std::is_member_pointer<decltype(
&LikeSerializable::AppendSerialized)>{},
int> = 0>
static void Serialize(const LikeSerializable& value,
std::vector<uint8_t>* out) {
value.AppendSerialized(out);
}
// This method covers the Exported types, e.g. from V8 into Chromium.
// TODO(johannes): Change Exported signature to AppendSerialized
// for consistency with Serializable; this is why we explicitly
// disable this template for Serializable here.
template <typename Exported,
typename std::enable_if_t<
std::is_member_pointer<decltype(&Exported::writeBinary)>{} &&
!std::is_same<Serializable, T>{},
int> = 0>
static void Serialize(const Exported& value, std::vector<uint8_t>* out) {
value.writeBinary(out);
}
};
// This covers std::string, which is assumed to be UTF-8.
......
......@@ -5,6 +5,7 @@
#include "serializer_traits.h"
#include <array>
#include "serializable.h"
#include "test_platform.h"
// The purpose of this test is to ensure that the
......@@ -134,7 +135,7 @@ TEST(SerializerTraits, UTF8String) {
// https://cs.chromium.org/chromium/src/out/Debug/gen/v8/include/inspector/Debugger.h).
struct Exported {
std::string msg;
void writeBinary(std::vector<uint8_t>* out) {
void AppendSerialized(std::vector<uint8_t>* out) const {
cbor::EncodeString8(SpanFrom(msg), out);
}
};
......@@ -144,7 +145,7 @@ TEST(SerializerTraits, Exported) {
exported.msg = "Hello, world.";
std::vector<uint8_t> out;
SerializerTraits<std::string>::Serialize(exported.msg, &out);
SerializerTraits<Exported>::Serialize(exported, &out);
std::vector<uint8_t> expected;
cbor::EncodeString8(SpanFrom(exported.msg), &expected);
......
......@@ -50,11 +50,6 @@ class span {
index_type size_;
};
template <typename T>
constexpr span<T> SpanFrom(const std::vector<T>& v) {
return span<T>(v.data(), v.size());
}
template <size_t N>
constexpr span<uint8_t> SpanFrom(const char (&str)[N]) {
return span<uint8_t>(reinterpret_cast<const uint8_t*>(str), N - 1);
......@@ -69,6 +64,16 @@ inline span<uint8_t> SpanFrom(const std::string& v) {
return span<uint8_t>(reinterpret_cast<const uint8_t*>(v.data()), v.size());
}
// This SpanFrom routine works for std::vector<uint8_t> and
// std::vector<uint16_t>, but also for base::span<const uint8_t> in Chromium.
template <typename C,
typename = std::enable_if_t<
std::is_unsigned<typename C::value_type>{} &&
std::is_member_function_pointer<decltype(&C::size)>{}>>
inline span<typename C::value_type> SpanFrom(const C& v) {
return span<typename C::value_type>(v.data(), v.size());
}
// Less than / equality comparison functions for sorting / searching for byte
// spans. These are similar to absl::string_view's < and == operators.
constexpr inline bool SpanLessThan(span<uint8_t> x, span<uint8_t> y) noexcept {
......
......@@ -77,6 +77,16 @@ TEST(SpanFromTest, FromConstCharAndLiteral) {
EXPECT_EQ(3u, SpanFrom("foo").size());
}
TEST(SpanFromTest, FromVectorUint8AndUint16) {
std::vector<uint8_t> foo = {'f', 'o', 'o'};
span<uint8_t> foo_span = SpanFrom(foo);
EXPECT_EQ(foo.size(), foo_span.size());
std::vector<uint16_t> bar = {0xff, 0xef, 0xeb};
span<uint16_t> bar_span = SpanFrom(bar);
EXPECT_EQ(bar.size(), bar_span.size());
}
TEST(SpanComparisons, ByteWiseLexicographicalOrder) {
// Compare the empty span.
EXPECT_FALSE(SpanLessThan(span<uint8_t>(), span<uint8_t>()));
......
......@@ -34,9 +34,11 @@ public:
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->writeBinary(output);
m_exported->AppendSerialized(output);
}
std::unique_ptr<Value> clone() const override {
return std::unique_ptr<Value>(new ImportedValue(m_exported));
}
......@@ -72,11 +74,6 @@ struct ValueConversions<{{"::".join(config.imported.namespace)}}::{{domain.domai
{
return ImportedValue::fromExported(exported);
}
static std::unique_ptr<protocol::Value> toValue(const std::unique_ptr<{{"::".join(config.imported.namespace)}}::{{domain.domain}}::API::{{type.id}}>& value)
{
return toValue(value.get());
}
};
{% endfor %}
......
......@@ -122,7 +122,7 @@ std::unique_ptr<{{type.id}}> {{type.id}}::clone() const
void {{type.id}}::writeBinary(std::vector<uint8_t>* out) const
{
toValue()->AppendSerialized(out);
AppendSerialized(out);
}
// static
......
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