From d102d16e98a8845cba96157b6396bd448241e47c Mon Sep 17 00:00:00 2001 From: Kohei Ueno Date: Thu, 11 Jan 2024 13:41:26 +0900 Subject: [PATCH] tools: update inspector_protocol to 83b1154 PR-URL: https://github.com/nodejs/node/pull/51309 Reviewed-By: Stephen Belanger --- src/inspector/node_inspector.gypi | 1 - src/inspector/tracing_agent.cc | 46 +++--- tools/inspector_protocol/code_generator.py | 1 - .../inspector_protocol/inspector_protocol.gni | 1 - .../inspector_protocol.gypi | 1 - tools/inspector_protocol/lib/Array_h.template | 138 ------------------ .../inspector_protocol/lib/Forward_h.template | 21 ++- .../lib/ValueConversions_h.template | 66 +++++++++ .../inspector_protocol/lib/Values_h.template | 1 + 9 files changed, 110 insertions(+), 166 deletions(-) delete mode 100644 tools/inspector_protocol/lib/Array_h.template diff --git a/src/inspector/node_inspector.gypi b/src/inspector/node_inspector.gypi index ba24e6acfc0..a2dfdcb42db 100644 --- a/src/inspector/node_inspector.gypi +++ b/src/inspector/node_inspector.gypi @@ -39,7 +39,6 @@ ], 'node_protocol_files': [ '<(protocol_tool_path)/lib/Allocator_h.template', - '<(protocol_tool_path)/lib/Array_h.template', '<(protocol_tool_path)/lib/base_string_adapter_cc.template', '<(protocol_tool_path)/lib/base_string_adapter_h.template', '<(protocol_tool_path)/lib/DispatcherBase_cpp.template', diff --git a/src/inspector/tracing_agent.cc b/src/inspector/tracing_agent.cc index cdbdd63f8af..e7b6d3b3ea6 100644 --- a/src/inspector/tracing_agent.cc +++ b/src/inspector/tracing_agent.cc @@ -147,8 +147,8 @@ DispatchResponse TracingAgent::start( std::set categories_set; protocol::Array* categories = traceConfig->getIncludedCategories(); - for (size_t i = 0; i < categories->length(); i++) - categories_set.insert(categories->get(i)); + for (size_t i = 0; i < categories->size(); i++) + categories_set.insert((*categories)[i]); if (categories_set.empty()) return DispatchResponse::Error("At least one category should be enabled"); @@ -172,29 +172,29 @@ DispatchResponse TracingAgent::stop() { DispatchResponse TracingAgent::getCategories( std::unique_ptr>* categories) { - *categories = Array::create(); + *categories = std::make_unique>(); protocol::Array* categories_list = categories->get(); // In alphabetical order - categories_list->addItem("node"); - categories_list->addItem("node.async_hooks"); - categories_list->addItem("node.bootstrap"); - categories_list->addItem("node.console"); - categories_list->addItem("node.dns.native"); - categories_list->addItem("node.environment"); - categories_list->addItem("node.fs.async"); - categories_list->addItem("node.fs.sync"); - categories_list->addItem("node.fs_dir.async"); - categories_list->addItem("node.fs_dir.sync"); - categories_list->addItem("node.http"); - categories_list->addItem("node.net.native"); - categories_list->addItem("node.perf"); - categories_list->addItem("node.perf.timerify"); - categories_list->addItem("node.perf.usertiming"); - categories_list->addItem("node.promises.rejections"); - categories_list->addItem("node.threadpoolwork.async"); - categories_list->addItem("node.threadpoolwork.sync"); - categories_list->addItem("node.vm.script"); - categories_list->addItem("v8"); + categories_list->emplace_back("node"); + categories_list->emplace_back("node.async_hooks"); + categories_list->emplace_back("node.bootstrap"); + categories_list->emplace_back("node.console"); + categories_list->emplace_back("node.dns.native"); + categories_list->emplace_back("node.environment"); + categories_list->emplace_back("node.fs.async"); + categories_list->emplace_back("node.fs.sync"); + categories_list->emplace_back("node.fs_dir.async"); + categories_list->emplace_back("node.fs_dir.sync"); + categories_list->emplace_back("node.http"); + categories_list->emplace_back("node.net.native"); + categories_list->emplace_back("node.perf"); + categories_list->emplace_back("node.perf.timerify"); + categories_list->emplace_back("node.perf.usertiming"); + categories_list->emplace_back("node.promises.rejections"); + categories_list->emplace_back("node.threadpoolwork.async"); + categories_list->emplace_back("node.threadpoolwork.sync"); + categories_list->emplace_back("node.vm.script"); + categories_list->emplace_back("v8"); return DispatchResponse::OK(); } diff --git a/tools/inspector_protocol/code_generator.py b/tools/inspector_protocol/code_generator.py index 0b8baea0ae7..a6e163c6fe9 100755 --- a/tools/inspector_protocol/code_generator.py +++ b/tools/inspector_protocol/code_generator.py @@ -638,7 +638,6 @@ def main(): "Object_h.template", "ValueConversions_h.template", "Maybe_h.template", - "Array_h.template", "DispatcherBase_h.template", "Parser_h.template", "encoding_h.template", diff --git a/tools/inspector_protocol/inspector_protocol.gni b/tools/inspector_protocol/inspector_protocol.gni index d612fb6aebb..3e934526b82 100644 --- a/tools/inspector_protocol/inspector_protocol.gni +++ b/tools/inspector_protocol/inspector_protocol.gni @@ -36,7 +36,6 @@ template("inspector_protocol_generate") { "$inspector_protocol_dir/lib/encoding_h.template", "$inspector_protocol_dir/lib/encoding_cpp.template", "$inspector_protocol_dir/lib/Allocator_h.template", - "$inspector_protocol_dir/lib/Array_h.template", "$inspector_protocol_dir/lib/DispatcherBase_cpp.template", "$inspector_protocol_dir/lib/DispatcherBase_h.template", "$inspector_protocol_dir/lib/ErrorSupport_cpp.template", diff --git a/tools/inspector_protocol/inspector_protocol.gypi b/tools/inspector_protocol/inspector_protocol.gypi index d614474e69c..c11386dc051 100644 --- a/tools/inspector_protocol/inspector_protocol.gypi +++ b/tools/inspector_protocol/inspector_protocol.gypi @@ -8,7 +8,6 @@ 'lib/encoding_h.template', 'lib/encoding_cpp.template', 'lib/Allocator_h.template', - 'lib/Array_h.template', 'lib/DispatcherBase_cpp.template', 'lib/DispatcherBase_h.template', 'lib/ErrorSupport_cpp.template', diff --git a/tools/inspector_protocol/lib/Array_h.template b/tools/inspector_protocol/lib/Array_h.template deleted file mode 100644 index c420a0f7e96..00000000000 --- a/tools/inspector_protocol/lib/Array_h.template +++ /dev/null @@ -1,138 +0,0 @@ -// This file is generated by Array_h.template. - -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef {{"_".join(config.protocol.namespace)}}_Array_h -#define {{"_".join(config.protocol.namespace)}}_Array_h - -//#include "ErrorSupport.h" -//#include "Forward.h" -//#include "ValueConversions.h" -//#include "Values.h" - -{% for namespace in config.protocol.namespace %} -namespace {{namespace}} { -{% endfor %} - -template -class Array { -public: - static std::unique_ptr> create() - { - return std::unique_ptr>(new Array()); - } - - static std::unique_ptr> fromValue(protocol::Value* value, ErrorSupport* errors) - { - protocol::ListValue* array = ListValue::cast(value); - if (!array) { - errors->addError("array expected"); - return nullptr; - } - std::unique_ptr> result(new Array()); - errors->push(); - for (size_t i = 0; i < array->size(); ++i) { - errors->setName(StringUtil::fromInteger(i)); - std::unique_ptr item = ValueConversions::fromValue(array->at(i), errors); - result->m_vector.push_back(std::move(item)); - } - errors->pop(); - if (errors->hasErrors()) - return nullptr; - return result; - } - - void addItem(std::unique_ptr value) - { - m_vector.push_back(std::move(value)); - } - - size_t length() - { - return m_vector.size(); - } - - T* get(size_t index) - { - return m_vector[index].get(); - } - - std::unique_ptr toValue() - { - std::unique_ptr result = ListValue::create(); - for (auto& item : m_vector) - result->pushValue(ValueConversions::toValue(item)); - return result; - } - -private: - std::vector> m_vector; -}; - -template -class ArrayBase { -public: - static std::unique_ptr> create() - { - return std::unique_ptr>(new Array()); - } - - static std::unique_ptr> fromValue(protocol::Value* value, ErrorSupport* errors) - { - protocol::ListValue* array = ListValue::cast(value); - if (!array) { - errors->addError("array expected"); - return nullptr; - } - errors->push(); - std::unique_ptr> result(new Array()); - for (size_t i = 0; i < array->size(); ++i) { - errors->setName(StringUtil::fromInteger(i)); - T item = ValueConversions::fromValue(array->at(i), errors); - result->m_vector.push_back(item); - } - errors->pop(); - if (errors->hasErrors()) - return nullptr; - return result; - } - - void addItem(const T& value) - { - m_vector.push_back(value); - } - - size_t length() - { - return m_vector.size(); - } - - T get(size_t index) - { - return m_vector[index]; - } - - std::unique_ptr toValue() - { - std::unique_ptr result = ListValue::create(); - for (auto& item : m_vector) - result->pushValue(ValueConversions::toValue(item)); - return result; - } - -private: - std::vector m_vector; -}; - -template<> class Array : public ArrayBase {}; -template<> class Array : public ArrayBase {}; -template<> class Array : public ArrayBase {}; -template<> class Array : public ArrayBase {}; - -{% for namespace in config.protocol.namespace %} -} // namespace {{namespace}} -{% endfor %} - -#endif // !defined({{"_".join(config.protocol.namespace)}}_Array_h) diff --git a/tools/inspector_protocol/lib/Forward_h.template b/tools/inspector_protocol/lib/Forward_h.template index 746ba20bba1..a6c4b12feca 100644 --- a/tools/inspector_protocol/lib/Forward_h.template +++ b/tools/inspector_protocol/lib/Forward_h.template @@ -22,7 +22,6 @@ namespace {{namespace}} { {% endfor %} -template class Array; class DictionaryValue; class DispatchResponse; class ErrorSupport; @@ -35,6 +34,26 @@ class StringValue; class UberDispatcher; class Value; +namespace detail { +template +struct ArrayTypedef { typedef std::vector> type; }; + +template <> +struct ArrayTypedef { typedef std::vector type; }; + +template <> +struct ArrayTypedef { typedef std::vector type; }; + +template <> +struct ArrayTypedef { typedef std::vector type; }; + +template <> +struct ArrayTypedef { typedef std::vector type; }; +} // namespace detail + +template +using Array = typename detail::ArrayTypedef::type; + {% for namespace in config.protocol.namespace %} } // namespace {{namespace}} {% endfor %} diff --git a/tools/inspector_protocol/lib/ValueConversions_h.template b/tools/inspector_protocol/lib/ValueConversions_h.template index 2ee5b724545..63baf689c6e 100644 --- a/tools/inspector_protocol/lib/ValueConversions_h.template +++ b/tools/inspector_protocol/lib/ValueConversions_h.template @@ -128,6 +128,72 @@ struct ValueConversions { } }; +template +struct ValueConversions>> { + static std::unique_ptr>> fromValue(protocol::Value* value, ErrorSupport* errors) { + protocol::ListValue* array = ListValue::cast(value); + if (!array) { + errors->addError("array expected"); + return nullptr; + } + errors->push(); + std::unique_ptr>> result( + new std::vector>()); + result->reserve(array->size()); + for (size_t i = 0; i < array->size(); ++i) { + errors->setName(StringUtil::fromInteger(i)); + auto item = ValueConversions::fromValue(array->at(i), errors); + result->emplace_back(std::move(item)); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; + } + + static std::unique_ptr toValue(std::vector>* v) + { + std::unique_ptr result = ListValue::create(); + result->reserve(v->size()); + for (auto& item : *v) + result->pushValue(ValueConversions::toValue(item.get())); + return result; + } + +}; + +template +struct ValueConversions> { + static std::unique_ptr> fromValue(protocol::Value* value, ErrorSupport* errors) { + protocol::ListValue* array = ListValue::cast(value); + if (!array) { + errors->addError("array expected"); + return nullptr; + } + errors->push(); + std::unique_ptr> result(new std::vector()); + result->reserve(array->size()); + for (size_t i = 0; i < array->size(); ++i) { + errors->setName(StringUtil::fromInteger(i)); + auto item = ValueConversions::fromValue(array->at(i), errors); + result->emplace_back(std::move(item)); + } + errors->pop(); + if (errors->hasErrors()) + return nullptr; + return result; + } + + static std::unique_ptr toValue(std::vector* v) + { + std::unique_ptr result = ListValue::create(); + result->reserve(v->size()); + for (auto& item : *v) + result->pushValue(ValueConversions::toValue(item)); + return result; + } +}; + template<> struct ValueConversions { static std::unique_ptr fromValue(protocol::Value* value, ErrorSupport* errors) diff --git a/tools/inspector_protocol/lib/Values_h.template b/tools/inspector_protocol/lib/Values_h.template index 4a2e58f4cd6..4d6fde07d4d 100644 --- a/tools/inspector_protocol/lib/Values_h.template +++ b/tools/inspector_protocol/lib/Values_h.template @@ -271,6 +271,7 @@ public: Value* at(size_t index); size_t size() const { return m_data.size(); } + void reserve(size_t capacity) { m_data.reserve(capacity); } private: ListValue();