From 54d36b00afa66102d55c6353a2f6c00459b97242 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 28 Jan 2021 23:22:18 +0800 Subject: [PATCH] src: rename binding_data_name to type_name in BindingData MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, this was a per-class string constant for BindingData which is used as keys for identifying these objects in the binding data map. These are just type names of the BindingData. This patch renames the variable to type_name so that we can generalize this constant for other BaseObjects and use it for debugging and logging the types of other BaseObjects. PR-URL: https://github.com/nodejs/node/pull/37112 Refs: https://github.com/nodejs/node/pull/36943 Reviewed-By: Juan José Arboleda --- src/README.md | 4 ++-- src/env-inl.h | 4 ++-- src/node_file.cc | 2 +- src/node_file.h | 2 +- src/node_http2.cc | 2 +- src/node_http2_state.h | 2 +- src/node_http_parser.cc | 4 ++-- src/node_v8.cc | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/README.md b/src/README.md index aec56e7a7ba05a..a3b54416a0d2f5 100644 --- a/src/README.md +++ b/src/README.md @@ -422,7 +422,7 @@ that state is through the use of `Environment::AddBindingData`, which gives binding functions access to an object for storing such state. That object is always a [`BaseObject`][]. -Its class needs to have a static `binding_data_name` field based on a +Its class needs to have a static `type_name` field based on a constant string, in order to disambiguate it from other classes of this type, and which could e.g. match the binding’s name (in the example above, that would be `cares_wrap`). @@ -433,7 +433,7 @@ class BindingData : public BaseObject { public: BindingData(Environment* env, Local obj) : BaseObject(env, obj) {} - static constexpr FastStringKey binding_data_name { "http_parser" }; + static constexpr FastStringKey type_name { "http_parser" }; std::vector parser_buffer; bool parser_buffer_in_use = false; diff --git a/src/env-inl.h b/src/env-inl.h index 95b818373b9a0a..93d2423580a88b 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -358,7 +358,7 @@ inline T* Environment::GetBindingData(v8::Local context) { context->GetAlignedPointerFromEmbedderData( ContextEmbedderIndex::kBindingListIndex)); DCHECK_NOT_NULL(map); - auto it = map->find(T::binding_data_name); + auto it = map->find(T::type_name); if (UNLIKELY(it == map->end())) return nullptr; T* result = static_cast(it->second.get()); DCHECK_NOT_NULL(result); @@ -377,7 +377,7 @@ inline T* Environment::AddBindingData( context->GetAlignedPointerFromEmbedderData( ContextEmbedderIndex::kBindingListIndex)); DCHECK_NOT_NULL(map); - auto result = map->emplace(T::binding_data_name, item); + auto result = map->emplace(T::type_name, item); CHECK(result.second); DCHECK_EQ(GetBindingData(context), item.get()); return item.get(); diff --git a/src/node_file.cc b/src/node_file.cc index 8c1ea9053f3519..31494e8d2e8370 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -2399,7 +2399,7 @@ void BindingData::MemoryInfo(MemoryTracker* tracker) const { } // TODO(addaleax): Remove once we're on C++17. -constexpr FastStringKey BindingData::binding_data_name; +constexpr FastStringKey BindingData::type_name; void Initialize(Local target, Local unused, diff --git a/src/node_file.h b/src/node_file.h index 95a68b5d89a704..9e652dc7a4afa4 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -27,7 +27,7 @@ class BindingData : public BaseObject { std::vector> file_handle_read_wrap_freelist; - static constexpr FastStringKey binding_data_name { "fs" }; + static constexpr FastStringKey type_name { "fs" }; void MemoryInfo(MemoryTracker* tracker) const override; SET_SELF_SIZE(BindingData) diff --git a/src/node_http2.cc b/src/node_http2.cc index 930167418e18db..a4b8e4d2ac7d50 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -3001,7 +3001,7 @@ void Http2State::MemoryInfo(MemoryTracker* tracker) const { } // TODO(addaleax): Remove once we're on C++17. -constexpr FastStringKey Http2State::binding_data_name; +constexpr FastStringKey Http2State::type_name; // Set up the process.binding('http2') binding. void Initialize(Local target, diff --git a/src/node_http2_state.h b/src/node_http2_state.h index cd29b207498dc0..7cf40ff1017ca3 100644 --- a/src/node_http2_state.h +++ b/src/node_http2_state.h @@ -127,7 +127,7 @@ class Http2State : public BaseObject { SET_SELF_SIZE(Http2State) SET_MEMORY_INFO_NAME(Http2State) - static constexpr FastStringKey binding_data_name { "http2" }; + static constexpr FastStringKey type_name { "http2" }; private: struct http2_state_internal { diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index b2841772aa3779..dfe0273d06f0e3 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -88,7 +88,7 @@ class BindingData : public BaseObject { BindingData(Environment* env, Local obj) : BaseObject(env, obj) {} - static constexpr FastStringKey binding_data_name { "http_parser" }; + static constexpr FastStringKey type_name { "http_parser" }; std::vector parser_buffer; bool parser_buffer_in_use = false; @@ -101,7 +101,7 @@ class BindingData : public BaseObject { }; // TODO(addaleax): Remove once we're on C++17. -constexpr FastStringKey BindingData::binding_data_name; +constexpr FastStringKey BindingData::type_name; // helper class for the Parser struct StringPtr { diff --git a/src/node_v8.cc b/src/node_v8.cc index 4ab87dce326bb1..d66b5e03b8620c 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -95,7 +95,7 @@ class BindingData : public BaseObject { heap_code_statistics_buffer(env->isolate(), kHeapCodeStatisticsPropertiesCount) {} - static constexpr FastStringKey binding_data_name { "v8" }; + static constexpr FastStringKey type_name { "v8" }; AliasedFloat64Array heap_statistics_buffer; AliasedFloat64Array heap_space_statistics_buffer; @@ -113,7 +113,7 @@ class BindingData : public BaseObject { }; // TODO(addaleax): Remove once we're on C++17. -constexpr FastStringKey BindingData::binding_data_name; +constexpr FastStringKey BindingData::type_name; void CachedDataVersionTag(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args);