Skip to content

Commit

Permalink
tools: update inspector_protocol to 83b1154
Browse files Browse the repository at this point in the history
PR-URL: #51309
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
  • Loading branch information
cola119 authored and richardlau committed Mar 25, 2024
1 parent 43a8d3e commit 6385c7a
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 166 deletions.
1 change: 0 additions & 1 deletion src/inspector/node_inspector.gypi
Expand Up @@ -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',
Expand Down
46 changes: 23 additions & 23 deletions src/inspector/tracing_agent.cc
Expand Up @@ -147,8 +147,8 @@ DispatchResponse TracingAgent::start(
std::set<std::string> categories_set;
protocol::Array<std::string>* 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");
Expand All @@ -172,29 +172,29 @@ DispatchResponse TracingAgent::stop() {

DispatchResponse TracingAgent::getCategories(
std::unique_ptr<protocol::Array<String>>* categories) {
*categories = Array<String>::create();
*categories = std::make_unique<Array<String>>();
protocol::Array<String>* 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();
}

Expand Down
1 change: 0 additions & 1 deletion tools/inspector_protocol/code_generator.py
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion tools/inspector_protocol/inspector_protocol.gni
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion tools/inspector_protocol/inspector_protocol.gypi
Expand Up @@ -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',
Expand Down
138 changes: 0 additions & 138 deletions tools/inspector_protocol/lib/Array_h.template

This file was deleted.

21 changes: 20 additions & 1 deletion tools/inspector_protocol/lib/Forward_h.template
Expand Up @@ -22,7 +22,6 @@
namespace {{namespace}} {
{% endfor %}

template<typename T> class Array;
class DictionaryValue;
class DispatchResponse;
class ErrorSupport;
Expand All @@ -35,6 +34,26 @@ class StringValue;
class UberDispatcher;
class Value;

namespace detail {
template <typename T>
struct ArrayTypedef { typedef std::vector<std::unique_ptr<T>> type; };

template <>
struct ArrayTypedef<String> { typedef std::vector<String> type; };

template <>
struct ArrayTypedef<int> { typedef std::vector<int> type; };

template <>
struct ArrayTypedef<double> { typedef std::vector<double> type; };

template <>
struct ArrayTypedef<bool> { typedef std::vector<bool> type; };
} // namespace detail

template <typename T>
using Array = typename detail::ArrayTypedef<T>::type;

{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
Expand Down
66 changes: 66 additions & 0 deletions tools/inspector_protocol/lib/ValueConversions_h.template
Expand Up @@ -128,6 +128,72 @@ struct ValueConversions<Binary> {
}
};

template<typename T>
struct ValueConversions<std::vector<std::unique_ptr<T>>> {
static std::unique_ptr<std::vector<std::unique_ptr<T>>> 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<std::vector<std::unique_ptr<T>>> result(
new std::vector<std::unique_ptr<T>>());
result->reserve(array->size());
for (size_t i = 0; i < array->size(); ++i) {
errors->setName(StringUtil::fromInteger(i));
auto item = ValueConversions<T>::fromValue(array->at(i), errors);
result->emplace_back(std::move(item));
}
errors->pop();
if (errors->hasErrors())
return nullptr;
return result;
}

static std::unique_ptr<protocol::ListValue> toValue(std::vector<std::unique_ptr<T>>* v)
{
std::unique_ptr<protocol::ListValue> result = ListValue::create();
result->reserve(v->size());
for (auto& item : *v)
result->pushValue(ValueConversions<T>::toValue(item.get()));
return result;
}

};

template<typename T>
struct ValueConversions<std::vector<T>> {
static std::unique_ptr<std::vector<T>> 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<std::vector<T>> result(new std::vector<T>());
result->reserve(array->size());
for (size_t i = 0; i < array->size(); ++i) {
errors->setName(StringUtil::fromInteger(i));
auto item = ValueConversions<T>::fromValue(array->at(i), errors);
result->emplace_back(std::move(item));
}
errors->pop();
if (errors->hasErrors())
return nullptr;
return result;
}

static std::unique_ptr<protocol::ListValue> toValue(std::vector<T>* v)
{
std::unique_ptr<protocol::ListValue> result = ListValue::create();
result->reserve(v->size());
for (auto& item : *v)
result->pushValue(ValueConversions<T>::toValue(item));
return result;
}
};

template<>
struct ValueConversions<Value> {
static std::unique_ptr<Value> fromValue(protocol::Value* value, ErrorSupport* errors)
Expand Down
1 change: 1 addition & 0 deletions tools/inspector_protocol/lib/Values_h.template
Expand Up @@ -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();
Expand Down

0 comments on commit 6385c7a

Please sign in to comment.