node/test/js-native-api/test_reference_double_free
Chengzhong Wu 926c830995
node-api: fix immediate napi_remove_wrap test
As documented in napi_wrap section, the returned reference must be
deleted with `napi_delete_reference` in response to the finalize
callback, in which `napi_unwrap` and `napi_remove_wrap` is not
available.

When the reference needs to be deleted early, it should be
deleted after the wrapped value is not accessed with `napi_unwrap`
and `napi_remove_wrap` too.

This test is previously added in response to duplicating the test
https://github.com/nodejs/node-addon-api/blob/main/test/objectwrap_constructor_exception.cc
in the node-addon-api. As Napi::ObjectWrap<> is a subclass of
Napi::Reference<>, napi_remove_wrap in the destructor of
Napi::ObjectWrap<> is called before napi_delete_reference in the
destructor of Napi::Reference<>.

PR-URL: https://github.com/nodejs/node/pull/45406
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2022-11-18 09:31:25 +00:00
..
binding.gyp
test.js
test_reference_double_free.c node-api: fix immediate napi_remove_wrap test 2022-11-18 09:31:25 +00:00
test_wrap.js