`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: https://github.com/nodejs/node/pull/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>
24 lines
628 B
JavaScript
24 lines
628 B
JavaScript
// 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);
|