Skip to content

Commit

Permalink
attempt fix compilation issues #2
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinEady committed Jul 25, 2024
1 parent 31d6c6c commit 89ebc42
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 51 deletions.
29 changes: 11 additions & 18 deletions doc/basic_env.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ its `Remove()` method.
### PostFinalizer
```cpp
using FinalizerWithoutData = void (*)(Env);
inline void PostFinalizer(FinalizerWithoutData finalizeCallback) const;
template <typename FinalizerType>
inline void PostFinalizer(FinalizerType finalizeCallback) const;
```

- `[in] finalizeCallback`: The function to queue for execution outside of the GC
Expand All @@ -129,34 +128,28 @@ inline void PostFinalizer(FinalizerWithoutData finalizeCallback) const;
### PostFinalizer

```cpp
template <typename T>
using Finalizer = void (*)(Napi::Env, T*);

template <typename DataType>
inline void PostFinalizer(Finalizer<DataType> finalizeCallback, DataType* data) const;
template <typename FinalizerType, typename T>
inline void PostFinalizer(FinalizerType finalizeCallback, T* data) const;
```
- `[in] finalizeCallback`: The function to queue for execution outside of the GC
finalization, implementing `operator()(Napi::Env, DataType*)`. See [Finalization]()
finalization, implementing `operator()(Napi::Env, T*)`. See [Finalization]()
for more details.
- `[in] data`: The data value passed to the `finalizeCallback` function.
- `[in] data`: The data to associate with the object.
### PostFinalizer
```cpp
template <typename DataType, typename HintType>
using FinalizerWithHint = void (*)(Napi::Env, DataType*, HintType*);
template <typename DataType, typename HintType>
inline void PostFinalizer(FinalizerWithHint<DataType, HintType> finalizeCallback,
DataType* data,
template <typename FinalizerType, typename T, typename Hint>
inline void PostFinalizer(FinalizerType finalizeCallback,
T* data,
Hint* finalizeHint) const;
```

- `[in] finalizeCallback`: The function to queue for execution outside of the GC
finalization, implementing `operator()(Napi::Env, DataType*, HintType*)`. See
finalization, implementing `operator()(Napi::Env, T*, Hint*)`. See
[Finalization]() for more details.
- `[in] data`: The data value passed to the `finalizeCallback` function.
- `[in] data`: The data to associate with the object.
- `[in] finalizeHint`: The hint value passed to the `finalizeCallback` function.

### AddCleanupHook
Expand Down
41 changes: 18 additions & 23 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6789,16 +6789,16 @@ bool Env::CleanupHook<Hook, Arg>::IsEmpty() const {
#endif // NAPI_VERSION > 2

#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
inline void BasicEnv::PostFinalizer(
FinalizerWithoutData finalizeCallback) const {
template <typename FinalizerType>
inline void BasicEnv::PostFinalizer(FinalizerType finalizeCallback) const {
using T = void*;
details::FinalizeData<T, FinalizerWithoutData>* finalizeData =
new details::FinalizeData<T, FinalizerWithoutData>(
details::FinalizeData<T, FinalizerType>* finalizeData =
new details::FinalizeData<T, FinalizerType>(
{std::move(finalizeCallback), nullptr});

napi_status status = node_api_post_finalizer(
_env,
details::FinalizeData<T, FinalizerWithoutData>::WrapperGCWithoutData,
details::FinalizeData<T, FinalizerType>::WrapperGCWithoutData,
static_cast<void*>(nullptr),
finalizeData);
if (status != napi_ok) {
Expand All @@ -6808,16 +6808,16 @@ inline void BasicEnv::PostFinalizer(
}
}

template <typename DataType>
inline void BasicEnv::PostFinalizer(Finalizer<DataType> finalizeCallback,
DataType* data) const {
details::FinalizeData<DataType, Finalizer<DataType>>* finalizeData =
new details::FinalizeData<DataType, Finalizer<DataType>>(
template <typename FinalizerType, typename T>
inline void BasicEnv::PostFinalizer(FinalizerType finalizeCallback,
T* data) const {
details::FinalizeData<T, FinalizerType>* finalizeData =
new details::FinalizeData<T, FinalizerType>(
{std::move(finalizeCallback), nullptr});

napi_status status = node_api_post_finalizer(
_env,
details::FinalizeData<DataType, Finalizer<DataType>>::WrapperGC,
details::FinalizeData<T, FinalizerType>::WrapperGC,
data,
finalizeData);
if (status != napi_ok) {
Expand All @@ -6827,21 +6827,16 @@ inline void BasicEnv::PostFinalizer(Finalizer<DataType> finalizeCallback,
}
}

template <typename DataType, typename HintType>
inline void BasicEnv::PostFinalizer(
FinalizerWithHint<DataType, HintType> finalizeCallback,
DataType* data,
HintType* finalizeHint) const {
details::FinalizeData<DataType,
FinalizerWithHint<DataType, HintType>,
HintType>* finalizeData = new details::
FinalizeData<DataType, FinalizerWithHint<DataType, HintType>, HintType>(
template <typename FinalizerType, typename T, typename Hint>
inline void BasicEnv::PostFinalizer(FinalizerType finalizeCallback,
T* data,
Hint* finalizeHint) const {
details::FinalizeData<T, FinalizerType, Hint>* finalizeData =
new details::FinalizeData<T, FinalizerType, Hint>(
{std::move(finalizeCallback), finalizeHint});
napi_status status = node_api_post_finalizer(
_env,
details::FinalizeData<DataType,
FinalizerWithHint<DataType, HintType>,
HintType>::WrapperGCWithHint,
details::FinalizeData<T, FinalizerType, Hint>::WrapperGCWithHint,
data,
finalizeData);
if (status != napi_ok) {
Expand Down
18 changes: 8 additions & 10 deletions napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,18 +395,16 @@ class BasicEnv {
#endif // NAPI_VERSION > 8

#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
using FinalizerWithoutData = void (*)(Env);
inline void PostFinalizer(FinalizerWithoutData finalizeCallback) const;
template <typename FinalizerType>
inline void PostFinalizer(FinalizerType finalizeCallback) const;

template <typename DataType>
inline void PostFinalizer(Finalizer<DataType> finalizeCallback,
DataType* data) const;
template <typename FinalizerType, typename T>
inline void PostFinalizer(FinalizerType finalizeCallback, T* data) const;

template <typename DataType, typename HintType>
inline void PostFinalizer(
FinalizerWithHint<DataType, HintType> finalizeCallback,
DataType* data,
HintType* finalizeHint) const;
template <typename FinalizerType, typename T, typename Hint>
inline void PostFinalizer(FinalizerType finalizeCallback,
T* data,
Hint* finalizeHint) const;
#endif // NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER

friend class Env;
Expand Down

0 comments on commit 89ebc42

Please sign in to comment.