Commit 844cf4d8 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector protocol (v8)

New rev: a14dad30f0e5b0fc05911856d5a20b1ffe89fd9b

Change-Id: I92a70bb8e5fef13e7422d609d3899ea1092def8c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1847785
Auto-Submit: Johannes Henkel <johannes@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64257}
parent 72766829
...@@ -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: d114a62e144cdfdae697fe0af6581ce39a31af37 Revision: a14dad30f0e5b0fc05911856d5a20b1ffe89fd9b
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -58,10 +58,9 @@ class ValueMaybe { ...@@ -58,10 +58,9 @@ class ValueMaybe {
return is_just_ ? value_ : default_value; return is_just_ ? value_ : default_value;
} }
bool isJust() const { return is_just_; } bool isJust() const { return is_just_; }
// TODO(johannes): |is_just_| isn't reset by this operation -
// introduce && to ensure avoiding continued usage of |this|?
T takeJust() { T takeJust() {
assert(is_just_); assert(is_just_);
is_just_ = false;
return std::move(value_); return std::move(value_);
} }
......
...@@ -43,6 +43,9 @@ def read_config(): ...@@ -43,6 +43,9 @@ def read_config():
items = [(k, os.path.join(output_base, v) if k == "output" else v) items = [(k, os.path.join(output_base, v) if k == "output" else v)
for (k, v) in items] for (k, v) in items]
keys, values = list(zip(*items)) keys, values = list(zip(*items))
# 'async' is a keyword since Python 3.7.
# Avoid namedtuple(rename=True) for compatibility with Python 2.X.
keys = tuple('async_' if k == 'async' else k for k in keys)
return collections.namedtuple('X', keys)(*values) return collections.namedtuple('X', keys)(*values)
return json.loads(data, object_hook=json_object_hook) return json.loads(data, object_hook=json_object_hook)
...@@ -555,7 +558,7 @@ class Protocol(object): ...@@ -555,7 +558,7 @@ class Protocol(object):
if not self.config.protocol.options: if not self.config.protocol.options:
return False return False
return self.check_options(self.config.protocol.options, domain, command, return self.check_options(self.config.protocol.options, domain, command,
"async", None, False) "async_", None, False)
def is_exported(self, domain, name): def is_exported(self, domain, name):
if not self.config.protocol.options: if not self.config.protocol.options:
......
...@@ -85,8 +85,25 @@ std::string Status::ToASCIIString() const { ...@@ -85,8 +85,25 @@ std::string Status::ToASCIIString() const {
return ToASCIIString("CBOR: map start expected"); return ToASCIIString("CBOR: map start expected");
case Error::CBOR_MAP_STOP_EXPECTED: case Error::CBOR_MAP_STOP_EXPECTED:
return ToASCIIString("CBOR: map stop expected"); return ToASCIIString("CBOR: map stop expected");
case Error::CBOR_ARRAY_START_EXPECTED:
return ToASCIIString("CBOR: array start expected");
case Error::CBOR_ENVELOPE_SIZE_LIMIT_EXCEEDED: case Error::CBOR_ENVELOPE_SIZE_LIMIT_EXCEEDED:
return ToASCIIString("CBOR: envelope size limit exceeded"); return ToASCIIString("CBOR: envelope size limit exceeded");
case Error::BINDINGS_MANDATORY_FIELD_MISSING:
return ToASCIIString("BINDINGS: mandatory field missing");
case Error::BINDINGS_BOOL_VALUE_EXPECTED:
return ToASCIIString("BINDINGS: bool value expected");
case Error::BINDINGS_INT32_VALUE_EXPECTED:
return ToASCIIString("BINDINGS: int32 value expected");
case Error::BINDINGS_DOUBLE_VALUE_EXPECTED:
return ToASCIIString("BINDINGS: double value expected");
case Error::BINDINGS_STRING_VALUE_EXPECTED:
return ToASCIIString("BINDINGS: string value expected");
case Error::BINDINGS_STRING8_VALUE_EXPECTED:
return ToASCIIString("BINDINGS: string8 value expected");
case Error::BINDINGS_BINARY_VALUE_EXPECTED:
return ToASCIIString("BINDINGS: binary value expected");
} }
// Some compilers can't figure out that we can't get here. // Some compilers can't figure out that we can't get here.
return "INVALID ERROR CODE"; return "INVALID ERROR CODE";
...@@ -707,6 +724,12 @@ span<uint8_t> CBORTokenizer::GetBinary() const { ...@@ -707,6 +724,12 @@ span<uint8_t> CBORTokenizer::GetBinary() const {
return bytes_.subspan(status_.pos + (token_byte_length_ - length), length); return bytes_.subspan(status_.pos + (token_byte_length_ - length), length);
} }
span<uint8_t> CBORTokenizer::GetEnvelope() const {
assert(token_tag_ == CBORTokenTag::ENVELOPE);
auto length = static_cast<size_t>(token_start_internal_value_);
return bytes_.subspan(status_.pos, length + kEncodedEnvelopeHeaderSize);
}
span<uint8_t> CBORTokenizer::GetEnvelopeContents() const { span<uint8_t> CBORTokenizer::GetEnvelopeContents() const {
assert(token_tag_ == CBORTokenTag::ENVELOPE); assert(token_tag_ == CBORTokenTag::ENVELOPE);
auto length = static_cast<size_t>(token_start_internal_value_); auto length = static_cast<size_t>(token_start_internal_value_);
......
...@@ -141,7 +141,16 @@ enum class Error { ...@@ -141,7 +141,16 @@ enum class Error {
CBOR_TRAILING_JUNK = 0x1e, CBOR_TRAILING_JUNK = 0x1e,
CBOR_MAP_START_EXPECTED = 0x1f, CBOR_MAP_START_EXPECTED = 0x1f,
CBOR_MAP_STOP_EXPECTED = 0x20, CBOR_MAP_STOP_EXPECTED = 0x20,
CBOR_ENVELOPE_SIZE_LIMIT_EXCEEDED = 0x21, CBOR_ARRAY_START_EXPECTED = 0x21,
CBOR_ENVELOPE_SIZE_LIMIT_EXCEEDED = 0x22,
BINDINGS_MANDATORY_FIELD_MISSING = 0x23,
BINDINGS_BOOL_VALUE_EXPECTED = 0x24,
BINDINGS_INT32_VALUE_EXPECTED = 0x25,
BINDINGS_DOUBLE_VALUE_EXPECTED = 0x26,
BINDINGS_STRING_VALUE_EXPECTED = 0x27,
BINDINGS_STRING8_VALUE_EXPECTED = 0x28,
BINDINGS_BINARY_VALUE_EXPECTED = 0x29,
}; };
// A status value with position that can be copied. The default status // A status value with position that can be copied. The default status
...@@ -419,6 +428,17 @@ class CBORTokenizer { ...@@ -419,6 +428,17 @@ class CBORTokenizer {
span<uint8_t> GetBinary() const; span<uint8_t> GetBinary() const;
// To be called only if ::TokenTag() == CBORTokenTag::ENVELOPE. // To be called only if ::TokenTag() == CBORTokenTag::ENVELOPE.
// Returns the envelope including its payload; message which
// can be passed to the CBORTokenizer constructor, which will
// then see the envelope token first (looking at it a second time,
// basically).
span<uint8_t> GetEnvelope() const;
// To be called only if ::TokenTag() == CBORTokenTag::ENVELOPE.
// Returns only the payload inside the envelope, e.g., a map
// or an array. This is not a complete message by our
// IsCBORMessage definition, since it doesn't include the
// enclosing envelope (the header, basically).
span<uint8_t> GetEnvelopeContents() const; span<uint8_t> GetEnvelopeContents() const;
private: private:
......
...@@ -688,6 +688,71 @@ TEST(EncodeDecodeDoubleTest, RoundtripsAdditionalExamples) { ...@@ -688,6 +688,71 @@ TEST(EncodeDecodeDoubleTest, RoundtripsAdditionalExamples) {
} }
} }
TEST(EncodeDecodeEnvelopesTest, MessageWithNestingAndEnvelopeContentsAccess) {
// This encodes and decodes the following message, which has some nesting
// and therefore envelopes.
// { "inner": { "foo" : "bar" } }
// The decoding is done with the Tokenizer,
// and we test both ::GetEnvelopeContents and GetEnvelope here.
std::vector<uint8_t> message;
EnvelopeEncoder envelope;
envelope.EncodeStart(&message);
size_t pos_after_header = message.size();
message.push_back(EncodeIndefiniteLengthMapStart());
EncodeString8(SpanFrom("inner"), &message);
size_t pos_inside_inner = message.size();
EnvelopeEncoder inner_envelope;
inner_envelope.EncodeStart(&message);
size_t pos_inside_inner_contents = message.size();
message.push_back(EncodeIndefiniteLengthMapStart());
EncodeString8(SpanFrom("foo"), &message);
EncodeString8(SpanFrom("bar"), &message);
message.push_back(EncodeStop());
size_t pos_after_inner = message.size();
inner_envelope.EncodeStop(&message);
message.push_back(EncodeStop());
envelope.EncodeStop(&message);
CBORTokenizer tokenizer(SpanFrom(message));
ASSERT_EQ(CBORTokenTag::ENVELOPE, tokenizer.TokenTag());
EXPECT_EQ(message.size(), tokenizer.GetEnvelope().size());
EXPECT_EQ(message.data(), tokenizer.GetEnvelope().data());
EXPECT_EQ(message.data() + pos_after_header,
tokenizer.GetEnvelopeContents().data());
EXPECT_EQ(message.size() - pos_after_header,
tokenizer.GetEnvelopeContents().size());
tokenizer.EnterEnvelope();
ASSERT_EQ(CBORTokenTag::MAP_START, tokenizer.TokenTag());
tokenizer.Next();
ASSERT_EQ(CBORTokenTag::STRING8, tokenizer.TokenTag());
EXPECT_EQ("inner", std::string(tokenizer.GetString8().begin(),
tokenizer.GetString8().end()));
tokenizer.Next();
ASSERT_EQ(CBORTokenTag::ENVELOPE, tokenizer.TokenTag());
EXPECT_EQ(message.data() + pos_inside_inner, tokenizer.GetEnvelope().data());
EXPECT_EQ(pos_after_inner - pos_inside_inner, tokenizer.GetEnvelope().size());
EXPECT_EQ(message.data() + pos_inside_inner_contents,
tokenizer.GetEnvelopeContents().data());
EXPECT_EQ(pos_after_inner - pos_inside_inner_contents,
tokenizer.GetEnvelopeContents().size());
tokenizer.EnterEnvelope();
ASSERT_EQ(CBORTokenTag::MAP_START, tokenizer.TokenTag());
tokenizer.Next();
ASSERT_EQ(CBORTokenTag::STRING8, tokenizer.TokenTag());
EXPECT_EQ("foo", std::string(tokenizer.GetString8().begin(),
tokenizer.GetString8().end()));
tokenizer.Next();
ASSERT_EQ(CBORTokenTag::STRING8, tokenizer.TokenTag());
EXPECT_EQ("bar", std::string(tokenizer.GetString8().begin(),
tokenizer.GetString8().end()));
tokenizer.Next();
ASSERT_EQ(CBORTokenTag::STOP, tokenizer.TokenTag());
tokenizer.Next();
ASSERT_EQ(CBORTokenTag::STOP, tokenizer.TokenTag());
tokenizer.Next();
ASSERT_EQ(CBORTokenTag::DONE, tokenizer.TokenTag());
}
// ============================================================================= // =============================================================================
// cbor::NewCBOREncoder - for encoding from a streaming parser // cbor::NewCBOREncoder - for encoding from a streaming parser
// ============================================================================= // =============================================================================
......
...@@ -302,15 +302,21 @@ void UberDispatcher::dispatch(int callId, const String& in_method, std::unique_p ...@@ -302,15 +302,21 @@ void UberDispatcher::dispatch(int callId, const String& in_method, std::unique_p
UberDispatcher::~UberDispatcher() = default; UberDispatcher::~UberDispatcher() = default;
// static // static
std::unique_ptr<InternalResponse> InternalResponse::createResponse(int callId, std::unique_ptr<Serializable> params) std::unique_ptr<Serializable> InternalResponse::createResponse(int callId, std::unique_ptr<Serializable> params)
{ {
return std::unique_ptr<InternalResponse>(new InternalResponse(callId, String(), std::move(params))); return std::unique_ptr<Serializable>(new InternalResponse(callId, String(), std::move(params)));
} }
// static // static
std::unique_ptr<InternalResponse> InternalResponse::createNotification(const String& notification, std::unique_ptr<Serializable> params) std::unique_ptr<Serializable> InternalResponse::createNotification(const String& notification, std::unique_ptr<Serializable> params)
{ {
return std::unique_ptr<InternalResponse>(new InternalResponse(0, notification, std::move(params))); return std::unique_ptr<Serializable>(new InternalResponse(0, notification, std::move(params)));
}
// static
std::unique_ptr<Serializable> InternalResponse::createErrorResponse(int callId, DispatchResponse::ErrorCode code, const String& message)
{
return ProtocolError::createErrorResponse(callId, code, message, nullptr);
} }
String InternalResponse::serializeToJSON() String InternalResponse::serializeToJSON()
......
...@@ -128,8 +128,9 @@ private: ...@@ -128,8 +128,9 @@ private:
class InternalResponse : public Serializable { class InternalResponse : public Serializable {
PROTOCOL_DISALLOW_COPY(InternalResponse); PROTOCOL_DISALLOW_COPY(InternalResponse);
public: public:
static std::unique_ptr<InternalResponse> createResponse(int callId, std::unique_ptr<Serializable> params); static std::unique_ptr<Serializable> createResponse(int callId, std::unique_ptr<Serializable> params);
static std::unique_ptr<InternalResponse> createNotification(const String& notification, std::unique_ptr<Serializable> params = nullptr); static std::unique_ptr<Serializable> createNotification(const String& notification, std::unique_ptr<Serializable> params = nullptr);
static std::unique_ptr<Serializable> createErrorResponse(int callId, DispatchResponse::ErrorCode code, const String& message);
String serializeToJSON() override; String serializeToJSON() override;
std::vector<uint8_t> serializeToBinary() override; std::vector<uint8_t> serializeToBinary() override;
......
...@@ -385,7 +385,6 @@ void DispatcherImpl::{{command.name}}(int callId, const String& method, const Pr ...@@ -385,7 +385,6 @@ void DispatcherImpl::{{command.name}}(int callId, const String& method, const Pr
{% endif %} {% endif %}
return; return;
{% else %} {% else %}
std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
std::unique_ptr<{{command_name_title}}CallbackImpl> callback(new {{command.name | to_title_case}}CallbackImpl(weakPtr(), callId, method, message)); std::unique_ptr<{{command_name_title}}CallbackImpl> callback(new {{command.name | to_title_case}}CallbackImpl(weakPtr(), callId, method, message));
m_backend->{{command.name | to_method_case}}( m_backend->{{command.name | to_method_case}}(
{%- for property in command.parameters -%} {%- for property in command.parameters -%}
......
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