Skip to content

Commit 06d592c

Browse files
committed
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: #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>
1 parent ea26ac0 commit 06d592c

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/env-inl.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,7 @@ void Environment::CreateImmediate(native_immediate_callback cb,
625625
native_immediate_callbacks_.push_back({
626626
cb,
627627
data,
628-
std::unique_ptr<Persistent<v8::Object>>(obj.IsEmpty() ?
629-
nullptr : new Persistent<v8::Object>(isolate_, obj)),
628+
v8::Global<v8::Object>(isolate_, obj),
630629
ref
631630
});
632631
immediate_info()->count_inc(1);

src/env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ class Environment {
11431143
struct NativeImmediateCallback {
11441144
native_immediate_callback cb_;
11451145
void* data_;
1146-
std::unique_ptr<Persistent<v8::Object>> keep_alive_;
1146+
v8::Global<v8::Object> keep_alive_;
11471147
bool refed_;
11481148
};
11491149
std::vector<NativeImmediateCallback> native_immediate_callbacks_;

0 commit comments

Comments
 (0)