From fd26fc17ea71b3eb6cf8ebe41039dc6e05ee9187 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 16 Sep 2020 12:04:09 -0400 Subject: [PATCH] Refactor: built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback.js Per recommendation here: https://github.com/web-platform-tests/wpt/pull/25496/files#r488316588 --- ...-has-one-chance-to-call-cleanupCallback.js | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback.js b/test/built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback.js index 4e4828188c..10e0c8f543 100644 --- a/test/built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback.js +++ b/test/built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback.js @@ -27,33 +27,30 @@ info: | b. Optionally, perform ! HostCleanupFinalizationRegistry(finalizationRegistry). features: [cleanupSome, FinalizationRegistry, async-functions, host-gc-required] flags: [async, non-deterministic] -includes: [async-gc.js] +includes: [async-gc.js, compareArray.js] ---*/ -var cleanupCallback = 0; -var called = 0; - +let cleanupCallback = 0; +let holdings = []; function cb(holding) { - assert.sameValue(holding, 'a'); - called += 1; + holdings.push(holding); } -var finalizationRegistry = new FinalizationRegistry(function() { +let finalizationRegistry = new FinalizationRegistry(function() { cleanupCallback += 1; }); function emptyCells() { - var target = {}; + let target = {}; finalizationRegistry.register(target, 'a'); - var prom = asyncGC(target); + let prom = asyncGC(target); target = null; return prom; } -emptyCells() - .then(async function() { +emptyCells().then(async function() { await Promise.resolve(1); finalizationRegistry.cleanupSome(cb); @@ -62,7 +59,7 @@ emptyCells() // cleanupCallback already ran, then cb won't be called. let expectedCalled = cleanupCallback === 1 ? 0 : 1; // This asserts the registered object was emptied in the previous GC. - assert.sameValue(called, expectedCalled, 'cleanupSome callback for the first time'); + assert.sameValue(holdings.length, expectedCalled, 'cleanupSome callback for the first time'); // At this point, we can't assert if cleanupCallback was called, because it's // optional. Although, we can finally assert it's not gonna be called anymore @@ -81,7 +78,7 @@ emptyCells() finalizationRegistry.cleanupSome(cb); - assert.sameValue(called, expectedCalled, 'cleanupSome callback is not called anymore, no empty cells'); + assert.sameValue(holdings.length, expectedCalled, 'cleanupSome callback is not called anymore, no empty cells'); assert.sameValue(cleanupCallback, 0, 'cleanupCallback is not called again #1'); await $262.gc(); @@ -89,9 +86,12 @@ emptyCells() finalizationRegistry.cleanupSome(cb); - assert.sameValue(called, expectedCalled, 'cleanupSome callback is not called again #2'); + assert.sameValue(holdings.length, expectedCalled, 'cleanupSome callback is not called again #2'); assert.sameValue(cleanupCallback, 0, 'cleanupCallback is not called again #2'); + if (holdings.length) { + assert.compareArray(holdings, ['a']); + } + await $262.gc(); - }) - .then($DONE, resolveAsyncGC); +}).then($DONE, resolveAsyncGC);