Permalink
Browse files

test: fix napi test_reference for recent V8

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 5, 2017
1 parent 42958d1 commit 0a734fec885409a09b9d18319e4ea7f6f25e6a3e
Showing with 16 additions and 13 deletions.
  1. +16 −13 test/addons-napi/test_reference/test.js
@@ -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();
@@ -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.