| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eb9d0ba commit 840a2ea
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ struct async_req { | |||
| 15 | 15 | int output; | |
| 16 | 16 | v8::Isolate* isolate; | |
| 17 | 17 | v8::Persistent<v8::Function> callback; | |
| 18 | + node::async_context context; | ||
| 18 | 19 | }; | |
| 19 | 20 | ||
| 20 | 21 | void DoAsync(uv_work_t* r) { | |
@@ -47,14 +48,16 @@ void AfterAsync(uv_work_t* r) { | |||
| 47 | 48 | ||
| 48 | 49 | if (use_makecallback) { | |
| 49 | 50 | v8::Local<v8::Value> ret = | |
| 50 | - node::MakeCallback(isolate, global, callback, 2, argv); | ||
| 51 | + node::MakeCallback(isolate, global, callback, 2, argv, req->context) | ||
| 52 | + .ToLocalChecked(); | ||
| 51 | 53 | // This should be changed to an empty handle. | |
| 52 | 54 | assert(!ret.IsEmpty()); | |
| 53 | 55 | } else { | |
| 54 | 56 | callback->Call(global, 2, argv); | |
| 55 | 57 | } | |
| 56 | 58 | ||
| 57 | 59 | // cleanup | |
| 60 | + node::EmitAsyncDestroy(isolate, req->context); | ||
| 58 | 61 | req->callback.Reset(); | |
| 59 | 62 | delete req; | |
| 60 | 63 | ||
@@ -73,6 +76,7 @@ void Method(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
| 73 | 76 | req->input = args[0]->IntegerValue(); | |
| 74 | 77 | req->output = 0; | |
| 75 | 78 | req->isolate = isolate; | |
| 79 | + req->context = node::EmitAsyncInit(isolate, v8::Object::New(isolate), "test"); | ||
| 76 | 80 | ||
| 77 | 81 | v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(args[1]); | |
| 78 | 82 | req->callback.Reset(isolate, callback); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,8 @@ static v8::Persistent<v8::Promise::Resolver> persistent; | |||
| 36 | 36 | static void Callback(uv_work_t* req, int ignored) { | |
| 37 | 37 | v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 38 | 38 | v8::HandleScope scope(isolate); | |
| 39 | - node::CallbackScope callback_scope(isolate, v8::Object::New(isolate), {0, 0}); | ||
| 39 | + node::CallbackScope callback_scope(isolate, v8::Object::New(isolate), | ||
| 40 | + node::async_context{0, 0}); | ||
| 40 | 41 | ||
| 41 | 42 | v8::Local<v8::Promise::Resolver> local = | |
| 42 | 43 | v8::Local<v8::Promise::Resolver>::New(isolate, persistent); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,8 @@ void MakeCallback(const FunctionCallbackInfo<Value>& args) { | |||
| 19 | 19 | Local<Object> recv = args[0].As<Object>(); | |
| 20 | 20 | Local<Function> method = args[1].As<Function>(); | |
| 21 | 21 | ||
| 22 | - node::MakeCallback(isolate, recv, method, 0, nullptr); | ||
| 22 | + node::MakeCallback(isolate, recv, method, 0, nullptr, | ||
| 23 | + node::async_context{0, 0}); | ||
| 23 | 24 | } | |
| 24 | 25 | ||
| 25 | 26 | void Initialize(Local<Object> exports) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,11 +19,13 @@ void MakeCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
| 19 | 19 | if (args[1]->IsFunction()) { | |
| 20 | 20 | auto method = args[1].As<v8::Function>(); | |
| 21 | 21 | result = | |
| 22 | - node::MakeCallback(isolate, recv, method, argv.size(), argv.data()); | ||
| 22 | + node::MakeCallback(isolate, recv, method, argv.size(), argv.data(), | ||
| 23 | + node::async_context{0, 0}).ToLocalChecked(); | ||
| 23 | 24 | } else if (args[1]->IsString()) { | |
| 24 | 25 | auto method = args[1].As<v8::String>(); | |
| 25 | 26 | result = | |
| 26 | - node::MakeCallback(isolate, recv, method, argv.size(), argv.data()); | ||
| 27 | + node::MakeCallback(isolate, recv, method, argv.size(), argv.data(), | ||
| 28 | + node::async_context{0, 0}).ToLocalChecked(); | ||
| 27 | 29 | } else { | |
| 28 | 30 | assert(0 && "unreachable"); | |
| 29 | 31 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,11 +36,10 @@ void Method(const FunctionCallbackInfo<Value>& args) { | |||
| 36 | 36 | Boolean::New(isolate, true), | |
| 37 | 37 | Boolean::New(isolate, false) | |
| 38 | 38 | }; | |
| 39 | - Local<Value> ret = node::MakeCallback(isolate, | ||
| 40 | - isolate->GetCurrentContext()->Global(), | ||
| 41 | - args[0].As<Function>(), | ||
| 42 | - 2, | ||
| 43 | - params); | ||
| 39 | + Local<Value> ret = | ||
| 40 | + node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), | ||
| 41 | + args[0].As<Function>(), 2, params, | ||
| 42 | + node::async_context{0, 0}).ToLocalChecked(); | ||
| 44 | 43 | assert(ret->IsTrue()); | |
| 45 | 44 | } | |
| 46 | 45 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments