-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node-api: allow napi_delete_reference in finalizers
`napi_delete_reference` must be called immediately for a `napi_reference` returned from `napi_wrap` in the corresponding finalizer, in order to clean up the `napi_reference` timely. `napi_delete_reference` is safe to be invoked during GC. PR-URL: #55620 Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
- Loading branch information
1 parent
65bc8e8
commit f883bed
Showing
5 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Flags: --expose-gc | ||
|
||
'use strict'; | ||
const common = require('../../common'); | ||
const assert = require('assert'); | ||
const addon = require(`./build/${common.buildType}/6_object_wrap_basic_finalizer`); | ||
|
||
// This test verifies that ObjectWrap can be correctly finalized with a node_api_basic_finalizer | ||
// in the current JS loop tick | ||
(() => { | ||
let obj = new addon.MyObject(9); | ||
obj = null; | ||
// Silent eslint about unused variables. | ||
assert.strictEqual(obj, null); | ||
})(); | ||
|
||
for (let i = 0; i < 10; ++i) { | ||
global.gc(); | ||
if (addon.getFinalizerCallCount() === 1) { | ||
break; | ||
} | ||
} | ||
|
||
assert.strictEqual(addon.getFinalizerCallCount(), 1); |