Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! fixup! fixup! squash! src: retrieve binding data from the context
  • Loading branch information
addaleax committed May 6, 2020
commit f878946190259dde854b3cd234791471882ee3f3
3 changes: 2 additions & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ That object is always a [`BaseObject`][].

Its class needs to have a static `binding_data_name` field that 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.
and which could e.g. match the binding’s name (in the example above, that would
be `cares_wrap`).

```c++
// In the HTTP parser source code file:
Expand Down
14 changes: 7 additions & 7 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@ inline T* Environment::GetBindingData(

template <typename T>
inline T* Environment::GetBindingData(v8::Local<v8::Context> context) {
BindingDataStore* list = static_cast<BindingDataStore*>(
BindingDataStore* map = static_cast<BindingDataStore*>(
context->GetAlignedPointerFromEmbedderData(
ContextEmbedderIndex::kBindingListIndex));
DCHECK_NOT_NULL(list);
auto it = list->find(T::binding_data_name);
DCHECK_NE(it, list->end());
DCHECK_NOT_NULL(map);
auto it = map->find(T::binding_data_name);
if (UNLIKELY(it == map->end())) return nullptr;
T* result = static_cast<T*>(it->second.get());
DCHECK_NOT_NULL(result);
DCHECK_EQ(result->env(), GetCurrent(context));
Expand All @@ -363,11 +363,11 @@ inline T* Environment::AddBindingData(
DCHECK_EQ(GetCurrent(context), this);
// This won't compile if T is not a BaseObject subclass.
BaseObjectPtr<T> item = MakeDetachedBaseObject<T>(this, target);
BindingDataStore* list = static_cast<BindingDataStore*>(
BindingDataStore* map = static_cast<BindingDataStore*>(
context->GetAlignedPointerFromEmbedderData(
ContextEmbedderIndex::kBindingListIndex));
DCHECK_NOT_NULL(list);
auto result = list->emplace(T::binding_data_name, item);
DCHECK_NOT_NULL(map);
auto result = map->emplace(T::binding_data_name, item);
CHECK(result.second);
DCHECK_EQ(GetBindingData<T>(context), item.get());
return item.get();
Expand Down
3 changes: 1 addition & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ MaybeLocal<Value> Environment::BootstrapNode() {

Local<String> env_string = FIXED_ONE_BYTE_STRING(isolate_, "env");
Local<Object> env_var_proxy;
if (!CreateEnvVarProxy(context(), isolate_, Local<Value>())
.ToLocal(&env_var_proxy) ||
if (!CreateEnvVarProxy(context(), isolate_).ToLocal(&env_var_proxy) ||
process_object()->Set(context(), env_string, env_var_proxy).IsNothing()) {
return MaybeLocal<Value>();
}
Expand Down
6 changes: 2 additions & 4 deletions src/node_env_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,11 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
env->env_vars()->Enumerate(env->isolate()));
}

MaybeLocal<Object> CreateEnvVarProxy(Local<Context> context,
Isolate* isolate,
Local<Value> data) {
MaybeLocal<Object> CreateEnvVarProxy(Local<Context> context, Isolate* isolate) {
EscapableHandleScope scope(isolate);
Local<ObjectTemplate> env_proxy_template = ObjectTemplate::New(isolate);
env_proxy_template->SetHandler(NamedPropertyHandlerConfiguration(
EnvGetter, EnvSetter, EnvQuery, EnvDeleter, EnvEnumerator, data,
EnvGetter, EnvSetter, EnvQuery, EnvDeleter, EnvEnumerator, Local<Value>(),
PropertyHandlerFlags::kHasNoSideEffect));
return scope.EscapeMaybe(env_proxy_template->NewInstance(context));
}
Expand Down
3 changes: 1 addition & 2 deletions src/node_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
namespace node {

v8::MaybeLocal<v8::Object> CreateEnvVarProxy(v8::Local<v8::Context> context,
v8::Isolate* isolate,
v8::Local<v8::Value> data);
v8::Isolate* isolate);

// Most of the time, it's best to use `console.error` to write
// to the process.stderr stream. However, in some cases, such as
Expand Down