Skip to content

Commit

Permalink
test: fix napi test_reference for recent V8
Browse files Browse the repository at this point in the history
PR-URL: #12864
Ref: #12551 (comment)
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
targos committed May 7, 2017
1 parent 42958d1 commit 0a734fe
Showing 1 changed file with 16 additions and 13 deletions.
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();
}));
}

0 comments on commit 0a734fe

Please sign in to comment.