Commit 4a98a260 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol. (V8)

Add Exported::AppendSerialized (consistency with Serialized interface).
Deprecate Exported::writeBinary.

Upstream PRs:
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1958506
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1941035

Change-Id: I50d6db05ea7c1336022b0b63e5ec2c69488ab525
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1958575Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65436}
parent 60f922b4
...@@ -2,7 +2,7 @@ Name: inspector protocol ...@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/ URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0 Version: 0
Revision: f5a3199a3f37c7e48a9ffdbee04aa5c8f38d2889 Revision: 8aa01855258db2ff1324d39a95d8da4dd8cfa868
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -25,25 +25,25 @@ class span { ...@@ -25,25 +25,25 @@ class span {
constexpr span() : data_(nullptr), size_(0) {} constexpr span() : data_(nullptr), size_(0) {}
constexpr span(const T* data, index_type size) : data_(data), size_(size) {} constexpr span(const T* data, index_type size) : data_(data), size_(size) {}
const T* data() const { return data_; } constexpr const T* data() const { return data_; }
const T* begin() const { return data_; } constexpr const T* begin() const { return data_; }
const T* end() const { return data_ + size_; } constexpr const T* end() const { return data_ + size_; }
const T& operator[](index_type idx) const { return data_[idx]; } constexpr const T& operator[](index_type idx) const { return data_[idx]; }
span<T> subspan(index_type offset, index_type count) const { constexpr span<T> subspan(index_type offset, index_type count) const {
return span(data_ + offset, count); return span(data_ + offset, count);
} }
span<T> subspan(index_type offset) const { constexpr span<T> subspan(index_type offset) const {
return span(data_ + offset, size_ - offset); return span(data_ + offset, size_ - offset);
} }
bool empty() const { return size_ == 0; } constexpr bool empty() const { return size_ == 0; }
index_type size() const { return size_; } constexpr index_type size() const { return size_; }
index_type size_bytes() const { return size_ * sizeof(T); } constexpr index_type size_bytes() const { return size_ * sizeof(T); }
private: private:
const T* data_; const T* data_;
...@@ -56,11 +56,11 @@ constexpr span<T> SpanFrom(const std::vector<T>& v) { ...@@ -56,11 +56,11 @@ constexpr span<T> SpanFrom(const std::vector<T>& v) {
} }
template <size_t N> template <size_t N>
span<uint8_t> SpanFrom(const char (&str)[N]) { constexpr span<uint8_t> SpanFrom(const char (&str)[N]) {
return span<uint8_t>(reinterpret_cast<const uint8_t*>(str), N - 1); return span<uint8_t>(reinterpret_cast<const uint8_t*>(str), N - 1);
} }
inline span<uint8_t> SpanFrom(const char* str) { constexpr inline span<uint8_t> SpanFrom(const char* str) {
return str ? span<uint8_t>(reinterpret_cast<const uint8_t*>(str), strlen(str)) return str ? span<uint8_t>(reinterpret_cast<const uint8_t*>(str), strlen(str))
: span<uint8_t>(); : span<uint8_t>();
} }
...@@ -71,13 +71,13 @@ inline span<uint8_t> SpanFrom(const std::string& v) { ...@@ -71,13 +71,13 @@ inline span<uint8_t> SpanFrom(const std::string& v) {
// Less than / equality comparison functions for sorting / searching for byte // Less than / equality comparison functions for sorting / searching for byte
// spans. These are similar to absl::string_view's < and == operators. // spans. These are similar to absl::string_view's < and == operators.
inline bool SpanLessThan(span<uint8_t> x, span<uint8_t> y) noexcept { constexpr inline bool SpanLessThan(span<uint8_t> x, span<uint8_t> y) noexcept {
auto min_size = std::min(x.size(), y.size()); auto min_size = std::min(x.size(), y.size());
const int r = min_size == 0 ? 0 : memcmp(x.data(), y.data(), min_size); const int r = min_size == 0 ? 0 : memcmp(x.data(), y.data(), min_size);
return (r < 0) || (r == 0 && x.size() < y.size()); return (r < 0) || (r == 0 && x.size() < y.size());
} }
inline bool SpanEquals(span<uint8_t> x, span<uint8_t> y) noexcept { constexpr inline bool SpanEquals(span<uint8_t> x, span<uint8_t> y) noexcept {
auto len = x.size(); auto len = x.size();
if (len != y.size()) if (len != y.size())
return false; return false;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <cstdlib> #include <cstdlib>
#include <string> #include <string>
#include <unordered_map>
#include "span.h" #include "span.h"
#include "test_platform.h" #include "test_platform.h"
...@@ -97,4 +98,41 @@ TEST(SpanComparisons, ByteWiseLexicographicalOrder) { ...@@ -97,4 +98,41 @@ TEST(SpanComparisons, ByteWiseLexicographicalOrder) {
EXPECT_FALSE(SpanLessThan(SpanFrom(msg), SpanFrom(lesser_msg))); EXPECT_FALSE(SpanLessThan(SpanFrom(msg), SpanFrom(lesser_msg)));
EXPECT_FALSE(SpanEquals(SpanFrom(msg), SpanFrom(lesser_msg))); EXPECT_FALSE(SpanEquals(SpanFrom(msg), SpanFrom(lesser_msg)));
} }
// TODO(johannes): The following shows how the span can be used in an
// std::unordered_map as a key. Once we have a production usage, we'll move
// SpanHash, SpanEq, SpanHasher into the header.
// A simple hash code, inspired by http://stackoverflow.com/q/1646807.
constexpr inline size_t SpanHash(span<uint8_t> s) noexcept {
size_t hash = 17;
for (uint8_t c : s)
hash = 31 * hash + c;
return hash;
}
// Structs for making std::unordered_map with std::span<uint8_t> keys.
struct SpanEq {
constexpr inline bool operator()(span<uint8_t> l, span<uint8_t> r) const {
return SpanEquals(l, r);
}
};
struct SpanHasher {
constexpr inline size_t operator()(span<uint8_t> s) const {
return SpanHash(s);
}
};
TEST(SpanHasherAndSpanEq, SpanAsKeyInUnorderedMap) {
// A very simple smoke test for unordered_map, storing three key/value pairs.
std::unordered_map<span<uint8_t>, int32_t, SpanHasher, SpanEq> a_map;
a_map[SpanFrom("foo")] = 1;
a_map[SpanFrom("bar")] = 2;
a_map[SpanFrom("baz")] = 3;
EXPECT_EQ(3u, a_map.size());
EXPECT_EQ(1, a_map[SpanFrom("foo")]);
EXPECT_EQ(2, a_map[SpanFrom("bar")]);
EXPECT_EQ(3, a_map[SpanFrom("baz")]);
}
} // namespace v8_crdtp } // namespace v8_crdtp
...@@ -21,7 +21,12 @@ namespace {{namespace}} { ...@@ -21,7 +21,12 @@ namespace {{namespace}} {
class {{config.exported.export_macro}} Exported { class {{config.exported.export_macro}} Exported {
public: public:
virtual {{config.exported.string_out}} toJSONString() const = 0; virtual {{config.exported.string_out}} toJSONString() const = 0;
V8_DEPRECATE_SOON("Use AppendSerialized instead.")
virtual void writeBinary(std::vector<uint8_t>* out) const = 0; virtual void writeBinary(std::vector<uint8_t>* out) const = 0;
virtual void AppendSerialized(std::vector<uint8_t>* out) const = 0;
virtual ~Exported() { } virtual ~Exported() { }
}; };
#endif // !defined({{"_".join(config.protocol.namespace)}}_exported_api_h) #endif // !defined({{"_".join(config.protocol.namespace)}}_exported_api_h)
......
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