diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2018-02-11 16:35:59 -0500 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2018-02-16 14:23:14 -0500 |
commit | e9ac80bb397293feef3b47f3ed609c86edb48681 (patch) | |
tree | 357523992d1b469f800e58853a3a79214633453e /src | |
parent | 7748865cd3322ff9421458ccc862291eb26cec62 (diff) | |
download | android-node-v8-e9ac80bb397293feef3b47f3ed609c86edb48681.tar.gz android-node-v8-e9ac80bb397293feef3b47f3ed609c86edb48681.tar.bz2 android-node-v8-e9ac80bb397293feef3b47f3ed609c86edb48681.zip |
async_hooks: clean up usage in internal code
Instead of exposing internals of async_hooks & async_wrap throughout
the code base, create necessary helper methods within the internal
async_hooks that allows easy usage by Node.js internals. This stops
every single internal user of async_hooks from importing a ton of
functions, constants and internal Aliased Buffers from C++ async_wrap.
Adds functions initHooksExist, afterHooksExist, and destroyHooksExist
to determine whether the related emit methods need to be triggered.
Adds clearDefaultTriggerAsyncId and clearAsyncIdStack on the JS side
as an alternative to always calling C++.
Moves async_id_symbol and trigger_async_id_symbol to internal
async_hooks as they are never used in C++.
Renames newUid to newAsyncId for added clarity of its purpose.
Adjusts usage throughout the codebase, as well as in a couple of tests.
PR-URL: https://github.com/nodejs/node/pull/18720
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/async_wrap.cc | 19 | ||||
-rw-r--r-- | src/async_wrap.h | 2 | ||||
-rw-r--r-- | src/env-inl.h | 1 |
3 files changed, 1 insertions, 21 deletions
diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 387f301248..7fa5f0ade9 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -47,7 +47,6 @@ using v8::PromiseHookType; using v8::PropertyCallbackInfo; using v8::RetainedObjectInfo; using v8::String; -using v8::Symbol; using v8::TryCatch; using v8::Undefined; using v8::Value; @@ -472,12 +471,6 @@ void AsyncWrap::PopAsyncIds(const FunctionCallbackInfo<Value>& args) { } -void AsyncWrap::ClearAsyncIdStack(const FunctionCallbackInfo<Value>& args) { - Environment* env = Environment::GetCurrent(args); - env->async_hooks()->clear_async_id_stack(); -} - - void AsyncWrap::AsyncReset(const FunctionCallbackInfo<Value>& args) { AsyncWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); @@ -512,7 +505,6 @@ void AsyncWrap::Initialize(Local<Object> target, env->SetMethod(target, "setupHooks", SetupHooks); env->SetMethod(target, "pushAsyncIds", PushAsyncIds); env->SetMethod(target, "popAsyncIds", PopAsyncIds); - env->SetMethod(target, "clearAsyncIdStack", ClearAsyncIdStack); env->SetMethod(target, "queueDestroyAsyncId", QueueDestroyAsyncId); env->SetMethod(target, "enablePromiseHook", EnablePromiseHook); env->SetMethod(target, "disablePromiseHook", DisablePromiseHook); @@ -581,17 +573,6 @@ void AsyncWrap::Initialize(Local<Object> target, #undef V FORCE_SET_TARGET_FIELD(target, "Providers", async_providers); - // These Symbols are used throughout node so the stored values on each object - // can be accessed easily across files. - FORCE_SET_TARGET_FIELD( - target, - "async_id_symbol", - Symbol::New(isolate, FIXED_ONE_BYTE_STRING(isolate, "asyncId"))); - FORCE_SET_TARGET_FIELD( - target, - "trigger_async_id_symbol", - Symbol::New(isolate, FIXED_ONE_BYTE_STRING(isolate, "triggerAsyncId"))); - #undef FORCE_SET_TARGET_FIELD env->set_async_hooks_init_function(Local<Function>()); diff --git a/src/async_wrap.h b/src/async_wrap.h index 1a5a347ba6..b7aed5d789 100644 --- a/src/async_wrap.h +++ b/src/async_wrap.h @@ -125,8 +125,6 @@ class AsyncWrap : public BaseObject { static void GetAsyncId(const v8::FunctionCallbackInfo<v8::Value>& args); static void PushAsyncIds(const v8::FunctionCallbackInfo<v8::Value>& args); static void PopAsyncIds(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 QueueDestroyAsyncId( const v8::FunctionCallbackInfo<v8::Value>& args); diff --git a/src/env-inl.h b/src/env-inl.h index 1e64a0fda5..2b2b0cba58 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -172,6 +172,7 @@ inline bool Environment::AsyncHooks::pop_async_id(double async_id) { return fields_[kStackLength] > 0; } +// Keep in sync with clearAsyncIdStack in lib/internal/async_hooks.js. inline void Environment::AsyncHooks::clear_async_id_stack() { async_id_fields_[kExecutionAsyncId] = 0; async_id_fields_[kTriggerAsyncId] = 0; |