src: simplify native immediate by using v8::Global

Unlike `node::Persistent`, `v8::Global` has move semantics and
can be used directly in STL containers.

PR-URL: https://github.com/nodejs/node/pull/26254
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen 2019-02-21 19:22:44 +01:00
parent 018e95ad13
commit d64e4deb73
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 2 additions and 3 deletions

View File

@ -625,8 +625,7 @@ void Environment::CreateImmediate(native_immediate_callback cb,
native_immediate_callbacks_.push_back({
cb,
data,
std::unique_ptr<Persistent<v8::Object>>(obj.IsEmpty() ?
nullptr : new Persistent<v8::Object>(isolate_, obj)),
v8::Global<v8::Object>(isolate_, obj),
ref
});
immediate_info()->count_inc(1);

View File

@ -1139,7 +1139,7 @@ class Environment {
struct NativeImmediateCallback {
native_immediate_callback cb_;
void* data_;
std::unique_ptr<Persistent<v8::Object>> keep_alive_;
v8::Global<v8::Object> keep_alive_;
bool refed_;
};
std::vector<NativeImmediateCallback> native_immediate_callbacks_;