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