diff --git a/doc/basic_env.md b/doc/basic_env.md index 7a5b430f1..840a5480f 100644 --- a/doc/basic_env.md +++ b/doc/basic_env.md @@ -72,17 +72,18 @@ void SetInstanceData(DataType* data, HintType* hint) const; - `[template] fini`: A function to call when the instance data is to be deleted. Accepts a function of the form `void CleanupData(Napi::Env env, DataType* data, HintType* hint)`. If not given, the default finalizer will be used, which simply -uses the `delete` operator to destroy `T*` when the add-on instance is unloaded. +uses the `delete` operator to destroy `DataType*` when the add-on instance is +unloaded. - `[in] data`: A pointer to data that will be associated with the instance of the add-on for the duration of its lifecycle. - `[in] hint`: A pointer to data that will be associated with the instance of the add-on for the duration of its lifecycle and will be passed as a hint to `fini` when the add-on instance is unloaded. -Associates a data item stored at `T* data` with the current instance of the -add-on. The item will be passed to the function `fini` which gets called when an -instance of the add-on is unloaded. This overload accepts an additional hint to -be passed to `fini`. +Associates a data item stored at `DataType* data` with the current instance of +the add-on. The item will be passed to the function `fini` which gets called +when an instance of the add-on is unloaded. This overload accepts an additional +hint to be passed to `fini`. ### GetModuleFileName diff --git a/doc/external.md b/doc/external.md index 4b4603e8e..1c48560b6 100644 --- a/doc/external.md +++ b/doc/external.md @@ -35,9 +35,8 @@ Returns the created `Napi::External` object. ```cpp template -static Napi::External Napi::External::New(napi_env env, - T* data, - Finalizer finalizeCallback); +template +static External New(napi_env env, T* data, Finalizer finalizeCallback); ``` - `[in] env`: The `napi_env` environment in which to construct the `Napi::External` object. @@ -52,7 +51,8 @@ Returns the created `Napi::External` object. ```cpp template -static Napi::External Napi::External::New(napi_env env, +template +static External New(napi_env env, T* data, Finalizer finalizeCallback, Hint* finalizeHint); diff --git a/doc/threadsafe_function.md b/doc/threadsafe_function.md index fcbc2dff1..9ab404731 100644 --- a/doc/threadsafe_function.md +++ b/doc/threadsafe_function.md @@ -70,9 +70,9 @@ New(napi_env env, opportunity for cleaning up after the threads e.g. by calling `uv_thread_join()`. It is important that, aside from the main loop thread, there be no threads left using the thread-safe function after the finalize - callback completes. Must implement `void operator()(Env env, DataType* data, - ContextType* hint)`, skipping `data` or `hint` if they are not provided. Can - be retrieved via `GetContext()`. + callback completes. Must implement `void operator()(Env env, + FinalizerDataType* data, ContextType* context)`, skipping `data` or `context` + if they are not provided. Can be retrieved via `GetContext()`. - `[optional] data`: Data to be passed to `finalizeCallback`. Returns a non-empty `Napi::ThreadSafeFunction` instance. diff --git a/doc/typed_threadsafe_function.md b/doc/typed_threadsafe_function.md index 74d3cc2ed..6dcc0343e 100644 --- a/doc/typed_threadsafe_function.md +++ b/doc/typed_threadsafe_function.md @@ -82,7 +82,7 @@ New(napi_env env, calling `uv_thread_join()`. It is important that, aside from the main loop thread, there be no threads left using the thread-safe function after the finalize callback completes. Must implement `void operator()(Env env, - FinalizerDataType* data, ContextType* hint)`. + FinalizerDataType* data, ContextType* context)`. - `[optional] data`: Data to be passed to `finalizeCallback`. Returns a non-empty `Napi::TypedThreadSafeFunction` instance. diff --git a/napi.h b/napi.h index 870a5c290..486f44c0f 100644 --- a/napi.h +++ b/napi.h @@ -422,12 +422,16 @@ class BasicEnv { #endif // NAPI_VERSION > 8 #ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER + // FinalizerType must implement `void operator()(Env env)`. template inline void PostFinalizer(FinalizerType finalizeCallback) const; + // FinalizerType must implement `void operator()(Env env, T* data)`. template inline void PostFinalizer(FinalizerType finalizeCallback, T* data) const; + // FinalizerType must implement `void operator()(Env env, T* data, + // Hint* hint)`. template inline void PostFinalizer(FinalizerType finalizeCallback, T* data, @@ -1107,9 +1111,12 @@ class Object : public TypeTaggable { const Function& constructor ///< Constructor function ) const; + // Finalizer must implement `void operator()(Env env, T* data)`. template inline void AddFinalizer(Finalizer finalizeCallback, T* data) const; + // Finalizer must implement `void operator()(Env env, T* data, + // Hint* hint)`. template inline void AddFinalizer(Finalizer finalizeCallback, T* data, @@ -1157,7 +1164,8 @@ class External : public TypeTaggable { // Finalizer must implement `void operator()(Env env, T* data)`. template static External New(napi_env env, T* data, Finalizer finalizeCallback); - // Finalizer must implement `void operator()(Env env, T* data, Hint* hint)`. + // Finalizer must implement `void operator()(Env env, T* data, + // Hint* hint)`. template static External New(napi_env env, T* data, @@ -1712,7 +1720,8 @@ class Buffer : public Uint8Array { T* data, size_t length, Finalizer finalizeCallback); - // Finalizer must implement `void operator()(Env env, T* data, Hint* hint)`. + // Finalizer must implement `void operator()(Env env, T* data, + // Hint* hint)`. template static Buffer New(napi_env env, T* data, @@ -1728,7 +1737,8 @@ class Buffer : public Uint8Array { T* data, size_t length, Finalizer finalizeCallback); - // Finalizer must implement `void operator()(Env env, T* data, Hint* hint)`. + // Finalizer must implement `void operator()(Env env, T* data, + // Hint* hint)`. template static Buffer NewOrCopy(napi_env env, T* data, @@ -2825,6 +2835,7 @@ class ThreadSafeFunction { ContextType* context); // This API may only be called from the main thread. + // Finalizer must implement `void operator()(Env env)`. template static ThreadSafeFunction New(napi_env env, const Function& callback, @@ -2834,6 +2845,8 @@ class ThreadSafeFunction { Finalizer finalizeCallback); // This API may only be called from the main thread. + // Finalizer must implement + // `void operator()(Env env, FinalizerDataType* data)`. template @@ -2846,6 +2859,8 @@ class ThreadSafeFunction { FinalizerDataType* data); // This API may only be called from the main thread. + // Finalizer must implement + // `void operator()(Env env, ContextType* context)`. template static ThreadSafeFunction New(napi_env env, const Function& callback, @@ -2856,6 +2871,8 @@ class ThreadSafeFunction { Finalizer finalizeCallback); // This API may only be called from the main thread. + // Finalizer must implement `void operator()(Env env, + // FinalizerDataType* data, ContextType* context)`. template static ThreadSafeFunction New(napi_env env, const Function& callback, @@ -2899,6 +2917,8 @@ class ThreadSafeFunction { Finalizer finalizeCallback); // This API may only be called from the main thread. + // Finalizer must implement + // `void operator()(Env env, FinalizerDataType* data)`. template @@ -2912,6 +2932,8 @@ class ThreadSafeFunction { FinalizerDataType* data); // This API may only be called from the main thread. + // Finalizer must implement + // `void operator()(Env env, ContextType* context)`. template static ThreadSafeFunction New(napi_env env, const Function& callback, @@ -2923,6 +2945,8 @@ class ThreadSafeFunction { Finalizer finalizeCallback); // This API may only be called from the main thread. + // Finalizer must implement `void operator()(Env env, + // FinalizerDataType* data, ContextType* context)`. template @@ -3082,6 +3108,8 @@ class TypedThreadSafeFunction { // This API may only be called from the main thread. // Creates a new threadsafe function with: // Callback [missing] Resource [passed] Finalizer [passed] + // Finalizer must implement `void operator()(Env env, + // FinalizerDataType* data, ContextType* context)`. template @@ -3124,6 +3152,8 @@ class TypedThreadSafeFunction { // This API may only be called from the main thread. // Creates a new threadsafe function with: // Callback [passed] Resource [missing] Finalizer [passed] + // Finalizer must implement `void operator()(Env env, + // FinalizerDataType* data, ContextType* context)`. template @@ -3140,6 +3170,8 @@ class TypedThreadSafeFunction { // This API may only be called from the main thread. // Creates a new threadsafe function with: // Callback [passed] Resource [passed] Finalizer [passed] + // Finalizer must implement `void operator()(Env env, + // FinalizerDataType* data, ContextType* context)`. template