GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — node-api: fix immediate napi_remove_wrap test · nodejs/node@44766c6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/js-native-api/test_reference_double_free
    • test_reference_double_free.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/js-native-api/test_reference_double_free/test_reference_double_free.c‎

Copy file name to clipboardExpand all lines: test/js-native-api/test_reference_double_free/test_reference_double_free.c
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ static napi_value New(napi_env env, napi_callback_info info) {
4444

4545
static void NoopDeleter(napi_env env, void* data, void* hint) {}
4646

47+
// Tests that calling napi_remove_wrap and napi_delete_reference consecutively
48+
// doesn't crash the process.
49+
// This is analogous to the test https://github.com/nodejs/node-addon-api/blob/main/test/objectwrap_constructor_exception.cc.
50+
// In which the Napi::ObjectWrap<> is being destructed immediately after napi_wrap.
51+
// As Napi::ObjectWrap<> is a subclass of Napi::Reference<>, napi_remove_wrap
52+
// in the destructor of Napi::ObjectWrap<> is called before napi_delete_reference
53+
// in the destructor of Napi::Reference<>.
4754
static napi_value DeleteImmediately(napi_env env, napi_callback_info info) {
4855
size_t argc = 1;
4956
napi_value js_obj;
@@ -56,8 +63,8 @@ static napi_value DeleteImmediately(napi_env env, napi_callback_info info) {
5663
NODE_API_ASSERT(env, type == napi_object, "Expected object parameter");
5764

5865
NODE_API_CALL(env, napi_wrap(env, js_obj, NULL, NoopDeleter, NULL, &ref));
59-
NODE_API_CALL(env, napi_delete_reference(env, ref));
6066
NODE_API_CALL(env, napi_remove_wrap(env, js_obj, NULL));
67+
NODE_API_CALL(env, napi_delete_reference(env, ref));
6168

6269
return NULL;
6370
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.