| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c004cf5 commit ec3c39f
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,6 @@ AsyncResource::AsyncResource(Isolate* isolate, | |||
| 24 | 24 | ||
| 25 | 25 | AsyncResource::~AsyncResource() { | |
| 26 | 26 | EmitAsyncDestroy(env_, async_context_); | |
| 27 | - resource_.Reset(); | ||
| 28 | 27 | } | |
| 29 | 28 | ||
| 30 | 29 | MaybeLocal<Value> AsyncResource::MakeCallback(Local<Function> callback, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -870,7 +870,7 @@ class NODE_EXTERN AsyncResource { | |||
| 870 | 870 | ||
| 871 | 871 | private: | |
| 872 | 872 | Environment* env_; | |
| 873 | - v8::Persistent<v8::Object> resource_; | ||
| 873 | + v8::Global<v8::Object> resource_; | ||
| 874 | 874 | async_context async_context_; | |
| 875 | 875 | }; | |
| 876 | 876 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ struct async_req { | |||
| 14 | 14 | int input; | |
| 15 | 15 | int output; | |
| 16 | 16 | v8::Isolate* isolate; | |
| 17 | - v8::Persistent<v8::Function> callback; | ||
| 17 | + v8::Global<v8::Function> callback; | ||
| 18 | 18 | node::async_context context; | |
| 19 | 19 | }; | |
| 20 | 20 | ||
@@ -61,7 +61,6 @@ void AfterAsync(uv_work_t* r) { | |||
| 61 | 61 | v8::SealHandleScope seal_handle_scope(isolate); | |
| 62 | 62 | // cleanup | |
| 63 | 63 | node::EmitAsyncDestroy(isolate, req->context); | |
| 64 | - req->callback.Reset(); | ||
| 65 | 64 | delete req; | |
| 66 | 65 | ||
| 67 | 66 | if (try_catch.HasCaught()) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | #include <assert.h> | |
| 6 | 6 | #include <vector> | |
| 7 | + #include <memory> | ||
| 7 | 8 | ||
| 8 | 9 | namespace { | |
| 9 | 10 | ||
@@ -31,16 +32,14 @@ void RunInCallbackScope(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
| 31 | 32 | args.GetReturnValue().Set(ret.ToLocalChecked()); | |
| 32 | 33 | } | |
| 33 | 34 | ||
| 34 | - static v8::Persistent<v8::Promise::Resolver> persistent; | ||
| 35 | - | ||
| 36 | 35 | static void Callback(uv_work_t* req, int ignored) { | |
| 37 | 36 | v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 38 | 37 | v8::HandleScope scope(isolate); | |
| 39 | 38 | node::CallbackScope callback_scope(isolate, v8::Object::New(isolate), | |
| 40 | 39 | node::async_context{0, 0}); | |
| 41 | - | ||
| 42 | - v8::Local<v8::Promise::Resolver> local = | ||
| 43 | - v8::Local<v8::Promise::Resolver>::New(isolate, persistent); | ||
| 40 | + std::unique_ptr<v8::Global<v8::Promise::Resolver>> persistent { | ||
| 41 | + static_cast<v8::Global<v8::Promise::Resolver>*>(req->data) }; | ||
| 42 | + v8::Local<v8::Promise::Resolver> local = persistent->Get(isolate); | ||
| 44 | 43 | local->Resolve(isolate->GetCurrentContext(), | |
| 45 | 44 | v8::Undefined(isolate)).ToChecked(); | |
| 46 | 45 | delete req; | |
@@ -49,20 +48,21 @@ static void Callback(uv_work_t* req, int ignored) { | |||
| 49 | 48 | static void TestResolveAsync(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 50 | 49 | v8::Isolate* isolate = args.GetIsolate(); | |
| 51 | 50 | ||
| 52 | - if (persistent.IsEmpty()) { | ||
| 53 | - persistent.Reset(isolate, v8::Promise::Resolver::New( | ||
| 54 | - isolate->GetCurrentContext()).ToLocalChecked()); | ||
| 51 | + v8::Global<v8::Promise::Resolver>* persistent = | ||
| 52 | + new v8::Global<v8::Promise::Resolver>( | ||
| 53 | + isolate, | ||
| 54 | + v8::Promise::Resolver::New( | ||
| 55 | + isolate->GetCurrentContext()).ToLocalChecked()); | ||
| 55 | 56 | ||
| 56 | - uv_work_t* req = new uv_work_t; | ||
| 57 | + uv_work_t* req = new uv_work_t; | ||
| 58 | + req->data = static_cast<void*>(persistent); | ||
| 57 | 59 | ||
| 58 | - uv_queue_work(node::GetCurrentEventLoop(isolate), | ||
| 59 | - req, | ||
| 60 | - [](uv_work_t*) {}, | ||
| 61 | - Callback); | ||
| 62 | - } | ||
| 60 | + uv_queue_work(node::GetCurrentEventLoop(isolate), | ||
| 61 | + req, | ||
| 62 | + [](uv_work_t*) {}, | ||
| 63 | + Callback); | ||
| 63 | 64 | ||
| 64 | - v8::Local<v8::Promise::Resolver> local = | ||
| 65 | - v8::Local<v8::Promise::Resolver>::New(isolate, persistent); | ||
| 65 | + v8::Local<v8::Promise::Resolver> local = persistent->Get(isolate); | ||
| 66 | 66 | ||
| 67 | 67 | args.GetReturnValue().Set(local->GetPromise()); | |
| 68 | 68 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments