-
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 <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Vladimir Morozov <[email protected]>
- Loading branch information
1 parent
50ec6f9
commit e726767
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); |