diff --git a/test/built-ins/FinalizationGroup/prototype/cleanupSome/cleanup-prevented-with-reference.js b/test/built-ins/FinalizationGroup/prototype/cleanupSome/cleanup-prevented-with-reference.js new file mode 100644 index 0000000000..bfff3426de --- /dev/null +++ b/test/built-ins/FinalizationGroup/prototype/cleanupSome/cleanup-prevented-with-reference.js @@ -0,0 +1,48 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-finalization-group.prototype.cleanupSome +description: Cleanup might be prevented with a reference usage; +info: | + FinalizationGroup.prototype.cleanupSome ( [ callback ] ) + + 1. Let finalizationGroup be the this value. + 2. If Type(finalizationGroup) is not Object, throw a TypeError exception. + 3. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. + 4. If callback is not undefined and IsCallable(callback) is false, throw a TypeError exception. + 5. Perform ? CleanupFinalizationGroup(finalizationGroup, callback). + 6. Return undefined. +features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class, host-gc-required] +---*/ + +var holdingsList; +function cb(iterator) { + holdingsList = [...iterator]; +}; +var fg = new FinalizationGroup(function() {}); + +function emptyCells() { + var x; + (function() { + var a = {}; + b = {}; + x = {}; + var y = {}; + fg.register(x, 'x'); + fg.register(a, 'a'); + fg.register(y, y); + fg.register(b, 'b'); + var b; + })(); + $262.gc(); + x; // This is an intentional reference to x, please leave it here, after the GC +} + +emptyCells(); +fg.cleanupSome(cb); + +// The order is per implementation so we can't use compareArray without sorting +assert.sameValue(holdingsList.length, 2); +assert(holdingsList.includes('a')); +assert(holdingsList.includes('b')); diff --git a/test/built-ins/FinalizationGroup/prototype/register/holdings-any-value-type.js b/test/built-ins/FinalizationGroup/prototype/register/holdings-any-value-type.js index a399a4bdb3..1048a07b81 100644 --- a/test/built-ins/FinalizationGroup/prototype/register/holdings-any-value-type.js +++ b/test/built-ins/FinalizationGroup/prototype/register/holdings-any-value-type.js @@ -30,8 +30,6 @@ assert.sameValue(fg.register(target, false), undefined, 'false'); assert.sameValue(fg.register(target, true), undefined, 'true'); assert.sameValue(fg.register(target, Symbol()), undefined, 'symbol'); assert.sameValue(fg.register(target, {}), undefined, 'object'); -assert.sameValue(fg.register(target, target), undefined, 'same as target'); assert.sameValue(fg.register(target, fg), undefined, 'same as fg instance'); -assert.sameValue(fg.register(target, target, target), undefined, 'target, and same as unregisterToken'); assert.sameValue(fg.register(target, 1), undefined, 'number'); assert.sameValue(fg.register(target, 'holdings'), undefined, 'string'); diff --git a/test/built-ins/FinalizationGroup/prototype/register/holdings-same-as-target.js b/test/built-ins/FinalizationGroup/prototype/register/holdings-same-as-target.js new file mode 100644 index 0000000000..d38d8884b9 --- /dev/null +++ b/test/built-ins/FinalizationGroup/prototype/register/holdings-same-as-target.js @@ -0,0 +1,26 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-finalization-group.prototype.register +description: holdings may be the same as target +info: | + FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] ) + + 1. Let finalizationGroup be the this value. + 2. If Type(finalizationGroup) is not Object, throw a TypeError exception. + 3. If Type(target) is not Object, throw a TypeError exception. + 4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. + 5. If Type(unregisterToken) is not Object, + a. If unregisterToken is not undefined, throw a TypeError exception. + b. Set unregisterToken to empty. + 6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }. + 7. Append cell to finalizationGroup.[[Cells]]. + 8. Return undefined. +features: [FinalizationGroup] +---*/ + +var fg = new FinalizationGroup(function() {}); + +var target = {}; +assert.sameValue(fg.register(target, target), undefined); diff --git a/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-holdings-and-target.js b/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-holdings-and-target.js new file mode 100644 index 0000000000..f1dc302f4d --- /dev/null +++ b/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-holdings-and-target.js @@ -0,0 +1,26 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-finalization-group.prototype.register +description: unregisterToken may be the same as holdings and target +info: | + FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] ) + + 1. Let finalizationGroup be the this value. + 2. If Type(finalizationGroup) is not Object, throw a TypeError exception. + 3. If Type(target) is not Object, throw a TypeError exception. + 4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. + 5. If Type(unregisterToken) is not Object, + a. If unregisterToken is not undefined, throw a TypeError exception. + b. Set unregisterToken to empty. + 6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }. + 7. Append cell to finalizationGroup.[[Cells]]. + 8. Return undefined. +features: [FinalizationGroup] +---*/ + +var fg = new FinalizationGroup(function() {}); + +var target = {}; +assert.sameValue(fg.register(target, target, target), undefined); diff --git a/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-holdings.js b/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-holdings.js new file mode 100644 index 0000000000..7c498bc04f --- /dev/null +++ b/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-holdings.js @@ -0,0 +1,27 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-finalization-group.prototype.register +description: unregisterToken may be the same as holdings +info: | + FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] ) + + 1. Let finalizationGroup be the this value. + 2. If Type(finalizationGroup) is not Object, throw a TypeError exception. + 3. If Type(target) is not Object, throw a TypeError exception. + 4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. + 5. If Type(unregisterToken) is not Object, + a. If unregisterToken is not undefined, throw a TypeError exception. + b. Set unregisterToken to empty. + 6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }. + 7. Append cell to finalizationGroup.[[Cells]]. + 8. Return undefined. +features: [FinalizationGroup] +---*/ + +var fg = new FinalizationGroup(function() {}); + +var target = {}; +var holdings = {}; +assert.sameValue(fg.register(target, holdings, holdings), undefined); diff --git a/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-target.js b/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-target.js new file mode 100644 index 0000000000..20fe2e0563 --- /dev/null +++ b/test/built-ins/FinalizationGroup/prototype/register/unregisterToken-same-as-target.js @@ -0,0 +1,26 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-finalization-group.prototype.register +description: unregisterToken may be the same as target +info: | + FinalizationGroup.prototype.register ( target , holdings [, unregisterToken ] ) + + 1. Let finalizationGroup be the this value. + 2. If Type(finalizationGroup) is not Object, throw a TypeError exception. + 3. If Type(target) is not Object, throw a TypeError exception. + 4. If finalizationGroup does not have a [[Cells]] internal slot, throw a TypeError exception. + 5. If Type(unregisterToken) is not Object, + a. If unregisterToken is not undefined, throw a TypeError exception. + b. Set unregisterToken to empty. + 6. Let cell be the Record { [[Target]] : target, [[Holdings]]: holdings, [[UnregisterToken]]: unregisterToken }. + 7. Append cell to finalizationGroup.[[Cells]]. + 8. Return undefined. +features: [FinalizationGroup] +---*/ + +var fg = new FinalizationGroup(function() {}); + +var target = {}; +assert.sameValue(fg.register(target, '1', target), undefined);