Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix napi test_reference for recent V8 #12864

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions test/addons-napi/test_reference/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ assert.strictEqual(test_reference.finalizeCount, 0);
assert.strictEqual(test_reference.finalizeCount, 1);
}

{
// Weak reference
let value = test_reference.createExternalWithFinalize();
assert.strictEqual(test_reference.finalizeCount, 0);
test_reference.createReference(value, 0);
assert.strictEqual(test_reference.referenceValue, value);
value = null;
global.gc(); // Value should be GC'd because there is only a weak ref
assert.strictEqual(test_reference.referenceValue, undefined);
assert.strictEqual(test_reference.finalizeCount, 1);
test_reference.deleteReference();
}

{
// Strong reference
let value = test_reference.createExternalWithFinalize();
Expand Down Expand Up @@ -85,3 +72,19 @@ assert.strictEqual(test_reference.finalizeCount, 0);
global.gc(); // Value was already GC'd
assert.strictEqual(test_reference.finalizeCount, 1);
}

{
// Weak reference
let value = test_reference.createExternalWithFinalize();
assert.strictEqual(test_reference.finalizeCount, 0);
test_reference.createReference(value, 0);
assert.strictEqual(test_reference.referenceValue, value);
value = null;
setImmediate(common.mustCall(() => {
// This test only works if gc() is called from an immediate callback.
global.gc(); // Value should be GC'd because there is only a weak ref
assert.strictEqual(test_reference.referenceValue, undefined);
assert.strictEqual(test_reference.finalizeCount, 1);
test_reference.deleteReference();
}));
}