mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
src,test: use v8::Global instead of v8::Persistent
This is in preparation for a lint rule forbidding usage of `v8::Persistent`. PR-URL: https://github.com/nodejs/node/pull/31018 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
This commit is contained in:
1 parent
c004cf51c6
commit
ec3c39f54b
4 files changed
+18
-20
No files matched your search
@@ -24,7 +24,6 @@ AsyncResource::AsyncResource(Isolate* isolate,
|
||||
|
||||
AsyncResource::~AsyncResource() {
|
||||
EmitAsyncDestroy(env_, async_context_);
|
||||
resource_.Reset();
|
||||
}
|
||||
|
||||
MaybeLocal<Value> AsyncResource::MakeCallback(Local<Function> callback,
|
||||
|
||||
+1
-1
@@ -870,7 +870,7 @@ class NODE_EXTERN AsyncResource {
|
||||
|
||||
private:
|
||||
Environment* env_;
|
||||
v8::Persistent<v8::Object> resource_;
|
||||
v8::Global<v8::Object> resource_;
|
||||
async_context async_context_;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ struct async_req {
|
||||
int input;
|
||||
int output;
|
||||
v8::Isolate* isolate;
|
||||
v8::Persistent<v8::Function> callback;
|
||||
v8::Global<v8::Function> callback;
|
||||
node::async_context context;
|
||||
};
|
||||
|
||||
@@ -61,7 +61,6 @@ void AfterAsync(uv_work_t* r) {
|
||||
v8::SealHandleScope seal_handle_scope(isolate);
|
||||
// cleanup
|
||||
node::EmitAsyncDestroy(isolate, req->context);
|
||||
req->callback.Reset();
|
||||
delete req;
|
||||
|
||||
if (try_catch.HasCaught()) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -31,16 +32,14 @@ void RunInCallbackScope(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
args.GetReturnValue().Set(ret.ToLocalChecked());
|
||||
}
|
||||
|
||||
static v8::Persistent<v8::Promise::Resolver> persistent;
|
||||
|
||||
static void Callback(uv_work_t* req, int ignored) {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope scope(isolate);
|
||||
node::CallbackScope callback_scope(isolate, v8::Object::New(isolate),
|
||||
node::async_context{0, 0});
|
||||
|
||||
v8::Local<v8::Promise::Resolver> local =
|
||||
v8::Local<v8::Promise::Resolver>::New(isolate, persistent);
|
||||
std::unique_ptr<v8::Global<v8::Promise::Resolver>> persistent {
|
||||
static_cast<v8::Global<v8::Promise::Resolver>*>(req->data) };
|
||||
v8::Local<v8::Promise::Resolver> local = persistent->Get(isolate);
|
||||
local->Resolve(isolate->GetCurrentContext(),
|
||||
v8::Undefined(isolate)).ToChecked();
|
||||
delete req;
|
||||
@@ -49,20 +48,21 @@ static void Callback(uv_work_t* req, int ignored) {
|
||||
static void TestResolveAsync(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
|
||||
if (persistent.IsEmpty()) {
|
||||
persistent.Reset(isolate, v8::Promise::Resolver::New(
|
||||
isolate->GetCurrentContext()).ToLocalChecked());
|
||||
v8::Global<v8::Promise::Resolver>* persistent =
|
||||
new v8::Global<v8::Promise::Resolver>(
|
||||
isolate,
|
||||
v8::Promise::Resolver::New(
|
||||
isolate->GetCurrentContext()).ToLocalChecked());
|
||||
|
||||
uv_work_t* req = new uv_work_t;
|
||||
uv_work_t* req = new uv_work_t;
|
||||
req->data = static_cast<void*>(persistent);
|
||||
|
||||
uv_queue_work(node::GetCurrentEventLoop(isolate),
|
||||
req,
|
||||
[](uv_work_t*) {},
|
||||
Callback);
|
||||
}
|
||||
uv_queue_work(node::GetCurrentEventLoop(isolate),
|
||||
req,
|
||||
[](uv_work_t*) {},
|
||||
Callback);
|
||||
|
||||
v8::Local<v8::Promise::Resolver> local =
|
||||
v8::Local<v8::Promise::Resolver>::New(isolate, persistent);
|
||||
v8::Local<v8::Promise::Resolver> local = persistent->Get(isolate);
|
||||
|
||||
args.GetReturnValue().Set(local->GetPromise());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user