summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Madsen <amwebdk@gmail.com>2017-09-26 15:50:10 +0200
committerAndreas Madsen <amwebdk@gmail.com>2017-09-26 15:50:10 +0200
commit3a69ef55e06cda552e7ad295ddf904e1c70ae13f (patch)
treea33643b534a256e0cefdb0a275b38ee5ee9defcf /src
parentf9e5709ea0bad223d44ade1760917764dca4c0cb (diff)
downloadandroid-node-v8-3a69ef55e06cda552e7ad295ddf904e1c70ae13f.tar.gz
android-node-v8-3a69ef55e06cda552e7ad295ddf904e1c70ae13f.tar.bz2
android-node-v8-3a69ef55e06cda552e7ad295ddf904e1c70ae13f.zip
async_hooks: consistent internal naming
PR-URL: https://github.com/nodejs/node/pull/15569 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/async-wrap-inl.h6
-rw-r--r--src/async-wrap.cc134
-rw-r--r--src/async-wrap.h14
-rw-r--r--src/connection_wrap.cc2
-rw-r--r--src/env-inl.h114
-rw-r--r--src/env.cc4
-rw-r--r--src/env.h53
-rw-r--r--src/node.cc16
-rw-r--r--src/node.h2
-rw-r--r--src/node_http_parser.cc2
-rw-r--r--src/pipe_wrap.cc2
-rw-r--r--src/stream_base-inl.h2
-rw-r--r--src/stream_base.cc8
-rw-r--r--src/tcp_wrap.cc6
-rw-r--r--src/udp_wrap.cc4
15 files changed, 189 insertions, 180 deletions
diff --git a/src/async-wrap-inl.h b/src/async-wrap-inl.h
index ed5a0c0d27..dd947dbd44 100644
--- a/src/async-wrap-inl.h
+++ b/src/async-wrap-inl.h
@@ -36,13 +36,13 @@ inline AsyncWrap::ProviderType AsyncWrap::provider_type() const {
}
-inline double AsyncWrap::get_id() const {
+inline double AsyncWrap::get_async_id() const {
return async_id_;
}
-inline double AsyncWrap::get_trigger_id() const {
- return trigger_id_;
+inline double AsyncWrap::get_trigger_async_id() const {
+ return trigger_async_id_;
}
diff --git a/src/async-wrap.cc b/src/async-wrap.cc
index 9b20d1c42b..7ccc108d37 100644
--- a/src/async-wrap.cc
+++ b/src/async-wrap.cc
@@ -140,8 +140,8 @@ RetainedObjectInfo* WrapperInfo(uint16_t class_id, Local<Value> wrapper) {
// end RetainedAsyncInfo
-static void DestroyIdsCb(uv_timer_t* handle) {
- Environment* env = Environment::from_destroy_ids_timer_handle(handle);
+static void DestroyAsyncIdsCallback(uv_timer_t* handle) {
+ Environment* env = Environment::from_destroy_async_ids_timer_handle(handle);
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
@@ -150,15 +150,15 @@ static void DestroyIdsCb(uv_timer_t* handle) {
TryCatch try_catch(env->isolate());
do {
- std::vector<double> destroy_ids_list;
- destroy_ids_list.swap(*env->destroy_ids_list());
- for (auto current_id : destroy_ids_list) {
+ std::vector<double> destroy_async_id_list;
+ destroy_async_id_list.swap(*env->destroy_async_id_list());
+ for (auto async_id : destroy_async_id_list) {
// Want each callback to be cleaned up after itself, instead of cleaning
// them all up after the while() loop completes.
HandleScope scope(env->isolate());
- Local<Value> argv = Number::New(env->isolate(), current_id);
+ Local<Value> async_id_value = Number::New(env->isolate(), async_id);
MaybeLocal<Value> ret = fn->Call(
- env->context(), Undefined(env->isolate()), 1, &argv);
+ env->context(), Undefined(env->isolate()), 1, &async_id_value);
if (ret.IsEmpty()) {
ClearFatalExceptionHandlers(env);
@@ -166,18 +166,19 @@ static void DestroyIdsCb(uv_timer_t* handle) {
UNREACHABLE();
}
}
- } while (!env->destroy_ids_list()->empty());
+ } while (!env->destroy_async_id_list()->empty());
}
-static void PushBackDestroyId(Environment* env, double id) {
+static void PushBackDestroyAsyncId(Environment* env, double id) {
if (env->async_hooks()->fields()[AsyncHooks::kDestroy] == 0)
return;
- if (env->destroy_ids_list()->empty())
- uv_timer_start(env->destroy_ids_timer_handle(), DestroyIdsCb, 0, 0);
+ if (env->destroy_async_id_list()->empty())
+ uv_timer_start(env->destroy_async_ids_timer_handle(),
+ DestroyAsyncIdsCallback, 0, 0);
- env->destroy_ids_list()->push_back(id);
+ env->destroy_async_id_list()->push_back(id);
}
@@ -187,11 +188,11 @@ void AsyncWrap::EmitPromiseResolve(Environment* env, double async_id) {
if (async_hooks->fields()[AsyncHooks::kPromiseResolve] == 0)
return;
- Local<Value> uid = Number::New(env->isolate(), async_id);
+ Local<Value> async_id_value = Number::New(env->isolate(), async_id);
Local<Function> fn = env->async_hooks_promise_resolve_function();
TryCatch try_catch(env->isolate());
MaybeLocal<Value> ar = fn->Call(
- env->context(), Undefined(env->isolate()), 1, &uid);
+ env->context(), Undefined(env->isolate()), 1, &async_id_value);
if (ar.IsEmpty()) {
ClearFatalExceptionHandlers(env);
FatalException(env->isolate(), try_catch);
@@ -206,11 +207,11 @@ void AsyncWrap::EmitBefore(Environment* env, double async_id) {
if (async_hooks->fields()[AsyncHooks::kBefore] == 0)
return;
- Local<Value> uid = Number::New(env->isolate(), async_id);
+ Local<Value> async_id_value = Number::New(env->isolate(), async_id);
Local<Function> fn = env->async_hooks_before_function();
TryCatch try_catch(env->isolate());
MaybeLocal<Value> ar = fn->Call(
- env->context(), Undefined(env->isolate()), 1, &uid);
+ env->context(), Undefined(env->isolate()), 1, &async_id_value);
if (ar.IsEmpty()) {
ClearFatalExceptionHandlers(env);
FatalException(env->isolate(), try_catch);
@@ -227,11 +228,11 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) {
// If the user's callback failed then the after() hooks will be called at the
// end of _fatalException().
- Local<Value> uid = Number::New(env->isolate(), async_id);
+ Local<Value> async_id_value = Number::New(env->isolate(), async_id);
Local<Function> fn = env->async_hooks_after_function();
TryCatch try_catch(env->isolate());
MaybeLocal<Value> ar = fn->Call(
- env->context(), Undefined(env->isolate()), 1, &uid);
+ env->context(), Undefined(env->isolate()), 1, &async_id_value);
if (ar.IsEmpty()) {
ClearFatalExceptionHandlers(env);
FatalException(env->isolate(), try_catch);
@@ -248,7 +249,7 @@ class PromiseWrap : public AsyncWrap {
size_t self_size() const override { return sizeof(*this); }
static constexpr int kPromiseField = 1;
- static constexpr int kParentIdField = 2;
+ static constexpr int kParentAsyncIdField = 2;
static constexpr int kInternalFieldCount = 3;
static PromiseWrap* New(Environment* env,
@@ -257,7 +258,7 @@ class PromiseWrap : public AsyncWrap {
bool silent);
static void GetPromise(Local<String> property,
const PropertyCallbackInfo<Value>& info);
- static void GetParentId(Local<String> property,
+ static void getParentAsyncId(Local<String> property,
const PropertyCallbackInfo<Value>& info);
};
@@ -269,9 +270,9 @@ PromiseWrap* PromiseWrap::New(Environment* env,
->NewInstance(env->context()).ToLocalChecked();
object->SetInternalField(PromiseWrap::kPromiseField, promise);
if (parent_wrap != nullptr) {
- object->SetInternalField(PromiseWrap::kParentIdField,
+ object->SetInternalField(PromiseWrap::kParentAsyncIdField,
Number::New(env->isolate(),
- parent_wrap->get_id()));
+ parent_wrap->get_async_id()));
}
CHECK_EQ(promise->GetAlignedPointerFromInternalField(0), nullptr);
promise->SetInternalField(0, object);
@@ -283,9 +284,10 @@ void PromiseWrap::GetPromise(Local<String> property,
info.GetReturnValue().Set(info.Holder()->GetInternalField(kPromiseField));
}
-void PromiseWrap::GetParentId(Local<String> property,
+void PromiseWrap::getParentAsyncId(Local<String> property,
const PropertyCallbackInfo<Value>& info) {
- info.GetReturnValue().Set(info.Holder()->GetInternalField(kParentIdField));
+ info.GetReturnValue().Set(
+ info.Holder()->GetInternalField(kParentAsyncIdField));
}
static void PromiseHook(PromiseHookType type, Local<Promise> promise,
@@ -317,8 +319,8 @@ static void PromiseHook(PromiseHookType type, Local<Promise> promise,
parent_wrap = PromiseWrap::New(env, parent_promise, nullptr, true);
}
// get id from parentWrap
- double trigger_id = parent_wrap->get_id();
- env->set_init_trigger_id(trigger_id);
+ double trigger_async_id = parent_wrap->get_async_id();
+ env->set_init_trigger_async_id(trigger_async_id);
}
wrap = PromiseWrap::New(env, promise, parent_wrap, silent);
@@ -326,20 +328,21 @@ static void PromiseHook(PromiseHookType type, Local<Promise> promise,
CHECK_NE(wrap, nullptr);
if (type == PromiseHookType::kBefore) {
- env->async_hooks()->push_ids(wrap->get_id(), wrap->get_trigger_id());
- AsyncWrap::EmitBefore(wrap->env(), wrap->get_id());
+ env->async_hooks()->push_async_ids(
+ wrap->get_async_id(), wrap->get_trigger_async_id());
+ AsyncWrap::EmitBefore(wrap->env(), wrap->get_async_id());
} else if (type == PromiseHookType::kAfter) {
- AsyncWrap::EmitAfter(wrap->env(), wrap->get_id());
- if (env->current_async_id() == wrap->get_id()) {
+ AsyncWrap::EmitAfter(wrap->env(), wrap->get_async_id());
+ if (env->execution_async_id() == wrap->get_async_id()) {
// This condition might not be true if async_hooks was enabled during
// the promise callback execution.
// Popping it off the stack can be skipped in that case, because is is
// known that it would correspond to exactly one call with
// PromiseHookType::kBefore that was not witnessed by the PromiseHook.
- env->async_hooks()->pop_ids(wrap->get_id());
+ env->async_hooks()->pop_async_id(wrap->get_async_id());
}
} else if (type == PromiseHookType::kResolve) {
- AsyncWrap::EmitPromiseResolve(wrap->env(), wrap->get_id());
+ AsyncWrap::EmitPromiseResolve(wrap->env(), wrap->get_async_id());
}
}
@@ -383,7 +386,7 @@ static void SetupHooks(const FunctionCallbackInfo<Value>& args) {
PromiseWrap::GetPromise);
promise_wrap_template->SetAccessor(
FIXED_ONE_BYTE_STRING(env->isolate(), "parentId"),
- PromiseWrap::GetParentId);
+ PromiseWrap::getParentAsyncId);
env->set_promise_wrap_template(promise_wrap_template);
}
}
@@ -411,24 +414,24 @@ void AsyncWrap::GetAsyncId(const FunctionCallbackInfo<Value>& args) {
AsyncWrap* wrap;
args.GetReturnValue().Set(-1);
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
- args.GetReturnValue().Set(wrap->get_id());
+ args.GetReturnValue().Set(wrap->get_async_id());
}
void AsyncWrap::PushAsyncIds(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
// No need for CHECK(IsNumber()) on args because if FromJust() doesn't fail
- // then the checks in push_ids() and pop_ids() will.
+ // then the checks in push_async_ids() and pop_async_id() will.
double async_id = args[0]->NumberValue(env->context()).FromJust();
- double trigger_id = args[1]->NumberValue(env->context()).FromJust();
- env->async_hooks()->push_ids(async_id, trigger_id);
+ double trigger_async_id = args[1]->NumberValue(env->context()).FromJust();
+ env->async_hooks()->push_async_ids(async_id, trigger_async_id);
}
void AsyncWrap::PopAsyncIds(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
double async_id = args[0]->NumberValue(env->context()).FromJust();
- args.GetReturnValue().Set(env->async_hooks()->pop_ids(async_id));
+ args.GetReturnValue().Set(env->async_hooks()->pop_async_id(async_id));
}
@@ -439,9 +442,9 @@ void AsyncWrap::AsyncIdStackSize(const FunctionCallbackInfo<Value>& args) {
}
-void AsyncWrap::ClearIdStack(const FunctionCallbackInfo<Value>& args) {
+void AsyncWrap::ClearAsyncIdStack(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
- env->async_hooks()->clear_id_stack();
+ env->async_hooks()->clear_async_id_stack();
}
@@ -452,9 +455,9 @@ void AsyncWrap::AsyncReset(const FunctionCallbackInfo<Value>& args) {
}
-void AsyncWrap::QueueDestroyId(const FunctionCallbackInfo<Value>& args) {
+void AsyncWrap::QueueDestroyAsyncId(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsNumber());
- PushBackDestroyId(Environment::GetCurrent(args), args[0]->NumberValue());
+ PushBackDestroyAsyncId(Environment::GetCurrent(args), args[0]->NumberValue());
}
void AsyncWrap::AddWrapMethods(Environment* env,
@@ -476,8 +479,8 @@ void AsyncWrap::Initialize(Local<Object> target,
env->SetMethod(target, "pushAsyncIds", PushAsyncIds);
env->SetMethod(target, "popAsyncIds", PopAsyncIds);
env->SetMethod(target, "asyncIdStackSize", AsyncIdStackSize);
- env->SetMethod(target, "clearIdStack", ClearIdStack);
- env->SetMethod(target, "addIdToDestroyList", QueueDestroyId);
+ env->SetMethod(target, "clearAsyncIdStack", ClearAsyncIdStack);
+ env->SetMethod(target, "queueDestroyAsyncId", QueueDestroyAsyncId);
env->SetMethod(target, "enablePromiseHook", EnablePromiseHook);
env->SetMethod(target, "disablePromiseHook", DisablePromiseHook);
@@ -504,12 +507,12 @@ void AsyncWrap::Initialize(Local<Object> target,
//
// kAsyncUid: Maintains the state of the next unique id to be assigned.
//
- // kInitTriggerId: Write the id of the resource responsible for a handle's
- // creation just before calling the new handle's constructor. After the new
- // handle is constructed kInitTriggerId is set back to 0.
+ // kInitTriggerAsyncId: Write the id of the resource responsible for a
+ // handle's creation just before calling the new handle's constructor.
+ // After the new handle is constructed kInitTriggerAsyncId is set back to 0.
FORCE_SET_TARGET_FIELD(target,
- "async_uid_fields",
- env->async_hooks()->uid_fields().GetJSArray());
+ "async_id_fields",
+ env->async_hooks()->async_id_fields().GetJSArray());
Local<Object> constants = Object::New(isolate);
#define SET_HOOKS_CONSTANT(name) \
@@ -522,10 +525,10 @@ void AsyncWrap::Initialize(Local<Object> target,
SET_HOOKS_CONSTANT(kDestroy);
SET_HOOKS_CONSTANT(kPromiseResolve);
SET_HOOKS_CONSTANT(kTotals);
- SET_HOOKS_CONSTANT(kCurrentAsyncId);
- SET_HOOKS_CONSTANT(kCurrentTriggerId);
- SET_HOOKS_CONSTANT(kAsyncUidCntr);
- SET_HOOKS_CONSTANT(kInitTriggerId);
+ SET_HOOKS_CONSTANT(kExecutionAsyncId);
+ SET_HOOKS_CONSTANT(kTriggerAsyncId);
+ SET_HOOKS_CONSTANT(kAsyncIdCounter);
+ SET_HOOKS_CONSTANT(kInitTriggerAsyncId);
#undef SET_HOOKS_CONSTANT
FORCE_SET_TARGET_FIELD(target, "constants", constants);
@@ -545,8 +548,8 @@ void AsyncWrap::Initialize(Local<Object> target,
Symbol::New(isolate, FIXED_ONE_BYTE_STRING(isolate, "asyncId")));
FORCE_SET_TARGET_FIELD(
target,
- "trigger_id_symbol",
- Symbol::New(isolate, FIXED_ONE_BYTE_STRING(isolate, "triggerId")));
+ "trigger_async_id_symbol",
+ Symbol::New(isolate, FIXED_ONE_BYTE_STRING(isolate, "triggerAsyncId")));
#undef FORCE_SET_TARGET_FIELD
@@ -586,7 +589,7 @@ AsyncWrap::AsyncWrap(Environment* env,
AsyncWrap::~AsyncWrap() {
- PushBackDestroyId(env(), get_id());
+ PushBackDestroyAsyncId(env(), get_async_id());
}
@@ -595,13 +598,13 @@ AsyncWrap::~AsyncWrap() {
// the resource is pulled out of the pool and put back into use.
void AsyncWrap::AsyncReset(bool silent) {
async_id_ = env()->new_async_id();
- trigger_id_ = env()->get_init_trigger_id();
+ trigger_async_id_ = env()->get_init_trigger_async_id();
if (silent) return;
EmitAsyncInit(env(), object(),
env()->async_hooks()->provider_string(provider_type()),
- async_id_, trigger_id_);
+ async_id_, trigger_async_id_);
}
@@ -609,7 +612,7 @@ void AsyncWrap::EmitAsyncInit(Environment* env,
Local<Object> object,
Local<String> type,
double async_id,
- double trigger_id) {
+ double trigger_async_id) {
CHECK(!object.IsEmpty());
CHECK(!type.IsEmpty());
AsyncHooks* async_hooks = env->async_hooks();
@@ -625,7 +628,7 @@ void AsyncWrap::EmitAsyncInit(Environment* env,
Local<Value> argv[] = {
Number::New(env->isolate(), async_id),
type,
- Number::New(env->isolate(), trigger_id),
+ Number::New(env->isolate(), trigger_async_id),
object,
};
@@ -643,7 +646,7 @@ void AsyncWrap::EmitAsyncInit(Environment* env,
MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
int argc,
Local<Value>* argv) {
- async_context context { get_id(), get_trigger_id() };
+ async_context context { get_async_id(), get_trigger_async_id() };
return InternalMakeCallback(env(), object(), cb, argc, argv, context);
}
@@ -652,12 +655,12 @@ MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
async_id AsyncHooksGetExecutionAsyncId(Isolate* isolate) {
- return Environment::GetCurrent(isolate)->current_async_id();
+ return Environment::GetCurrent(isolate)->execution_async_id();
}
async_id AsyncHooksGetTriggerAsyncId(Isolate* isolate) {
- return Environment::GetCurrent(isolate)->trigger_id();
+ return Environment::GetCurrent(isolate)->trigger_async_id();
}
@@ -679,7 +682,7 @@ async_context EmitAsyncInit(Isolate* isolate,
// Initialize async context struct
if (trigger_async_id == -1)
- trigger_async_id = env->get_init_trigger_id();
+ trigger_async_id = env->get_init_trigger_async_id();
async_context context = {
env->new_async_id(), // async_id_
@@ -694,7 +697,8 @@ async_context EmitAsyncInit(Isolate* isolate,
}
void EmitAsyncDestroy(Isolate* isolate, async_context asyncContext) {
- PushBackDestroyId(Environment::GetCurrent(isolate), asyncContext.async_id);
+ PushBackDestroyAsyncId(Environment::GetCurrent(isolate),
+ asyncContext.async_id);
}
} // namespace node
diff --git a/src/async-wrap.h b/src/async-wrap.h
index dd9d038582..e860afb905 100644
--- a/src/async-wrap.h
+++ b/src/async-wrap.h
@@ -111,15 +111,17 @@ class AsyncWrap : public BaseObject {
static void PushAsyncIds(const v8::FunctionCallbackInfo<v8::Value>& args);
static void PopAsyncIds(const v8::FunctionCallbackInfo<v8::Value>& args);
static void AsyncIdStackSize(const v8::FunctionCallbackInfo<v8::Value>& args);
- static void ClearIdStack(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void ClearAsyncIdStack(
+ const v8::FunctionCallbackInfo<v8::Value>& args);
static void AsyncReset(const v8::FunctionCallbackInfo<v8::Value>& args);
- static void QueueDestroyId(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void QueueDestroyAsyncId(
+ const v8::FunctionCallbackInfo<v8::Value>& args);
static void EmitAsyncInit(Environment* env,
v8::Local<v8::Object> object,
v8::Local<v8::String> type,
double id,
- double trigger_id);
+ double trigger_async_id);
static void EmitBefore(Environment* env, double id);
static void EmitAfter(Environment* env, double id);
@@ -127,9 +129,9 @@ class AsyncWrap : public BaseObject {
inline ProviderType provider_type() const;
- inline double get_id() const;
+ inline double get_async_id() const;
- inline double get_trigger_id() const;
+ inline double get_trigger_async_id() const;
void AsyncReset(bool silent = false);
@@ -152,7 +154,7 @@ class AsyncWrap : public BaseObject {
const ProviderType provider_type_;
// Because the values may be Reset(), cannot be made const.
double async_id_;
- double trigger_id_;
+ double trigger_async_id_;
};
void LoadAsyncWrapperInfo(Environment* env);
diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc
index da65c49316..d894ef6cc0 100644
--- a/src/connection_wrap.cc
+++ b/src/connection_wrap.cc
@@ -51,7 +51,7 @@ void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,
};
if (status == 0) {
- env->set_init_trigger_id(wrap_data->get_id());
+ env->set_init_trigger_async_id(wrap_data->get_async_id());
// Instantiate the client javascript object and handle.
Local<Object> client_obj = WrapType::Instantiate(env, wrap_data);
diff --git a/src/env-inl.h b/src/env-inl.h
index 28512003f0..0297e66977 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -85,12 +85,12 @@ inline uint32_t* IsolateData::zero_fill_field() const {
inline Environment::AsyncHooks::AsyncHooks(v8::Isolate* isolate)
: isolate_(isolate),
fields_(isolate, kFieldsCount),
- uid_fields_(isolate, kUidFieldsCount) {
+ async_id_fields_(isolate, kUidFieldsCount) {
v8::HandleScope handle_scope(isolate_);
- // kAsyncUidCntr should start at 1 because that'll be the id the execution
+ // kAsyncIdCounter should start at 1 because that'll be the id the execution
// context during bootstrap (code that runs before entering uv_run()).
- uid_fields_[AsyncHooks::kAsyncUidCntr] = 1;
+ async_id_fields_[AsyncHooks::kAsyncIdCounter] = 1;
// Create all the provider strings that will be passed to JS. Place them in
// an array so the array index matches the PROVIDER id offset. This way the
@@ -117,11 +117,11 @@ inline int Environment::AsyncHooks::fields_count() const {
}
inline AliasedBuffer<double, v8::Float64Array>&
-Environment::AsyncHooks::uid_fields() {
- return uid_fields_;
+Environment::AsyncHooks::async_id_fields() {
+ return async_id_fields_;
}
-inline int Environment::AsyncHooks::uid_fields_count() const {
+inline int Environment::AsyncHooks::async_id_fields_count() const {
return kUidFieldsCount;
}
@@ -129,29 +129,29 @@ inline v8::Local<v8::String> Environment::AsyncHooks::provider_string(int idx) {
return providers_[idx].Get(isolate_);
}
-inline void Environment::AsyncHooks::push_ids(double async_id,
- double trigger_id) {
+inline void Environment::AsyncHooks::push_async_ids(double async_id,
+ double trigger_async_id) {
CHECK_GE(async_id, -1);
- CHECK_GE(trigger_id, -1);
+ CHECK_GE(trigger_async_id, -1);
- ids_stack_.push({ uid_fields_[kCurrentAsyncId],
- uid_fields_[kCurrentTriggerId] });
- uid_fields_[kCurrentAsyncId] = async_id;
- uid_fields_[kCurrentTriggerId] = trigger_id;
+ async_ids_stack_.push({ async_id_fields_[kExecutionAsyncId],
+ async_id_fields_[kTriggerAsyncId] });
+ async_id_fields_[kExecutionAsyncId] = async_id;
+ async_id_fields_[kTriggerAsyncId] = trigger_async_id;
}
-inline bool Environment::AsyncHooks::pop_ids(double async_id) {
+inline bool Environment::AsyncHooks::pop_async_id(double async_id) {
// In case of an exception then this may have already been reset, if the
// stack was multiple MakeCallback()'s deep.
- if (ids_stack_.empty()) return false;
+ if (async_ids_stack_.empty()) return false;
// Ask for the async_id to be restored as a sanity check that the stack
// hasn't been corrupted.
- if (uid_fields_[kCurrentAsyncId] != async_id) {
+ if (async_id_fields_[kExecutionAsyncId] != async_id) {
fprintf(stderr,
"Error: async hook stack has become corrupted ("
"actual: %.f, expected: %.f)\n",
- uid_fields_.GetValue(kCurrentAsyncId),
+ async_id_fields_.GetValue(kExecutionAsyncId),
async_id);
Environment* env = Environment::GetCurrent(isolate_);
DumpBacktrace(stderr);
@@ -163,35 +163,37 @@ inline bool Environment::AsyncHooks::pop_ids(double async_id) {
ABORT_NO_BACKTRACE();
}
- auto ids = ids_stack_.top();
- ids_stack_.pop();
- uid_fields_[kCurrentAsyncId] = ids.async_id;
- uid_fields_[kCurrentTriggerId] = ids.trigger_id;
- return !ids_stack_.empty();
+ auto async_ids = async_ids_stack_.top();
+ async_ids_stack_.pop();
+ async_id_fields_[kExecutionAsyncId] = async_ids.async_id;
+ async_id_fields_[kTriggerAsyncId] = async_ids.trigger_async_id;
+ return !async_ids_stack_.empty();
}
inline size_t Environment::AsyncHooks::stack_size() {
- return ids_stack_.size();
+ return async_ids_stack_.size();
}
-inline void Environment::AsyncHooks::clear_id_stack() {
- while (!ids_stack_.empty())
- ids_stack_.pop();
- uid_fields_[kCurrentAsyncId] = 0;
- uid_fields_[kCurrentTriggerId] = 0;
+inline void Environment::AsyncHooks::clear_async_id_stack() {
+ while (!async_ids_stack_.empty())
+ async_ids_stack_.pop();
+ async_id_fields_[kExecutionAsyncId] = 0;
+ async_id_fields_[kTriggerAsyncId] = 0;
}
inline Environment::AsyncHooks::InitScope::InitScope(
- Environment* env, double init_trigger_id)
+ Environment* env, double init_trigger_async_id)
: env_(env),
- uid_fields_ref_(env->async_hooks()->uid_fields()) {
- CHECK_GE(init_trigger_id, -1);
- env->async_hooks()->push_ids(uid_fields_ref_[AsyncHooks::kCurrentAsyncId],
- init_trigger_id);
+ async_id_fields_ref_(env->async_hooks()->async_id_fields()) {
+ CHECK_GE(init_trigger_async_id, -1);
+ env->async_hooks()->push_async_ids(
+ async_id_fields_ref_[AsyncHooks::kExecutionAsyncId],
+ init_trigger_async_id);
}
inline Environment::AsyncHooks::InitScope::~InitScope() {
- env_->async_hooks()->pop_ids(uid_fields_ref_[AsyncHooks::kCurrentAsyncId]);
+ env_->async_hooks()->pop_async_id(
+ async_id_fields_ref_[AsyncHooks::kExecutionAsyncId]);
}
inline Environment::AsyncCallbackScope::AsyncCallbackScope(Environment* env)
@@ -306,7 +308,7 @@ inline Environment::Environment(IsolateData* isolate_data,
AssignToContext(context);
- destroy_ids_list_.reserve(512);
+ destroy_async_id_list_.reserve(512);
performance_state_ = Calloc<performance::performance_state>(1);
performance_state_->milestones[
performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT] =
@@ -358,13 +360,13 @@ inline uv_idle_t* Environment::immediate_idle_handle() {
return &immediate_idle_handle_;
}
-inline Environment* Environment::from_destroy_ids_timer_handle(
+inline Environment* Environment::from_destroy_async_ids_timer_handle(
uv_timer_t* handle) {
- return ContainerOf(&Environment::destroy_ids_timer_handle_, handle);
+ return ContainerOf(&Environment::destroy_async_ids_timer_handle_, handle);
}
-inline uv_timer_t* Environment::destroy_ids_timer_handle() {
- return &destroy_ids_timer_handle_;
+inline uv_timer_t* Environment::destroy_async_ids_timer_handle() {
+ return &destroy_async_ids_timer_handle_;
}
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
@@ -425,35 +427,35 @@ inline void Environment::set_abort_on_uncaught_exception(bool value) {
abort_on_uncaught_exception_ = value;
}
-inline std::vector<double>* Environment::destroy_ids_list() {
- return &destroy_ids_list_;
+inline std::vector<double>* Environment::destroy_async_id_list() {
+ return &destroy_async_id_list_;
}
inline double Environment::new_async_id() {
- async_hooks()->uid_fields()[AsyncHooks::kAsyncUidCntr] =
- async_hooks()->uid_fields()[AsyncHooks::kAsyncUidCntr] + 1;
- return async_hooks()->uid_fields()[AsyncHooks::kAsyncUidCntr];
+ async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter] =
+ async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter] + 1;
+ return async_hooks()->async_id_fields()[AsyncHooks::kAsyncIdCounter];
}
-inline double Environment::current_async_id() {
- return async_hooks()->uid_fields()[AsyncHooks::kCurrentAsyncId];
+inline double Environment::execution_async_id() {
+ return async_hooks()->async_id_fields()[AsyncHooks::kExecutionAsyncId];
}
-inline double Environment::trigger_id() {
- return async_hooks()->uid_fields()[AsyncHooks::kCurrentTriggerId];
+inline double Environment::trigger_async_id() {
+ return async_hooks()->async_id_fields()[AsyncHooks::kTriggerAsyncId];
}
-inline double Environment::get_init_trigger_id() {
- AliasedBuffer<double, v8::Float64Array>& uid_fields =
- async_hooks()->uid_fields();
- double tid = uid_fields[AsyncHooks::kInitTriggerId];
- uid_fields[AsyncHooks::kInitTriggerId] = 0;
- if (tid <= 0) tid = current_async_id();
+inline double Environment::get_init_trigger_async_id() {
+ AliasedBuffer<double, v8::Float64Array>& async_id_fields =
+ async_hooks()->async_id_fields();
+ double tid = async_id_fields[AsyncHooks::kInitTriggerAsyncId];
+ async_id_fields[AsyncHooks::kInitTriggerAsyncId] = 0;
+ if (tid <= 0) tid = execution_async_id();
return tid;
}
-inline void Environment::set_init_trigger_id(const double id) {
- async_hooks()->uid_fields()[AsyncHooks::kInitTriggerId] = id;
+inline void Environment::set_init_trigger_async_id(const double id) {
+ async_hooks()->async_id_fields()[AsyncHooks::kInitTriggerAsyncId] = id;
}
inline double* Environment::heap_statistics_buffer() const {
diff --git a/src/env.cc b/src/env.cc
index 25d80ba1e8..a0d82986c9 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -48,7 +48,7 @@ void Environment::Start(int argc,
uv_unref(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_));
uv_unref(reinterpret_cast<uv_handle_t*>(&idle_check_handle_));
- uv_timer_init(event_loop(), destroy_ids_timer_handle());
+ uv_timer_init(event_loop(), destroy_async_ids_timer_handle());
auto close_and_finish = [](Environment* env, uv_handle_t* handle, void* arg) {
handle->data = env;
@@ -75,7 +75,7 @@ void Environment::Start(int argc,
close_and_finish,
nullptr);
RegisterHandleCleanup(
- reinterpret_cast<uv_handle_t*>(&destroy_ids_timer_handle_),
+ reinterpret_cast<uv_handle_t*>(&destroy_async_ids_timer_handle_),
close_and_finish,
nullptr);
diff --git a/src/env.h b/src/env.h
index 25db2e14e9..ef4874057a 100644
--- a/src/env.h
+++ b/src/env.h
@@ -332,7 +332,7 @@ class Environment;
struct node_async_ids {
double async_id;
- double trigger_id;
+ double trigger_async_id;
};
class IsolateData {
@@ -388,10 +388,10 @@ class Environment {
};
enum UidFields {
- kCurrentAsyncId,
- kCurrentTriggerId,
- kAsyncUidCntr,
- kInitTriggerId,
+ kExecutionAsyncId,
+ kTriggerAsyncId,
+ kAsyncIdCounter,
+ kInitTriggerAsyncId,
kUidFieldsCount,
};
@@ -400,28 +400,28 @@ class Environment {
inline AliasedBuffer<uint32_t, v8::Uint32Array>& fields();
inline int fields_count() const;
- inline AliasedBuffer<double, v8::Float64Array>& uid_fields();
- inline int uid_fields_count() const;
+ inline AliasedBuffer<double, v8::Float64Array>& async_id_fields();
+ inline int async_id_fields_count() const;
inline v8::Local<v8::String> provider_string(int idx);
- inline void push_ids(double async_id, double trigger_id);
- inline bool pop_ids(double async_id);
+ inline void push_async_ids(double async_id, double trigger_async_id);
+ inline bool pop_async_id(double async_id);
inline size_t stack_size();
- inline void clear_id_stack(); // Used in fatal exceptions.
+ inline void clear_async_id_stack(); // Used in fatal exceptions.
- // Used to propagate the trigger_id to the constructor of any newly created
- // resources using RAII. Instead of needing to pass the trigger_id along
- // with other constructor arguments.
+ // Used to propagate the trigger_async_id to the constructor of any newly
+ // created resources using RAII. Instead of needing to pass the
+ // trigger_async_id along with other constructor arguments.
class InitScope {
public:
InitScope() = delete;
- explicit InitScope(Environment* env, double init_trigger_id);
+ explicit InitScope(Environment* env, double init_trigger_async_id);
~InitScope();
private:
Environment* env_;
- AliasedBuffer<double, v8::Float64Array> uid_fields_ref_;
+ AliasedBuffer<double, v8::Float64Array> async_id_fields_ref_;
DISALLOW_COPY_AND_ASSIGN(InitScope);
};
@@ -434,12 +434,12 @@ class Environment {
// Used by provider_string().
v8::Isolate* isolate_;
// Stores the ids of the current execution context stack.
- std::stack<struct node_async_ids> ids_stack_;
+ std::stack<struct node_async_ids> async_ids_stack_;
// Attached to a Uint32Array that tracks the number of active hooks for
// each type.
AliasedBuffer<uint32_t, v8::Uint32Array> fields_;
// Attached to a Float64Array that tracks the state of async resources.
- AliasedBuffer<double, v8::Float64Array> uid_fields_;
+ AliasedBuffer<double, v8::Float64Array> async_id_fields_;
DISALLOW_COPY_AND_ASSIGN(AsyncHooks);
};
@@ -549,10 +549,11 @@ class Environment {
inline uint32_t watched_providers() const;
static inline Environment* from_immediate_check_handle(uv_check_t* handle);
- static inline Environment* from_destroy_ids_timer_handle(uv_timer_t* handle);
+ static inline Environment* from_destroy_async_ids_timer_handle(
+ uv_timer_t* handle);
inline uv_check_t* immediate_check_handle();
inline uv_idle_t* immediate_idle_handle();
- inline uv_timer_t* destroy_ids_timer_handle();
+ inline uv_timer_t* destroy_async_ids_timer_handle();
// Register clean-up cb to be called on environment destruction.
inline void RegisterHandleCleanup(uv_handle_t* handle,
@@ -581,13 +582,13 @@ class Environment {
// The necessary API for async_hooks.
inline double new_async_id();
- inline double current_async_id();
- inline double trigger_id();
- inline double get_init_trigger_id();
- inline void set_init_trigger_id(const double id);
+ inline double execution_async_id();
+ inline double trigger_async_id();
+ inline double get_init_trigger_async_id();
+ inline void set_init_trigger_async_id(const double id);
// List of id's that have been destroyed and need the destroy() cb called.
- inline std::vector<double>* destroy_ids_list();
+ inline std::vector<double>* destroy_async_id_list();
std::unordered_multimap<int, loader::ModuleWrap*> module_map;
@@ -686,7 +687,7 @@ class Environment {
IsolateData* const isolate_data_;
uv_check_t immediate_check_handle_;
uv_idle_t immediate_idle_handle_;
- uv_timer_t destroy_ids_timer_handle_;
+ uv_timer_t destroy_async_ids_timer_handle_;
uv_prepare_t idle_prepare_handle_;
uv_check_t idle_check_handle_;
@@ -700,7 +701,7 @@ class Environment {
bool abort_on_uncaught_exception_;
bool emit_napi_warning_;
size_t makecallback_cntr_;
- std::vector<double> destroy_ids_list_;
+ std::vector<double> destroy_async_id_list_;
performance::performance_state* performance_state_ = nullptr;
std::map<std::string, uint64_t> performance_marks_;
diff --git a/src/node.cc b/src/node.cc
index 541c5f5eec..1162a31a6f 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -1381,7 +1381,7 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
AsyncWrap::EmitBefore(env, asyncContext.async_id);
}
- env->async_hooks()->push_ids(async_context_.async_id,
+ env->async_hooks()->push_async_ids(async_context_.async_id,
async_context_.trigger_async_id);
pushed_ids_ = true;
}
@@ -1396,7 +1396,7 @@ void InternalCallbackScope::Close() {
HandleScope handle_scope(env_->isolate());
if (pushed_ids_)
- env_->async_hooks()->pop_ids(async_context_.async_id);
+ env_->async_hooks()->pop_async_id(async_context_.async_id);
if (failed_) return;
@@ -1420,8 +1420,8 @@ void InternalCallbackScope::Close() {
// Make sure the stack unwound properly. If there are nested MakeCallback's
// then it should return early and not reach this code.
- CHECK_EQ(env_->current_async_id(), 0);
- CHECK_EQ(env_->trigger_id(), 0);
+ CHECK_EQ(env_->execution_async_id(), 0);
+ CHECK_EQ(env_->trigger_async_id(), 0);
Local<Object> process = env_->process_object();
@@ -1430,8 +1430,8 @@ void InternalCallbackScope::Close() {
return;
}
- CHECK_EQ(env_->current_async_id(), 0);
- CHECK_EQ(env_->trigger_id(), 0);
+ CHECK_EQ(env_->execution_async_id(), 0);
+ CHECK_EQ(env_->trigger_async_id(), 0);
if (env_->tick_callback_function()->Call(process, 0, nullptr).IsEmpty()) {
failed_ = true;
@@ -4695,9 +4695,9 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
{
Environment::AsyncCallbackScope callback_scope(&env);
- env.async_hooks()->push_ids(1, 0);
+ env.async_hooks()->push_async_ids(1, 0);
LoadEnvironment(&env);
- env.async_hooks()->pop_ids(1);
+ env.async_hooks()->pop_async_id(1);
}
env.set_trace_sync_io(trace_sync_io);
diff --git a/src/node.h b/src/node.h
index 8d93fea7dc..287823b17b 100644
--- a/src/node.h
+++ b/src/node.h
@@ -556,7 +556,7 @@ NODE_EXTERN async_id AsyncHooksGetTriggerAsyncId(v8::Isolate* isolate);
/* If the native API doesn't inherit from the helper class then the callbacks
* must be triggered manually. This triggers the init() callback. The return
- * value is the uid assigned to the resource.
+ * value is the async id assigned to the resource.
*
* The `trigger_async_id` parameter should correspond to the resource which is
* creating the new resource, which will usually be the return value of
diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc
index dfe0028147..11d0aa42b2 100644
--- a/src/node_http_parser.cc
+++ b/src/node_http_parser.cc
@@ -479,7 +479,7 @@ class Parser : public AsyncWrap {
ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
// Should always be called from the same context.
CHECK_EQ(env, parser->env());
- // The parser is being reused. Reset the uid and call init() callbacks.
+ // The parser is being reused. Reset the async id and call init() callbacks.
parser->AsyncReset();
parser->Init(type);
}
diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc
index e29cf6d70f..bf1ddbdc0d 100644
--- a/src/pipe_wrap.cc
+++ b/src/pipe_wrap.cc
@@ -52,7 +52,7 @@ using AsyncHooks = Environment::AsyncHooks;
Local<Object> PipeWrap::Instantiate(Environment* env, AsyncWrap* parent) {
EscapableHandleScope handle_scope(env->isolate());
- AsyncHooks::InitScope init_scope(env, parent->get_id());
+ AsyncHooks::InitScope init_scope(env, parent->get_async_id());
CHECK_EQ(false, env->pipe_constructor_template().IsEmpty());
Local<Function> constructor = env->pipe_constructor_template()->GetFunction();
CHECK_EQ(false, constructor.IsEmpty());
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h
index 8b5b154207..25293d2d06 100644
--- a/src/stream_base-inl.h
+++ b/src/stream_base-inl.h
@@ -136,7 +136,7 @@ void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) {
if (!wrap->IsAlive())
return args.GetReturnValue().Set(UV_EINVAL);
- AsyncHooks::InitScope init_scope(handle->env(), handle->get_id());
+ AsyncHooks::InitScope init_scope(handle->env(), handle->get_async_id());
args.GetReturnValue().Set((wrap->*Method)(args));
}
diff --git a/src/stream_base.cc b/src/stream_base.cc
index 51bad94a4f..d753dea318 100644
--- a/src/stream_base.cc
+++ b/src/stream_base.cc
@@ -55,7 +55,7 @@ int StreamBase::Shutdown(const FunctionCallbackInfo<Value>& args) {
AsyncWrap* wrap = GetAsyncWrap();
CHECK_NE(wrap, nullptr);
- env->set_init_trigger_id(wrap->get_id());
+ env->set_init_trigger_async_id(wrap->get_async_id());
ShutdownWrap* req_wrap = new ShutdownWrap(env,
req_wrap_obj,
this,
@@ -160,7 +160,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
wrap = GetAsyncWrap();
CHECK_NE(wrap, nullptr);
- env->set_init_trigger_id(wrap->get_id());
+ env->set_init_trigger_async_id(wrap->get_async_id());
req_wrap = WriteWrap::New(env, req_wrap_obj, this, AfterWrite, storage_size);
offset = 0;
@@ -249,7 +249,7 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
wrap = GetAsyncWrap();
if (wrap != nullptr)
- env->set_init_trigger_id(wrap->get_id());
+ env->set_init_trigger_async_id(wrap->get_async_id());
// Allocate, or write rest
req_wrap = WriteWrap::New(env, req_wrap_obj, this, AfterWrite);
@@ -334,7 +334,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
wrap = GetAsyncWrap();
if (wrap != nullptr)
- env->set_init_trigger_id(wrap->get_id());
+ env->set_init_trigger_async_id(wrap->get_async_id());
req_wrap = WriteWrap::New(env, req_wrap_obj, this, AfterWrite, storage_size);
data = req_wrap->Extra();
diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc
index 2c2aeab6dd..2bbc350dd5 100644
--- a/src/tcp_wrap.cc
+++ b/src/tcp_wrap.cc
@@ -55,7 +55,7 @@ using AsyncHooks = Environment::AsyncHooks;
Local<Object> TCPWrap::Instantiate(Environment* env, AsyncWrap* parent) {
EscapableHandleScope handle_scope(env->isolate());
- AsyncHooks::InitScope init_scope(env, parent->get_id());
+ AsyncHooks::InitScope init_scope(env, parent->get_async_id());
CHECK_EQ(env->tcp_constructor_template().IsEmpty(), false);
Local<Function> constructor = env->tcp_constructor_template()->GetFunction();
CHECK_EQ(constructor.IsEmpty(), false);
@@ -268,7 +268,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
int err = uv_ip4_addr(*ip_address, port, &addr);
if (err == 0) {
- env->set_init_trigger_id(wrap->get_id());
+ env->set_init_trigger_async_id(wrap->get_async_id());
ConnectWrap* req_wrap =
new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP);
err = uv_tcp_connect(req_wrap->req(),
@@ -304,7 +304,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
int err = uv_ip6_addr(*ip_address, port, &addr);
if (err == 0) {
- env->set_init_trigger_id(wrap->get_id());
+ env->set_init_trigger_async_id(wrap->get_async_id());
ConnectWrap* req_wrap =
new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP);
err = uv_tcp_connect(req_wrap->req(),
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc
index 5fb8daed74..98399155a8 100644
--- a/src/udp_wrap.cc
+++ b/src/udp_wrap.cc
@@ -350,7 +350,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
node::Utf8Value address(env->isolate(), args[4]);
const bool have_callback = args[5]->IsTrue();
- env->set_init_trigger_id(wrap->get_id());
+ env->set_init_trigger_async_id(wrap->get_async_id());
SendWrap* req_wrap = new SendWrap(env, req_wrap_obj, have_callback);
size_t msg_size = 0;
@@ -498,7 +498,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
Local<Object> UDPWrap::Instantiate(Environment* env, AsyncWrap* parent) {
EscapableHandleScope scope(env->isolate());
- AsyncHooks::InitScope init_scope(env, parent->get_id());
+ AsyncHooks::InitScope init_scope(env, parent->get_async_id());
// If this assert fires then Initialize hasn't been called yet.
CHECK_EQ(env->udp_constructor_function().IsEmpty(), false);
Local<Object> instance = env->udp_constructor_function()