1#include "node.h" 2#include "env-inl.h" 3 4namespace node { 5 6using v8::Function; 7using v8::Isolate; 8using v8::Local; 9using v8::MaybeLocal; 10using v8::Object; 11using v8::String; 12using v8::Value; 13 14AsyncResource::AsyncResource(Isolate* isolate, 15 Local<Object> resource, 16 const char* name, 17 async_id trigger_async_id) 18 : env_(Environment::GetCurrent(isolate)), 19 resource_(isolate, resource) { 20 CHECK_NOT_NULL(env_); 21 async_context_ = EmitAsyncInit(isolate, resource, name, 22 trigger_async_id); 23} 24 25AsyncResource::~AsyncResource() { 26 EmitAsyncDestroy(env_, async_context_); 27} 28 29MaybeLocal<Value> AsyncResource::MakeCallback(Local<Function> callback, 30 int argc, 31 Local<Value>* argv) { 32 return node::MakeCallback(env_->isolate(), get_resource(), 33 callback, argc, argv, 34 async_context_); 35} 36 37MaybeLocal<Value> AsyncResource::MakeCallback(const char* method, 38 int argc, 39 Local<Value>* argv) { 40 return node::MakeCallback(env_->isolate(), get_resource(), 41 method, argc, argv, 42 async_context_); 43} 44 45MaybeLocal<Value> AsyncResource::MakeCallback(Local<String> symbol, 46 int argc, 47 Local<Value>* argv) { 48 return node::MakeCallback(env_->isolate(), get_resource(), 49 symbol, argc, argv, 50 async_context_); 51} 52 53Local<Object> AsyncResource::get_resource() { 54 return resource_.Get(env_->isolate()); 55} 56 57async_id AsyncResource::get_async_id() const { 58 return async_context_.async_id; 59} 60 61async_id AsyncResource::get_trigger_async_id() const { 62 return async_context_.trigger_async_id; 63} 64 65AsyncResource::CallbackScope::CallbackScope(AsyncResource* res) 66 : node::CallbackScope(res->env_, 67 res->resource_.Get(res->env_->isolate()), 68 res->async_context_) {} 69 70} // namespace node 71