From f7ad2953edc52ceeee730c4133cc277b29bc8b19 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Wed, 18 Dec 2019 16:23:23 +0000 Subject: [PATCH] Update tests now that FinalizationGroup.prototype.cleanupSome throws if cleanup is currently in progress. (#2434) This behaviour was changed in: https://github.com/tc39/proposal-weakrefs/pull/158 --- .../cleanupSome/cleanup-throws-in-callback.js | 55 +++++++++ .../prototype/cleanupSome/iterator-dynamic.js | 106 ------------------ 2 files changed, 55 insertions(+), 106 deletions(-) create mode 100644 test/built-ins/FinalizationGroup/prototype/cleanupSome/cleanup-throws-in-callback.js delete mode 100644 test/built-ins/FinalizationGroup/prototype/cleanupSome/iterator-dynamic.js diff --git a/test/built-ins/FinalizationGroup/prototype/cleanupSome/cleanup-throws-in-callback.js b/test/built-ins/FinalizationGroup/prototype/cleanupSome/cleanup-throws-in-callback.js new file mode 100644 index 0000000000..4d588ecda3 --- /dev/null +++ b/test/built-ins/FinalizationGroup/prototype/cleanupSome/cleanup-throws-in-callback.js @@ -0,0 +1,55 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-finalization-group-constructor +description: > + The cleanupSome() method throws if cleanup is currently in progress. +info: | + FinalizationGroup.prototype.cleanupSome ( [ callback ] ) + + 1. Let finalizationGroup be the this value. + ... + 4. If finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] is true, + throw a TypeError exception. + +features: [FinalizationGroup, host-gc-required] +includes: [async-gc.js] +flags: [async, non-deterministic] +---*/ + +var called = 0; +var endOfCall = 0; +var fg = new FinalizationGroup(function() {}); + +function callback(iterator) { + called += 1; + + if (called === 1) { + // Atempt to re-enter the callback. + var nestedCallbackRan = false; + assert.throws(TypeError, () => { + fg.cleanupSome(() => { nestedCallbackRan = true }); + }); + assert.sameValue(nestedCallbackRan, false); + } + + endOfCall += 1; +} + +function emptyCells() { + var o1 = {}; + fg.register(o1, 'holdings 1'); + + var prom = asyncGC(o1); + o1 = null; + + return prom; +} + +emptyCells().then(function() { + fg.cleanupSome(callback); + + assert.sameValue(called, 1, 'callback was called'); + assert.sameValue(endOfCall, 1, 'callback finished'); +}).then($DONE, resolveAsyncGC); diff --git a/test/built-ins/FinalizationGroup/prototype/cleanupSome/iterator-dynamic.js b/test/built-ins/FinalizationGroup/prototype/cleanupSome/iterator-dynamic.js deleted file mode 100644 index 6299a1f299..0000000000 --- a/test/built-ins/FinalizationGroup/prototype/cleanupSome/iterator-dynamic.js +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2019 Leo Balter. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-properties-of-the-finalization-group-constructor -description: > - The callback iterator is dynamic. Therefore, it can be emptied before iteration -info: | - FinalizationGroup.prototype.cleanupSome ( [ callback ] ) - - 1. Let finalizationGroup be the this value. - ... - 5. Perform ! CleanupFinalizationGroup(finalizationGroup, callback). - ... - - CleanupFinalizationGroup ( finalizationGroup [ , callback ] ) - - ... - 3. Let iterator be ! CreateFinalizationGroupCleanupIterator(finalizationGroup). - ... - 6. Let result be Call(callback, undefined, « iterator »). - ... - - %FinalizationGroupCleanupIteratorPrototype%.next ( ) - - 8. If finalizationGroup.[[Cells]] contains a Record cell such that cell.[[Target]] is empty, - a. Choose any such cell. - b. Remove cell from finalizationGroup.[[Cells]]. - c. Return CreateIterResultObject(cell.[[Holdings]], false). - 9. Otherwise, return CreateIterResultObject(undefined, true). -features: [FinalizationGroup, host-gc-required, Symbol] -includes: [async-gc.js] -flags: [async, non-deterministic] ----*/ - -var called = 0; -var endOfCall = 0; -var first, second, third; -var firstIter, secondIter, thirdIter; -var fg = new FinalizationGroup(function() {}); - -function callback(iterator) { - called += 1; - - if (called === 1) { - - // Inception! - fg.cleanupSome(callback); - - first = iterator.next(); - firstIter = iterator; - } else if (called === 2) { - - // Double Inception! - fg.cleanupSome(callback); - - second = iterator.next(); - secondIter = iterator; - } else if (called === 3) { - - // Triple Inception! - // But this time we won't try to consume iterator anymore, leave it alone there. - fg.cleanupSome(callback); - - third = iterator.next(); - thirdIter = iterator; - } - - endOfCall += 1; -} - -function emptyCells() { - var o1 = {}; - var o2 = {}; - fg.register(o1, 'holdings 1'); - fg.register(o2, 'holdings 2'); - - var prom = asyncGC(o1, o2); - o1 = null; - o2 = null; - - return prom; -} - -emptyCells().then(function() { - fg.cleanupSome(callback); - - // Make sure everything is set - assert.sameValue(called, 4, 'cleanup successfully'); - assert.sameValue(endOfCall, 4, 'cleanup ended successfully'); - - assert.notSameValue(firstIter, secondIter, 'callback is not called with the same iterator #1'); - assert.notSameValue(firstIter, thirdIter, 'callback is not called with the same iterator #2'); - assert.notSameValue(secondIter, thirdIter, 'callback is not called with the same iterator #3'); - - assert.sameValue(first.value, undefined, 'iterator is already consumed'); - assert.sameValue(first.done, true, 'first callback will find no empty Targets'); - assert.sameValue(second.done, false, 'second callback will find an empty Target'); - assert.sameValue(third.done, false, 'third callback will find an empty Target'); - - // 8.a. Choose any such cell. - var holdings = [second.value, third.value]; - - assert(holdings.includes('holdings 1'), 'iterators consume emptied cells #1'); - assert(holdings.includes('holdings 2'), 'iterators consume emptied cells #2'); -}).then($DONE, resolveAsyncGC);