Skip to content

Commit

Permalink
src: rename binding_data_name to type_name in BindingData
Browse files Browse the repository at this point in the history
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: #37112
Refs: #36943
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
  • Loading branch information
joyeecheung authored and danielleadams committed Feb 16, 2021
1 parent 3079a78 commit 54d36b0
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand All @@ -433,7 +433,7 @@ class BindingData : public BaseObject {
public:
BindingData(Environment* env, Local<Object> obj) : BaseObject(env, obj) {}
static constexpr FastStringKey binding_data_name { "http_parser" };
static constexpr FastStringKey type_name { "http_parser" };
std::vector<char> parser_buffer;
bool parser_buffer_in_use = false;
Expand Down
4 changes: 2 additions & 2 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ inline T* Environment::GetBindingData(v8::Local<v8::Context> 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<T*>(it->second.get());
DCHECK_NOT_NULL(result);
Expand All @@ -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<T>(context), item.get());
return item.get();
Expand Down
2 changes: 1 addition & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> target,
Local<Value> unused,
Expand Down
2 changes: 1 addition & 1 deletion src/node_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BindingData : public BaseObject {
std::vector<BaseObjectPtr<FileHandleReadWrap>>
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)
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> target,
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class BindingData : public BaseObject {
BindingData(Environment* env, Local<Object> obj)
: BaseObject(env, obj) {}

static constexpr FastStringKey binding_data_name { "http_parser" };
static constexpr FastStringKey type_name { "http_parser" };

std::vector<char> parser_buffer;
bool parser_buffer_in_use = false;
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/node_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Expand Down

0 comments on commit 54d36b0

Please sign in to comment.