diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js')
-rw-r--r-- | js/src/tests/test262/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js b/js/src/tests/test262/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js new file mode 100644 index 0000000000..da74a59287 --- /dev/null +++ b/js/src/tests/test262/built-ins/FinalizationRegistry/prototype/unregister/unregister-cleaned-up-object-cell.js @@ -0,0 +1,64 @@ +// |reftest| skip-if(!this.hasOwnProperty('FinalizationRegistry')) async -- FinalizationRegistry is not enabled unconditionally +// Copyright (C) 2019 Mathieu Hofman. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-finalization-registry.prototype.unregister +description: > + Cannot unregister a cell referring to an Object that has been cleaned up +info: | + FinalizationRegistry.prototype.cleanupSome ( [ _callback_ ] ) + 4. Perform ? CleanupFinalizationRegistry(_finalizationRegistry_, _callback_). + + CleanupFinalizationRegistry ( _finalizationRegistry_ ): + 3. While _finalizationRegistry_.[[Cells]] contains a Record _cell_ such that + _cell_.[[WeakRefTarget]] is ~empty~, then an implementation may perform the + following steps: + a. Choose any such _cell_. + b. Remove _cell_ from _finalizationRegistry_.[[Cells]]. + c. Perform ? HostCallJobCallback(_callback_, *undefined*, + « _cell_.[[HeldValue]] »). + + FinalizationRegistry.prototype.unregister ( _unregisterToken_ ) + 4. Let _removed_ be *false*. + 5. For each Record { [[WeakRefTarget]], [[HeldValue]], [[UnregisterToken]] } + _cell_ of _finalizationRegistry_.[[Cells]], do + a. If _cell_.[[UnregisterToken]] is not ~empty~ and + SameValue(_cell_.[[UnregisterToken]], _unregisterToken_) is *true*, then + i. Remove _cell_ from _finalizationRegistry_.[[Cells]]. + ii. Set _removed_ to *true*. + 6. Return _removed_. +features: [FinalizationRegistry.prototype.cleanupSome, FinalizationRegistry, host-gc-required] +includes: [async-gc.js] +flags: [async, non-deterministic] +---*/ + +var value = 'target!'; +var token = {}; +var finalizationRegistry = new FinalizationRegistry(function() {}); + +function emptyCells() { + var target = {}; + finalizationRegistry.register(target, value, token); + + var prom = asyncGC(target); + target = null; + + return prom; +} + +emptyCells().then(function() { + var called = 0; + var holdings = []; + finalizationRegistry.cleanupSome(function cb(holding) { + called += 1; + holdings.push(holding); + }); + + assert.sameValue(called, 1); + assert.sameValue(holdings.length, 1); + assert.sameValue(holdings[0], value); + + var res = finalizationRegistry.unregister(token); + assert.sameValue(res, false, 'unregister after iterating over it in cleanup'); +}).then($DONE, resolveAsyncGC); |