From f938b792ab663dc4227bb0aff71965bf82d2a1b6 Mon Sep 17 00:00:00 2001 From: Andrey Kosyakov Date: Mon, 19 Sep 2022 12:21:36 -0700 Subject: [PATCH] Roll inspector_protocol 6901e556365f74a41bb85b62a70d444d87db639a Change-Id: Ia8d92151114c674b581ec2fa2b4e3297e9c7cf6f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3905927 Commit-Queue: Yang Guo Reviewed-by: Yang Guo Auto-Submit: Andrey Kosyakov Cr-Commit-Position: refs/heads/main@{#83331} --- third_party/inspector_protocol/README.v8 | 2 +- .../inspector_protocol/code_generator.py | 68 +++++++++++++------ third_party/inspector_protocol/crdtp/cbor.cc | 2 +- .../inspector_protocol/crdtp/cbor_test.cc | 9 +-- .../inspector_protocol/crdtp/dispatch_test.cc | 4 +- .../inspector_protocol/crdtp/protocol_core.h | 1 + 6 files changed, 56 insertions(+), 30 deletions(-) diff --git a/third_party/inspector_protocol/README.v8 b/third_party/inspector_protocol/README.v8 index 8e9cd9c127..d1e8d01b46 100644 --- a/third_party/inspector_protocol/README.v8 +++ b/third_party/inspector_protocol/README.v8 @@ -2,7 +2,7 @@ Name: inspector protocol Short Name: inspector_protocol URL: https://chromium.googlesource.com/deps/inspector_protocol/ Version: 0 -Revision: 134539780e606a77d660d58bf95b5ab55875bc3c +Revision: 6901e556365f74a41bb85b62a70d444d87db639a License: BSD License File: LICENSE Security Critical: no diff --git a/third_party/inspector_protocol/code_generator.py b/third_party/inspector_protocol/code_generator.py index c3768b8d3e..2e4adcdf4a 100755 --- a/third_party/inspector_protocol/code_generator.py +++ b/third_party/inspector_protocol/code_generator.py @@ -279,15 +279,16 @@ def create_any_type_definition(): def create_string_type_definition(): # pylint: disable=W0622 return { - "return_type": "String", - "pass_type": "const String&", - "to_pass_type": "%s", - "to_raw_type": "%s", - "to_rvalue": "%s", - "type": "String", - "raw_type": "String", - "raw_pass_type": "const String&", - "raw_return_type": "String", + "return_type": "String", + "pass_type": "const String&", + "to_pass_type": "%s", + "to_raw_type": "%s", + "to_rvalue": "%s", + "type": "String", + "raw_type": "String", + "raw_pass_type": "const String&", + "raw_return_type": "String", + "is_primitive": True } @@ -324,19 +325,19 @@ def create_primitive_type_definition(type): "boolean": "TypeBoolean", } return { - "return_type": typedefs[type], - "pass_type": typedefs[type], - "to_pass_type": "%s", - "to_raw_type": "%s", - "to_rvalue": "%s", - "type": typedefs[type], - "raw_type": typedefs[type], - "raw_pass_type": typedefs[type], - "raw_return_type": typedefs[type], - "default_value": defaults[type] + "return_type": typedefs[type], + "pass_type": typedefs[type], + "to_pass_type": "%s", + "to_raw_type": "%s", + "to_rvalue": "%s", + "type": typedefs[type], + "raw_type": typedefs[type], + "raw_pass_type": typedefs[type], + "raw_return_type": typedefs[type], + "default_value": defaults[type], + "is_primitive": True } - def wrap_array_definition(type): # pylint: disable=W0622 return { @@ -424,6 +425,22 @@ class Protocol(object): refs.add(json["$ref"]) return refs + def check_if_dependency_declared(self, domain, refs): + dependencies = domain.get('dependencies', set()) + for ref in refs: + type_definition = self.type_definitions[ref] + if type_definition.get('is_primitive', False): + continue + domain_match = re.match(r'^(.*)[.]', ref) + if domain_match: + referenced_domain_name = domain_match.group(1) + if referenced_domain_name != domain[ + 'domain'] and not referenced_domain_name in dependencies: + sys.stderr.write(( + "Domains [%s] uses type [%s] from domain [%s], but did not declare the dependency\n\n" + ) % (domain["domain"], ref, referenced_domain_name)) + exit(1) + def generate_used_types(self): all_refs = set() for domain in self.json_api["domains"]: @@ -431,11 +448,18 @@ class Protocol(object): if "commands" in domain: for command in domain["commands"]: if self.generate_command(domain_name, command["name"]): - all_refs |= self.all_references(command) + all_refs_command = self.all_references(command) + # If the command has a redirect, it is as if it didn't exist on this domain. + if not command.get('redirect', False): + self.check_if_dependency_declared(domain, all_refs_command) + all_refs |= all_refs_command + if "events" in domain: for event in domain["events"]: if self.generate_event(domain_name, event["name"]): - all_refs |= self.all_references(event) + all_refs_event = self.all_references(event) + self.check_if_dependency_declared(domain, all_refs_event) + all_refs |= all_refs_event dependencies = self.generate_type_dependencies() queue = set(all_refs) diff --git a/third_party/inspector_protocol/crdtp/cbor.cc b/third_party/inspector_protocol/crdtp/cbor.cc index b2d5c2e103..a7bb3e9e5e 100644 --- a/third_party/inspector_protocol/crdtp/cbor.cc +++ b/third_party/inspector_protocol/crdtp/cbor.cc @@ -344,7 +344,7 @@ void EncodeDouble(double value, std::vector* out) { void EnvelopeEncoder::EncodeStart(std::vector* out) { assert(byte_size_pos_ == 0); out->push_back(kInitialByteForEnvelope); - // TODO(caseq): encode tag as an additional byte here. + out->push_back(kCBOREnvelopeTag); out->push_back(kInitialByteFor32BitLengthByteString); byte_size_pos_ = out->size(); out->resize(out->size() + sizeof(uint32_t)); diff --git a/third_party/inspector_protocol/crdtp/cbor_test.cc b/third_party/inspector_protocol/crdtp/cbor_test.cc index 3fcf702eb1..f4bf82e786 100644 --- a/third_party/inspector_protocol/crdtp/cbor_test.cc +++ b/third_party/inspector_protocol/crdtp/cbor_test.cc @@ -727,9 +727,9 @@ TEST(JsonCborRoundtrip, EncodingDecoding) { span ascii_in = SpanFrom(json); json::ParseJSON(ascii_in, encoder.get()); std::vector expected = { - 0xd8, // envelope - 0x5a, // byte string with 32 bit length - 0, 0, 0, 94, // length is 94 bytes + 0xd8, 0x18, // envelope + 0x5a, // byte string with 32 bit length + 0, 0, 0, 95, // length is 95 bytes }; expected.push_back(0xbf); // indef length map start EncodeString8(SpanFrom("string"), &expected); @@ -752,7 +752,8 @@ TEST(JsonCborRoundtrip, EncodingDecoding) { EncodeString8(SpanFrom("null"), &expected); expected.push_back(7 << 5 | 22); // RFC 7049 Section 2.3, Table 2: null EncodeString8(SpanFrom("array"), &expected); - expected.push_back(0xd8); // envelope + expected.push_back(0xd8); // envelope (tag first byte) + expected.push_back(0x18); // envelope (tag second byte) expected.push_back(0x5a); // byte string with 32 bit length // the length is 5 bytes (that's up to end indef length array below). for (uint8_t ch : std::array{{0, 0, 0, 5}}) diff --git a/third_party/inspector_protocol/crdtp/dispatch_test.cc b/third_party/inspector_protocol/crdtp/dispatch_test.cc index 8eacdee93e..adf9f1865f 100644 --- a/third_party/inspector_protocol/crdtp/dispatch_test.cc +++ b/third_party/inspector_protocol/crdtp/dispatch_test.cc @@ -267,8 +267,8 @@ TEST(DispatchableTest, FaultyCBORTrailingJunk) { Dispatchable dispatchable(SpanFrom(cbor)); EXPECT_FALSE(dispatchable.ok()); EXPECT_EQ(DispatchCode::PARSE_ERROR, dispatchable.DispatchError().Code()); - EXPECT_EQ(56u, trailing_junk_pos); - EXPECT_EQ("CBOR: trailing junk at position 56", + EXPECT_EQ(57u, trailing_junk_pos); + EXPECT_EQ("CBOR: trailing junk at position 57", dispatchable.DispatchError().Message()); } diff --git a/third_party/inspector_protocol/crdtp/protocol_core.h b/third_party/inspector_protocol/crdtp/protocol_core.h index f61bb5783b..22cdc98558 100644 --- a/third_party/inspector_protocol/crdtp/protocol_core.h +++ b/third_party/inspector_protocol/crdtp/protocol_core.h @@ -9,6 +9,7 @@ #include #include +#include #include #include "cbor.h"