node/test/js-native-api/6_object_wrap/nested_wrap.h
Chengzhong Wu 3b90f3454d
node-api: add nested object wrap and napi_ref test
Test that an napi_ref can be nested inside another ObjectWrap. The test
shows a critical case where a finalizer deletes an `napi_ref` whose
finalizer is also scheduled.

PR-URL: https://github.com/nodejs/node/pull/57981
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2025-04-25 22:22:30 +00:00

33 lines
831 B
C++

#ifndef TEST_JS_NATIVE_API_6_OBJECT_WRAP_NESTED_WRAP_H_
#define TEST_JS_NATIVE_API_6_OBJECT_WRAP_NESTED_WRAP_H_
#include <js_native_api.h>
/**
* Test that an napi_ref can be nested inside another ObjectWrap.
*
* This test shows a critical case where a finalizer deletes an napi_ref
* whose finalizer is also scheduled.
*/
class NestedWrap {
public:
static void Init(napi_env env, napi_value exports);
static void Destructor(node_api_basic_env env,
void* nativeObject,
void* finalize_hint);
private:
explicit NestedWrap();
~NestedWrap();
static napi_value New(napi_env env, napi_callback_info info);
static napi_ref constructor;
napi_env env_{};
napi_ref wrapper_{};
napi_ref nested_{};
};
#endif // TEST_JS_NATIVE_API_6_OBJECT_WRAP_NESTED_WRAP_H_