11cb0ef41Sopenharmony_ci#include "node.h" 21cb0ef41Sopenharmony_ci#include "env-inl.h" 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cinamespace node { 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciusing v8::Function; 71cb0ef41Sopenharmony_ciusing v8::Isolate; 81cb0ef41Sopenharmony_ciusing v8::Local; 91cb0ef41Sopenharmony_ciusing v8::MaybeLocal; 101cb0ef41Sopenharmony_ciusing v8::Object; 111cb0ef41Sopenharmony_ciusing v8::String; 121cb0ef41Sopenharmony_ciusing v8::Value; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciAsyncResource::AsyncResource(Isolate* isolate, 151cb0ef41Sopenharmony_ci Local<Object> resource, 161cb0ef41Sopenharmony_ci const char* name, 171cb0ef41Sopenharmony_ci async_id trigger_async_id) 181cb0ef41Sopenharmony_ci : env_(Environment::GetCurrent(isolate)), 191cb0ef41Sopenharmony_ci resource_(isolate, resource) { 201cb0ef41Sopenharmony_ci CHECK_NOT_NULL(env_); 211cb0ef41Sopenharmony_ci async_context_ = EmitAsyncInit(isolate, resource, name, 221cb0ef41Sopenharmony_ci trigger_async_id); 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciAsyncResource::~AsyncResource() { 261cb0ef41Sopenharmony_ci EmitAsyncDestroy(env_, async_context_); 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciMaybeLocal<Value> AsyncResource::MakeCallback(Local<Function> callback, 301cb0ef41Sopenharmony_ci int argc, 311cb0ef41Sopenharmony_ci Local<Value>* argv) { 321cb0ef41Sopenharmony_ci return node::MakeCallback(env_->isolate(), get_resource(), 331cb0ef41Sopenharmony_ci callback, argc, argv, 341cb0ef41Sopenharmony_ci async_context_); 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ciMaybeLocal<Value> AsyncResource::MakeCallback(const char* method, 381cb0ef41Sopenharmony_ci int argc, 391cb0ef41Sopenharmony_ci Local<Value>* argv) { 401cb0ef41Sopenharmony_ci return node::MakeCallback(env_->isolate(), get_resource(), 411cb0ef41Sopenharmony_ci method, argc, argv, 421cb0ef41Sopenharmony_ci async_context_); 431cb0ef41Sopenharmony_ci} 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ciMaybeLocal<Value> AsyncResource::MakeCallback(Local<String> symbol, 461cb0ef41Sopenharmony_ci int argc, 471cb0ef41Sopenharmony_ci Local<Value>* argv) { 481cb0ef41Sopenharmony_ci return node::MakeCallback(env_->isolate(), get_resource(), 491cb0ef41Sopenharmony_ci symbol, argc, argv, 501cb0ef41Sopenharmony_ci async_context_); 511cb0ef41Sopenharmony_ci} 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ciLocal<Object> AsyncResource::get_resource() { 541cb0ef41Sopenharmony_ci return resource_.Get(env_->isolate()); 551cb0ef41Sopenharmony_ci} 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ciasync_id AsyncResource::get_async_id() const { 581cb0ef41Sopenharmony_ci return async_context_.async_id; 591cb0ef41Sopenharmony_ci} 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ciasync_id AsyncResource::get_trigger_async_id() const { 621cb0ef41Sopenharmony_ci return async_context_.trigger_async_id; 631cb0ef41Sopenharmony_ci} 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ciAsyncResource::CallbackScope::CallbackScope(AsyncResource* res) 661cb0ef41Sopenharmony_ci : node::CallbackScope(res->env_, 671cb0ef41Sopenharmony_ci res->resource_.Get(res->env_->isolate()), 681cb0ef41Sopenharmony_ci res->async_context_) {} 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci} // namespace node 71