Skip to content

Commit 4a112dd

Browse files
committed
Address comments in 8 Jun 2024 Node-API meeting:
- Use post finalizer to delete reference in `~Reference` - Remove const ref from comparison operator in `NogcEnv` - Remove leftover debugging statements
1 parent c64d8cf commit 4a112dd

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

napi-inl.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3244,15 +3244,19 @@ inline Reference<T>::Reference(napi_env env, napi_ref ref)
32443244

32453245
template <typename T>
32463246
inline Reference<T>::~Reference() {
3247-
#ifndef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
32483247
if (_ref != nullptr) {
32493248
if (!_suppressDestruct) {
3249+
#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
3250+
Env().AddPostFinalizer(
3251+
[](Napi::Env env, napi_ref ref) { napi_delete_reference(env, ref); },
3252+
_ref);
3253+
#else
32503254
napi_delete_reference(_env, _ref);
3255+
#endif
32513256
}
32523257

32533258
_ref = nullptr;
32543259
}
3255-
#endif // NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
32563260
}
32573261

32583262
template <typename T>

napi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class NogcEnv {
345345
bool operator==(const NogcEnv& other) const {
346346
return _env == other._env;
347347
};
348-
bool operator==(const std::nullptr_t& /*other*/) const {
348+
bool operator==(std::nullptr_t /*other*/) const {
349349
return _env == nullptr;
350350
};
351351

test/movable_callbacks.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <iostream>
21
#include "napi.h"
32

43
using namespace Napi;

0 commit comments

Comments
 (0)