@@ -17,28 +17,23 @@ AsyncResource::AsyncResource(Isolate* isolate,
1717 const char * name,
1818 async_id trigger_async_id)
1919 : env_(Environment::GetCurrent(isolate)),
20- resource_ (isolate, resource) {
20+ resource_ (isolate, resource),
21+ context_frame_(isolate, async_context_frame::current(isolate)) {
2122 CHECK_NOT_NULL (env_);
22- env_->SetAsyncResourceContextFrame (
23- reinterpret_cast <std::uintptr_t >(this ),
24- {isolate, async_context_frame::current (isolate)});
2523 async_context_ = EmitAsyncInit (isolate, resource, name, trigger_async_id);
2624}
2725
2826AsyncResource::~AsyncResource () {
2927 CHECK_NOT_NULL (env_);
3028 EmitAsyncDestroy (env_, async_context_);
31- env_->RemoveAsyncResourceContextFrame (reinterpret_cast <std::uintptr_t >(this ));
3229}
3330
3431MaybeLocal<Value> AsyncResource::MakeCallback (Local<Function> callback,
3532 int argc,
3633 Local<Value>* argv) {
3734 auto isolate = env_->isolate ();
38- auto context_frame =
39- env_->GetAsyncResourceContextFrame (reinterpret_cast <std::uintptr_t >(this ))
40- .Get (isolate);
41- async_context_frame::Scope async_context_frame_scope (isolate, context_frame);
35+ async_context_frame::Scope async_context_frame_scope (
36+ isolate, context_frame_.Get (isolate));
4237
4338 return node::MakeCallback (
4439 isolate, get_resource (), callback, argc, argv, async_context_);
@@ -48,10 +43,8 @@ MaybeLocal<Value> AsyncResource::MakeCallback(const char* method,
4843 int argc,
4944 Local<Value>* argv) {
5045 auto isolate = env_->isolate ();
51- auto context_frame =
52- env_->GetAsyncResourceContextFrame (reinterpret_cast <std::uintptr_t >(this ))
53- .Get (isolate);
54- async_context_frame::Scope async_context_frame_scope (isolate, context_frame);
46+ async_context_frame::Scope async_context_frame_scope (
47+ isolate, context_frame_.Get (isolate));
5548
5649 return node::MakeCallback (
5750 isolate, get_resource (), method, argc, argv, async_context_);
@@ -61,10 +54,8 @@ MaybeLocal<Value> AsyncResource::MakeCallback(Local<String> symbol,
6154 int argc,
6255 Local<Value>* argv) {
6356 auto isolate = env_->isolate ();
64- auto context_frame =
65- env_->GetAsyncResourceContextFrame (reinterpret_cast <std::uintptr_t >(this ))
66- .Get (isolate);
67- async_context_frame::Scope async_context_frame_scope (isolate, context_frame);
57+ async_context_frame::Scope async_context_frame_scope (
58+ isolate, context_frame_.Get (isolate));
6859
6960 return node::MakeCallback (
7061 isolate, get_resource (), symbol, argc, argv, async_context_);
0 commit comments