From ec4168668bd251eaff40e8f0604626c0e0a74976 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 2 Jul 2025 21:57:10 +0200 Subject: [PATCH] tools: update inspector_protocol to 69d69dd PR-URL: https://github.com/nodejs/node/pull/58900 Reviewed-By: Chengzhong Wu Reviewed-By: Luigi Pinca --- deps/inspector_protocol/BUILD.gn | 101 +++++++++--- deps/inspector_protocol/LICENSE | 2 +- deps/inspector_protocol/README.node | 2 +- deps/inspector_protocol/code_generator.py | 8 +- deps/inspector_protocol/crdtp/README.md | 4 +- deps/inspector_protocol/crdtp/cbor.h | 3 +- .../inspector_protocol/crdtp/dispatch_test.cc | 20 ++- .../crdtp/frontend_channel.h | 2 +- deps/inspector_protocol/crdtp/json_test.cc | 19 ++- deps/inspector_protocol/crdtp/maybe.h | 154 ------------------ deps/inspector_protocol/crdtp/maybe_test.cc | 44 ----- .../inspector_protocol/crdtp/protocol_core.cc | 6 +- deps/inspector_protocol/crdtp/protocol_core.h | 39 ++--- .../crdtp/protocol_core_test.cc | 12 +- .../inspector_protocol/inspector_protocol.gni | 14 +- .../inspector_protocol/lib/Forward_h.template | 6 - .../lib/Values_cpp.template | 3 +- .../templates/TypeBuilder_cpp.template | 8 +- .../templates/TypeBuilder_h.template | 17 +- src/inspector/node_string.h | 6 - 20 files changed, 161 insertions(+), 309 deletions(-) delete mode 100644 deps/inspector_protocol/crdtp/maybe.h delete mode 100644 deps/inspector_protocol/crdtp/maybe_test.cc diff --git a/deps/inspector_protocol/BUILD.gn b/deps/inspector_protocol/BUILD.gn index 974471bf27..ee03d87826 100644 --- a/deps/inspector_protocol/BUILD.gn +++ b/deps/inspector_protocol/BUILD.gn @@ -1,34 +1,95 @@ -# Copyright 2019 the V8 project authors. All rights reserved. +# Copyright 2018 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -static_library("encoding") { +# This BUILD.gn file is specific to the standalone project. Do not +# copy this downstream. + +import("//testing/test.gni") + +static_library("crdtp") { sources = [ - "encoding/encoding.cc", - "encoding/encoding.h", + "crdtp/cbor.cc", + "crdtp/cbor.h", + "crdtp/dispatch.cc", + "crdtp/dispatch.h", + "crdtp/error_support.cc", + "crdtp/error_support.h", + "crdtp/export.h", + "crdtp/find_by_first.h", + "crdtp/frontend_channel.h", + "crdtp/glue.h", + "crdtp/json.cc", + "crdtp/json.h", + "crdtp/parser_handler.h", + "crdtp/protocol_core.cc", + "crdtp/protocol_core.h", + "crdtp/serializable.cc", + "crdtp/serializable.h", + "crdtp/span.cc", + "crdtp/span.h", + "crdtp/status.cc", + "crdtp/status.h", + ] + deps = [ ":crdtp_platform" ] +} + +# A small adapter library which only :crdtp may depend on. +static_library("crdtp_platform") { + sources = [ + "crdtp/json_platform.cc", + "crdtp/json_platform.h", ] } -# encoding_test is part of the unittests, defined in -# test/unittests/BUILD.gn. +# In this (upstream) standalone package, we declare crdtp_test, and a +# few minimal files in testing (accessed via test_platform.{h,cc}) to +# make it look like Chromium's testing package. In Chromium, +# we run these tests as part of the content_unittests, declared in +# content/test/BUILD.gn, and in V8, we run them via unittests, declared +# in test/unittests/BUILD.gn. -import("../../gni/v8.gni") - -v8_source_set("encoding_test") { +test("crdtp_test") { sources = [ - "encoding/encoding_test.cc", - "encoding/encoding_test_helper.h", - ] - configs = [ - "../..:external_config", - "../..:internal_config_base", + "crdtp/cbor_test.cc", + "crdtp/dispatch_test.cc", + "crdtp/error_support_test.cc", + "crdtp/find_by_first_test.cc", + "crdtp/json_test.cc", + "crdtp/protocol_core_test.cc", + "crdtp/serializable_test.cc", + "crdtp/span_test.cc", + "crdtp/status_test.cc", + "crdtp/status_test_support.cc", + "crdtp/status_test_support.h", + "crdtp/test_string_traits.cc", + "crdtp/test_string_traits.h", ] + include_dirs = [ "." ] deps = [ - ":encoding", - "../..:v8_libbase", - "../../src/inspector:inspector_string_conversions", - "//testing/gmock", - "//testing/gtest", + ":crdtp", + ":crdtp_test_platform", + ] +} + +# A small adapter library which only :crdtp_test may depend on. +static_library("crdtp_test_platform") { + sources = [ + "crdtp/test_platform.cc", + "crdtp/test_platform.h", ] testonly = true + include_dirs = [ "." ] + public_deps = [ + "//base", + "//testing/gmock", + "//testing/gtest", + "//testing/gtest:gtest_main", + ] +} + +# A command line utility for converting between JSON and CBOR. +executable("transcode") { + sources = [ "crdtp/transcode.cc" ] + deps = [ ":crdtp" ] } diff --git a/deps/inspector_protocol/LICENSE b/deps/inspector_protocol/LICENSE index 800468e576..4d9a34a914 100644 --- a/deps/inspector_protocol/LICENSE +++ b/deps/inspector_protocol/LICENSE @@ -1,4 +1,4 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. +// Copyright 2016 The Chromium Authors. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are diff --git a/deps/inspector_protocol/README.node b/deps/inspector_protocol/README.node index 5d5b486b51..af4618cd61 100644 --- a/deps/inspector_protocol/README.node +++ b/deps/inspector_protocol/README.node @@ -2,7 +2,7 @@ Name: inspector protocol Short Name: inspector_protocol URL: https://chromium.googlesource.com/deps/inspector_protocol/ Version: 0 -Revision: 64cc2301620c04f0fe0313ae94a9319f003603cf +Revision: 69d69ddf3aa698b171886551a4a672c5af1ad902 License: BSD License File: LICENSE Security Critical: no diff --git a/deps/inspector_protocol/code_generator.py b/deps/inspector_protocol/code_generator.py index 53beb86125..ce989e4869 100755 --- a/deps/inspector_protocol/code_generator.py +++ b/deps/inspector_protocol/code_generator.py @@ -147,7 +147,7 @@ def dash_to_camelcase(word): def to_snake_case(name): name = re.sub(r"([A-Z]{2,})([A-Z][a-z])", r"\1_\2", name) - return re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", name, sys.maxsize).lower() + return re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", name, count=sys.maxsize).lower() def to_method_case(config, name): @@ -542,6 +542,12 @@ class Protocol(object): return wrap_array_definition(self.resolve_type(prop["items"])) return self.type_definitions[prop["type"]] + def optional_type(self, prop): + type = self.resolve_type(prop) + template = ("std::optional<{}>" if type.get('is_primitive', False) + else "std::unique_ptr<{}>") + return template.format(type.get("raw_type")) + def generate_command(self, domain, command): if not self.config.protocol.options: return domain in self.generate_domains diff --git a/deps/inspector_protocol/crdtp/README.md b/deps/inspector_protocol/crdtp/README.md index a9bbc9e886..a3bc75943f 100644 --- a/deps/inspector_protocol/crdtp/README.md +++ b/deps/inspector_protocol/crdtp/README.md @@ -51,10 +51,10 @@ to fetch the package (and dependencies) and build and run the tests: ninja -C out/Release crdtp_test out/Release/crdtp_test -You'll probably also need to install g++, since Clang uses this to find the +You'll probably also need to install libstdc++, since Clang uses this to find the standard C++ headers. E.g., - sudo apt-get install g++-8 + sudo apt-get install libstdc++-14-dev # Purpose of the tests diff --git a/deps/inspector_protocol/crdtp/cbor.h b/deps/inspector_protocol/crdtp/cbor.h index 471aa78e60..2d925fad5c 100644 --- a/deps/inspector_protocol/crdtp/cbor.h +++ b/deps/inspector_protocol/crdtp/cbor.h @@ -255,7 +255,8 @@ class CRDTP_EXPORT CBORTokenizer { span GetString8() const; // Wire representation for STRING16 is low byte first (little endian). - // To be called only if ::TokenTag() == CBORTokenTag::STRING16. + // To be called only if ::TokenTag() == CBORTokenTag::STRING16. The result is + // guaranteed to have even length. span GetString16WireRep() const; // To be called only if ::TokenTag() == CBORTokenTag::BINARY. diff --git a/deps/inspector_protocol/crdtp/dispatch_test.cc b/deps/inspector_protocol/crdtp/dispatch_test.cc index 03c8792a8e..c7290f9296 100644 --- a/deps/inspector_protocol/crdtp/dispatch_test.cc +++ b/deps/inspector_protocol/crdtp/dispatch_test.cc @@ -169,10 +169,11 @@ TEST(DispatchableTest, MessageWithUnknownProperty) { } TEST(DispatchableTest, DuplicateMapKey) { - for (const std::string& json : - {"{\"id\":42,\"id\":42}", "{\"params\":null,\"params\":null}", - "{\"method\":\"foo\",\"method\":\"foo\"}", - "{\"sessionId\":\"42\",\"sessionId\":\"42\"}"}) { + const std::array jsons = { + {"{\"id\":42,\"id\":42}", "{\"params\":null,\"params\":null}", + "{\"method\":\"foo\",\"method\":\"foo\"}", + "{\"sessionId\":\"42\",\"sessionId\":\"42\"}"}}; + for (const std::string& json : jsons) { SCOPED_TRACE("json = " + json); std::vector cbor; ASSERT_TRUE(json::ConvertJSONToCBOR(SpanFrom(json), &cbor).ok()); @@ -185,11 +186,12 @@ TEST(DispatchableTest, DuplicateMapKey) { } TEST(DispatchableTest, ValidMessageParsesOK_NoParams) { - for (const std::string& json : - {"{\"id\":42,\"method\":\"Foo.executeBar\",\"sessionId\":" - "\"f421ssvaz4\"}", - "{\"id\":42,\"method\":\"Foo.executeBar\",\"sessionId\":\"f421ssvaz4\"," - "\"params\":null}"}) { + const std::array jsons = { + {"{\"id\":42,\"method\":\"Foo.executeBar\",\"sessionId\":" + "\"f421ssvaz4\"}", + "{\"id\":42,\"method\":\"Foo.executeBar\",\"sessionId\":\"f421ssvaz4\"," + "\"params\":null}"}}; + for (const std::string& json : jsons) { SCOPED_TRACE("json = " + json); std::vector cbor; ASSERT_TRUE(json::ConvertJSONToCBOR(SpanFrom(json), &cbor).ok()); diff --git a/deps/inspector_protocol/crdtp/frontend_channel.h b/deps/inspector_protocol/crdtp/frontend_channel.h index 0aa7480c94..652c65219d 100644 --- a/deps/inspector_protocol/crdtp/frontend_channel.h +++ b/deps/inspector_protocol/crdtp/frontend_channel.h @@ -24,7 +24,7 @@ class CRDTP_EXPORT FrontendChannel { // responses may be sent from an untrusted source to a trusted process (e.g. // from Chromium's renderer (blink) to the browser process), which needs // to be able to match the response to an earlier request without parsing the - // messsage. + // message. virtual void SendProtocolResponse(int call_id, std::unique_ptr message) = 0; virtual void SendProtocolNotification( diff --git a/deps/inspector_protocol/crdtp/json_test.cc b/deps/inspector_protocol/crdtp/json_test.cc index 64362d391b..08f65e48a2 100644 --- a/deps/inspector_protocol/crdtp/json_test.cc +++ b/deps/inspector_protocol/crdtp/json_test.cc @@ -704,15 +704,16 @@ using ContainerTestTypes = ::testing::Types, std::string>; TYPED_TEST_SUITE(ConvertJSONToCBORTest, ContainerTestTypes); TYPED_TEST(ConvertJSONToCBORTest, RoundTripValidJson) { - for (const std::string& json_in : { - "{\"msg\":\"Hello, world.\",\"lst\":[1,2,3]}", - "3.1415", - "false", - "true", - "\"Hello, world.\"", - "[1,2,3]", - "[]", - }) { + const std::array jsons = {{ + "{\"msg\":\"Hello, world.\",\"lst\":[1,2,3]}", + "3.1415", + "false", + "true", + "\"Hello, world.\"", + "[1,2,3]", + "[]", + }}; + for (const std::string& json_in : jsons) { SCOPED_TRACE(json_in); TypeParam json(json_in.begin(), json_in.end()); std::vector cbor; diff --git a/deps/inspector_protocol/crdtp/maybe.h b/deps/inspector_protocol/crdtp/maybe.h deleted file mode 100644 index ecdfb4fd89..0000000000 --- a/deps/inspector_protocol/crdtp/maybe.h +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2019 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -#ifndef CRDTP_MAYBE_H_ -#define CRDTP_MAYBE_H_ - -#include -#include - -namespace crdtp { - -// ============================================================================= -// detail::PtrMaybe, detail::ValueMaybe, templates for optional -// pointers / values which are used in ../lib/Forward_h.template. -// ============================================================================= - -namespace detail { -template -class PtrMaybe { - public: - PtrMaybe() = default; - PtrMaybe(std::unique_ptr value) : value_(std::move(value)) {} - PtrMaybe(PtrMaybe&& other) noexcept : value_(std::move(other.value_)) {} - void operator=(std::unique_ptr value) { value_ = std::move(value); } - - // std::optional<>-compatible accessors (preferred). - bool has_value() const { return !!value_; } - operator bool() const { return has_value(); } - const T& value() const& { - assert(has_value()); - return *value_; - } - T& value() & { - assert(has_value()); - return *value_; - } - T&& value() && { - assert(has_value()); - return std::move(*value_); - } - const T& value_or(const T& default_value) const { - return has_value() ? *value_ : default_value; - } - T* operator->() { return &value(); } - const T* operator->() const { return &value(); } - - T& operator*() & { return value(); } - const T& operator*() const& { return value(); } - T&& operator*() && { return std::move(value()); } - - // Legacy Maybe<> accessors (deprecated). - T* fromJust() const { - assert(value_); - return value_.get(); - } - T* fromMaybe(T* default_value) const { - return value_ ? value_.get() : default_value; - } - bool isJust() const { return value_ != nullptr; } - - private: - std::unique_ptr value_; -}; - -template -class ValueMaybe { - public: - ValueMaybe() : is_just_(false), value_() {} - ValueMaybe(T value) : is_just_(true), value_(std::move(value)) {} - ValueMaybe(ValueMaybe&& other) noexcept - : is_just_(other.is_just_), value_(std::move(other.value_)) {} - void operator=(T value) { - value_ = std::move(value); - is_just_ = true; - } - - // std::optional<>-compatible accessors (preferred). - bool has_value() const { return is_just_; } - operator bool() const { return has_value(); } - const T& value() const& { - assert(is_just_); - return value_; - } - T& value() & { - assert(is_just_); - return value_; - } - T&& value() && { - assert(is_just_); - return *std::move(value_); - } - template - T value_or(U&& default_value) const& { - return is_just_ ? value_ : std::forward(default_value); - } - template - T value_or(U&& default_value) && { - return is_just_ ? std::move(value_) : std::forward(default_value); - } - T* operator->() { return &value(); } - const T* operator->() const { return &value(); } - - T& operator*() & { return value(); } - const T& operator*() const& { return value(); } - T&& operator*() && { return std::move(value()); } - - // Legacy Maybe<> accessors (deprecated). - const T& fromJust() const { - assert(is_just_); - return value_; - } - const T& fromMaybe(const T& default_value) const { - return is_just_ ? value_ : default_value; - } - bool isJust() const { return is_just_; } - - private: - bool is_just_; - T value_; -}; - -template -struct MaybeTypedef { - typedef PtrMaybe type; -}; - -template <> -struct MaybeTypedef { - typedef ValueMaybe type; -}; - -template <> -struct MaybeTypedef { - typedef ValueMaybe type; -}; - -template <> -struct MaybeTypedef { - typedef ValueMaybe type; -}; - -template <> -struct MaybeTypedef { - typedef ValueMaybe type; -}; - -} // namespace detail - -template -using Maybe = typename detail::MaybeTypedef::type; - -} // namespace crdtp - -#endif // CRDTP_MAYBE_H_ diff --git a/deps/inspector_protocol/crdtp/maybe_test.cc b/deps/inspector_protocol/crdtp/maybe_test.cc deleted file mode 100644 index d606692b51..0000000000 --- a/deps/inspector_protocol/crdtp/maybe_test.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2019 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "maybe.h" - -#include -#include - -#include "test_platform.h" - -namespace crdtp { - -// ============================================================================= -// detail::PtrMaybe, detail::ValueMaybe, templates for optional -// pointers / values which are used in ../lib/Forward_h.template. -// ============================================================================= -TEST(PtrMaybeTest, SmokeTest) { - detail::PtrMaybe> example; - EXPECT_FALSE(example.has_value()); - std::unique_ptr> v(new std::vector); - v->push_back(42); - v->push_back(21); - example = std::move(v); - EXPECT_TRUE(example.has_value()); - EXPECT_THAT(example.value(), testing::ElementsAre(42, 21)); - std::vector out = *std::move(example); - EXPECT_TRUE(example.has_value()); - EXPECT_THAT(*example, testing::IsEmpty()); - EXPECT_THAT(out, testing::ElementsAre(42, 21)); -} - -TEST(ValueMaybeTest, SmokeTest) { - detail::ValueMaybe example; - EXPECT_FALSE(example.has_value()); - EXPECT_EQ(-1, example.value_or(-1)); - example = 42; - EXPECT_TRUE(example.has_value()); - EXPECT_EQ(42, example.value()); - int32_t out = *std::move(example); - EXPECT_EQ(out, 42); -} - -} // namespace crdtp diff --git a/deps/inspector_protocol/crdtp/protocol_core.cc b/deps/inspector_protocol/crdtp/protocol_core.cc index d9cc3b1136..69773593de 100644 --- a/deps/inspector_protocol/crdtp/protocol_core.cc +++ b/deps/inspector_protocol/crdtp/protocol_core.cc @@ -280,10 +280,10 @@ bool ProtocolTypeTraits>::Deserialize( return true; } -void ProtocolTypeTraits>::Serialize( - const std::unique_ptr& value, +void ProtocolTypeTraits::Serialize( + const DeferredMessage& value, std::vector* bytes) { - value->AppendSerialized(bytes); + value.AppendSerialized(bytes); } } // namespace crdtp diff --git a/deps/inspector_protocol/crdtp/protocol_core.h b/deps/inspector_protocol/crdtp/protocol_core.h index e89e0b2d95..f828336777 100644 --- a/deps/inspector_protocol/crdtp/protocol_core.h +++ b/deps/inspector_protocol/crdtp/protocol_core.h @@ -8,12 +8,12 @@ #include #include +#include #include #include #include #include "cbor.h" -#include "maybe.h" #include "serializable.h" #include "span.h" #include "status.h" @@ -84,7 +84,7 @@ class CRDTP_EXPORT ContainerSerializer { ProtocolTypeTraits::Serialize(value, bytes_); } template - void AddField(span field_name, const detail::ValueMaybe& value) { + void AddField(span field_name, const std::optional& value) { if (!value.has_value()) { return; } @@ -92,11 +92,11 @@ class CRDTP_EXPORT ContainerSerializer { } template - void AddField(span field_name, const detail::PtrMaybe& value) { - if (!value.has_value()) { + void AddField(span field_name, const std::unique_ptr& value) { + if (!value) { return; } - AddField(field_name, value.value()); + AddField(field_name, *value); } void EncodeStop(); @@ -209,14 +209,18 @@ template <> struct CRDTP_EXPORT ProtocolTypeTraits> { static bool Deserialize(DeserializerState* state, std::unique_ptr* value); - static void Serialize(const std::unique_ptr& value, +}; + +template <> +struct CRDTP_EXPORT ProtocolTypeTraits { + static void Serialize(const DeferredMessage& value, std::vector* bytes); }; template -struct ProtocolTypeTraits> { +struct ProtocolTypeTraits> { static bool Deserialize(DeserializerState* state, - detail::ValueMaybe* value) { + std::optional* value) { T res; if (!ProtocolTypeTraits::Deserialize(state, &res)) return false; @@ -224,24 +228,7 @@ struct ProtocolTypeTraits> { return true; } - static void Serialize(const detail::ValueMaybe& value, - std::vector* bytes) { - ProtocolTypeTraits::Serialize(value.value(), bytes); - } -}; - -template -struct ProtocolTypeTraits> { - static bool Deserialize(DeserializerState* state, - detail::PtrMaybe* value) { - std::unique_ptr res; - if (!ProtocolTypeTraits>::Deserialize(state, &res)) - return false; - *value = std::move(res); - return true; - } - - static void Serialize(const detail::PtrMaybe& value, + static void Serialize(const std::optional& value, std::vector* bytes) { ProtocolTypeTraits::Serialize(value.value(), bytes); } diff --git a/deps/inspector_protocol/crdtp/protocol_core_test.cc b/deps/inspector_protocol/crdtp/protocol_core_test.cc index 2d9246b4b8..dbe99be634 100644 --- a/deps/inspector_protocol/crdtp/protocol_core_test.cc +++ b/deps/inspector_protocol/crdtp/protocol_core_test.cc @@ -7,7 +7,6 @@ #include #include "cbor.h" -#include "maybe.h" #include "status_test_support.h" #include "test_platform.h" #include "test_string_traits.h" @@ -359,10 +358,9 @@ class TestTypeOptional : public ProtocolObject { const std::string& GetStrField() const { return str_field_.value(); } void SetStrField(std::string value) { str_field_ = std::move(value); } - bool HasTestTypeBasicField() { return test_type_basic_field_.has_value(); } + bool HasTestTypeBasicField() { return !!test_type_basic_field_; } const TestTypeBasic* GetTestTypeBasicField() const { - return test_type_basic_field_.has_value() ? &test_type_basic_field_.value() - : nullptr; + return test_type_basic_field_.get(); } void SetTestTypeBasicField(std::unique_ptr value) { test_type_basic_field_ = std::move(value); @@ -371,9 +369,9 @@ class TestTypeOptional : public ProtocolObject { private: DECLARE_SERIALIZATION_SUPPORT(); - Maybe int_field_; - Maybe str_field_; - Maybe test_type_basic_field_; + std::optional int_field_; + std::optional str_field_; + std::unique_ptr test_type_basic_field_; }; // clang-format off diff --git a/deps/inspector_protocol/inspector_protocol.gni b/deps/inspector_protocol/inspector_protocol.gni index 4e2547a09a..15ffbf923c 100644 --- a/deps/inspector_protocol/inspector_protocol.gni +++ b/deps/inspector_protocol/inspector_protocol.gni @@ -2,11 +2,6 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -declare_args() { - # Where jinja2 is located, in chromium it is //third_party. - jinja_dir = "//third_party" -} - # This template will generate inspector protocol source code. The code will # not be compiled, use get_target_outputs() to compile them. # @@ -24,6 +19,9 @@ declare_args() { # # inputs (optional) # Extra inputs specified by the config file. +# +# jinja_dir (optional) +# Custom path to jinja (defaults to "//third_party"). template("inspector_protocol_generate") { assert(defined(invoker.config_file)) assert(defined(invoker.out_dir)) @@ -32,6 +30,12 @@ template("inspector_protocol_generate") { inspector_protocol_dir = invoker.inspector_protocol_dir use_embedder_types = defined(invoker.use_embedder_types) && invoker.use_embedder_types + + if (defined(invoker.jinja_dir)) { + jinja_dir = invoker.jinja_dir + } else { + jinja_dir = "//third_party" + } action(target_name) { script = "$inspector_protocol_dir/code_generator.py" diff --git a/deps/inspector_protocol/lib/Forward_h.template b/deps/inspector_protocol/lib/Forward_h.template index 4de0eeb803..247bc03c79 100644 --- a/deps/inspector_protocol/lib/Forward_h.template +++ b/deps/inspector_protocol/lib/Forward_h.template @@ -54,12 +54,6 @@ class StringValue; class Value; {% endif %} -using {{config.crdtp.namespace}}::detail::PtrMaybe; -using {{config.crdtp.namespace}}::detail::ValueMaybe; - -template -using Maybe = {{config.crdtp.namespace}}::Maybe; - namespace detail { template diff --git a/deps/inspector_protocol/lib/Values_cpp.template b/deps/inspector_protocol/lib/Values_cpp.template index dbc51694db..0c409295d5 100644 --- a/deps/inspector_protocol/lib/Values_cpp.template +++ b/deps/inspector_protocol/lib/Values_cpp.template @@ -87,8 +87,7 @@ class ValueParserHandler : public ParserHandler { } void HandleBinary(span bytes) override { - AddValueToParent( - BinaryValue::create(Binary::fromSpan(bytes.data(), bytes.size()))); + AddValueToParent(BinaryValue::create(Binary::fromSpan(bytes))); } void HandleDouble(double value) override { diff --git a/deps/inspector_protocol/templates/TypeBuilder_cpp.template b/deps/inspector_protocol/templates/TypeBuilder_cpp.template index 27a8f1f12b..a38182c311 100644 --- a/deps/inspector_protocol/templates/TypeBuilder_cpp.template +++ b/deps/inspector_protocol/templates/TypeBuilder_cpp.template @@ -116,7 +116,7 @@ const char* {{ literal | to_title_case}} = "{{literal}}"; void Frontend::{{event.name | to_method_case}}( {%- for parameter in event.parameters %} {% if "optional" in parameter -%} - Maybe<{{protocol.resolve_type(parameter).raw_type}}> + {{protocol.optional_type(parameter)}} {%- else -%} {{protocol.resolve_type(parameter).pass_type}} {%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%} @@ -215,7 +215,7 @@ public: void sendSuccess( {%- for parameter in command.returns -%} {%- if "optional" in parameter -%} - Maybe<{{protocol.resolve_type(parameter).raw_type}}> {{parameter.name}} + {{protocol.optional_type(parameter)}} {{parameter.name}} {%- else -%} {{protocol.resolve_type(parameter).pass_type}} {{parameter.name}} {%- endif -%} @@ -249,7 +249,7 @@ struct {{command.name}}Params : public {{config.crdtp.namespace}}::Deserializabl {% for parameter in command.parameters %} {% set parameter_type = protocol.resolve_type(parameter) %} {% if parameter.optional %} - Maybe<{{parameter_type.raw_type}}> {{parameter.name}}; + {{protocol.optional_type(parameter)}} {{parameter.name}}; {% else %} {{parameter_type.type}} {{parameter.name}}; {% endif %} @@ -286,7 +286,7 @@ void DomainDispatcherImpl::{{command.name}}(const {{config.crdtp.namespace}}::Di // Declare output parameters. {% for parameter in command.returns %} {% if "optional" in parameter %} - Maybe<{{protocol.resolve_type(parameter).raw_type}}> out_{{parameter.name}}; + {{protocol.optional_type(parameter)}} out_{{parameter.name}}; {% else %} {{protocol.resolve_type(parameter).type}} out_{{parameter.name}}; {% endif %} diff --git a/deps/inspector_protocol/templates/TypeBuilder_h.template b/deps/inspector_protocol/templates/TypeBuilder_h.template index e23567a573..7c2a696ad0 100644 --- a/deps/inspector_protocol/templates/TypeBuilder_h.template +++ b/deps/inspector_protocol/templates/TypeBuilder_h.template @@ -89,16 +89,19 @@ public: {% endif %} {% if property.optional %} - bool {{"has" | to_method_case}}{{property_name}}() { return {{property_field}}.has_value(); } + bool {{"has" | to_method_case}}{{property_name}}() { return !!{{property_field}}; } {% if property_type.is_primitive %} {{property_type.raw_return_type}} {{"get" | to_method_case}}{{property_name}}({{property_type.raw_pass_type}} defaultValue) const { return {{property_field}}.value_or(defaultValue); } {% else %} {{property_type.raw_return_type}} {{"get" | to_method_case}}{{property_name}}({{property_type.raw_pass_type}} defaultValue) { - return {{property_field}}.has_value() ? &{{property_field}}.value() : defaultValue; + return {{property_field}} ? {{property_field}}.get() : defaultValue; } {% endif %} + const {{protocol.optional_type(property)}}& {{"get" | to_method_case}}{{property_name}}() const { + return {{property_field}}; + } {% else %} {{property_type.raw_return_type}} {{"get" | to_method_case}}{{property_name}}() { return {{property_type.to_raw_type % property_field}}; } {% endif %} @@ -175,7 +178,7 @@ private: {% for property in type.properties %} {% if property.optional %} - Maybe<{{protocol.resolve_type(property).raw_type}}> m_{{property.name}}; + {{protocol.optional_type(property)}} m_{{property.name}}; {% else %} {{protocol.resolve_type(property).type}} m_{{property.name}}; {% endif %} @@ -199,7 +202,7 @@ public: virtual void sendSuccess( {%- for parameter in command.returns -%} {%- if "optional" in parameter -%} - Maybe<{{protocol.resolve_type(parameter).raw_type}}> {{parameter.name}} + {{protocol.optional_type(parameter)}} {{parameter.name}} {%- else -%} {{protocol.resolve_type(parameter).pass_type}} {{parameter.name}} {%- endif -%} @@ -219,7 +222,7 @@ public: {%- for parameter in command.parameters -%} {%- if not loop.first -%}, {% endif -%} {%- if "optional" in parameter -%} - Maybe<{{protocol.resolve_type(parameter).raw_type}}> in_{{parameter.name}} + {{protocol.optional_type(parameter)}} in_{{parameter.name}} {%- else -%} {{protocol.resolve_type(parameter).pass_type}} in_{{parameter.name}} {%- endif -%} @@ -231,7 +234,7 @@ public: {%- for parameter in command.returns -%} {%- if (not loop.first) or command.parameters -%}, {% endif -%} {%- if "optional" in parameter -%} - Maybe<{{protocol.resolve_type(parameter).raw_type}}>* out_{{parameter.name}} + {{protocol.optional_type(parameter)}}* out_{{parameter.name}} {%- else -%} {{protocol.resolve_type(parameter).type}}* out_{{parameter.name}} {%- endif -%} @@ -258,7 +261,7 @@ public: void {{event.name | to_method_case}}( {%- for parameter in event.parameters -%} {%- if "optional" in parameter -%} - Maybe<{{protocol.resolve_type(parameter).raw_type}}> {{parameter.name}} = Maybe<{{protocol.resolve_type(parameter).raw_type}}>() + {{protocol.optional_type(parameter)}} {{parameter.name}} = {} {%- else -%} {{protocol.resolve_type(parameter).pass_type}} {{parameter.name}} {%- endif -%}{%- if not loop.last -%}, {% endif -%} diff --git a/src/inspector/node_string.h b/src/inspector/node_string.h index 94ec9b2301..bcdedaa2ae 100644 --- a/src/inspector/node_string.h +++ b/src/inspector/node_string.h @@ -6,7 +6,6 @@ #include #include #include -#include "crdtp/maybe.h" #include "crdtp/protocol_core.h" #include "util.h" #include "v8-inspector.h" @@ -31,11 +30,6 @@ struct ProtocolTypeTraits { std::vector* bytes); }; -template <> -struct detail::MaybeTypedef { - typedef ValueMaybe type; -}; - } // namespace crdtp namespace node {