@@ -81,8 +81,18 @@ inline v8::Isolate* Environment::IsolateData::isolate() const {
8181 return isolate_;
8282}
8383
84- inline Environment::AsyncHooks::AsyncHooks () {
84+ inline Environment::AsyncHooks::AsyncHooks (Environment* env)
85+ : async_wrap_uid_(0 ),
86+ env_(env) {
8587 for (int i = 0 ; i < kFieldsCount ; i++) fields_[i] = 0 ;
88+ const size_t array_length = sizeof (async_wrap_uid_) / sizeof (int32_t );
89+ static_assert (array_length == 2 , " async_wrap_uid_ unexpected size" );
90+ v8::HandleScope handle_scope (env_->isolate ());
91+ v8::Local<v8::ArrayBuffer> ab =
92+ v8::ArrayBuffer::New (env_->isolate (), &async_wrap_uid_, array_length);
93+ v8::Local<v8::Uint32Array> ua =
94+ v8::Uint32Array::New (ab, 0 , array_length);
95+ async_wrap_uid_array_.Reset (env_->isolate (), ua);
8696}
8797
8898inline uint32_t * Environment::AsyncHooks::fields () {
@@ -101,6 +111,14 @@ inline void Environment::AsyncHooks::set_enable_callbacks(uint32_t flag) {
101111 fields_[kEnableCallbacks ] = flag;
102112}
103113
114+ inline int64_t Environment::AsyncHooks::get_async_wrap_uid () {
115+ return ++async_wrap_uid_;
116+ }
117+
118+ inline v8::Local<v8::Uint32Array> Environment::AsyncHooks::get_uid_array () {
119+ return async_wrap_uid_array_.Get (env_->isolate ());
120+ }
121+
104122inline Environment::AsyncCallbackScope::AsyncCallbackScope (Environment* env)
105123 : env_(env) {
106124 env_->makecallback_cntr_ ++;
@@ -216,12 +234,12 @@ inline Environment::Environment(v8::Local<v8::Context> context,
216234 uv_loop_t * loop)
217235 : isolate_(context->GetIsolate ()),
218236 isolate_data_(IsolateData::GetOrCreate(context->GetIsolate (), loop)),
237+ async_hooks_(this ),
219238 timer_base_(uv_now(loop)),
220239 using_domains_(false ),
221240 printed_error_(false ),
222241 trace_sync_io_(false ),
223242 makecallback_cntr_(0 ),
224- async_wrap_uid_(0 ),
225243 debugger_agent_(this ),
226244 http_parser_buffer_(nullptr ),
227245 context_(context->GetIsolate (), context) {
@@ -373,7 +391,7 @@ inline void Environment::set_trace_sync_io(bool value) {
373391}
374392
375393inline int64_t Environment::get_async_wrap_uid () {
376- return ++async_wrap_uid_ ;
394+ return async_hooks ()-> get_async_wrap_uid () ;
377395}
378396
379397inline uint32_t * Environment::heap_statistics_buffer () const {
0 commit comments