Fix tests for FinalizationGroup

This commit is contained in:
Leo Balter 2019-06-26 13:16:32 -04:00 committed by Rick Waldron
parent 166d5ac589
commit 7c7d3f756c
4 changed files with 114 additions and 19 deletions

View File

@ -0,0 +1,58 @@
// 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: Return abrupt completion from CleanupFinalizationGroup
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.
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
4. If callback is undefined, set callback to finalizationGroup.[[CleanupCallback]].
5. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to true.
6. Let result be Call(callback, undefined, « iterator »).
7. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to false.
8. If result is an abrupt completion, return result.
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class, host-gc-required]
---*/
var called = 0;
var iterator;
function poisoned(iter) {
iterator = iter;
iter.next(); // Won't throw
throw new Test262Error();
}
var fg = new FinalizationGroup(function() {
called += 1;
});
function emptyCells() {
(function() {
var o = {};
fg.register(o);
})();
$262.gc();
}
emptyCells();
assert.throws(Test262Error, function() {
fg.cleanupSome(poisoned);
});
assert.sameValue(called, 0);
assert.sameValue(typeof iteraror.next, 'function');
assert.throws(TypeError, function() {
iterator.next();
}, 'iterator.next throws a TypeError if IsFinalizationGroupCleanupJobActive is false');

View File

@ -0,0 +1,52 @@
// 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: Return abrupt completion from CleanupFinalizationGroup (using CleanupCallback)
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.
CleanupFinalizationGroup ( finalizationGroup [ , callback ] )
4. If callback is undefined, set callback to finalizationGroup.[[CleanupCallback]].
5. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to true.
6. Let result be Call(callback, undefined, « iterator »).
7. Set finalizationGroup.[[IsFinalizationGroupCleanupJobActive]] to false.
8. If result is an abrupt completion, return result.
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class, host-gc-required]
---*/
var iterator;
function poisoned(iter) {
iterator = iter;
iter.next(); // Won't throw
throw new Test262Error();
}
var fg = new FinalizationGroup(poisoned);
function emptyCells() {
(function() {
var o = {};
fg.register(o);
})();
$262.gc();
}
emptyCells();
assert.throws(Test262Error, function() {
fg.cleanupSome();
});
assert.sameValue(typeof iteraror.next, 'function');
assert.throws(TypeError, function() {
iterator.next();
}, 'iterator.next throws a TypeError if IsFinalizationGroupCleanupJobActive is false');

View File

@ -11,7 +11,7 @@ info: |
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).
5. Perform ? CleanupFinalizationGroup(finalizationGroup, callback).
6. Return undefined.
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class, host-gc-required]
---*/
@ -25,17 +25,13 @@ var cb = function() {
called += 1;
return 42;
};
var poisoned = function() { throw new Test262Error(); };
var fg = new FinalizationGroup(fn);
function emptyCells(custom) {
function emptyCells() {
called = 0;
if (!custom) {
custom = fg;
}
(function() {
var o = {};
custom.register(o);
fg.register(o);
})();
$262.gc();
}
@ -54,9 +50,6 @@ assert.sameValue(fg.cleanupSome(() => 1), undefined, 'arrow function');
emptyCells();
assert.sameValue(fg.cleanupSome(fg.cleanupSome), undefined, 'cleanupSome itself');
emptyCells();
assert.sameValue(fg.cleanupSome(poisoned), undefined, 'poisoned');
emptyCells();
assert.sameValue(fg.cleanupSome(class {}), undefined, 'class expression');
@ -74,11 +67,3 @@ assert.sameValue(fg.cleanupSome(), undefined, 'undefined, implicit');
emptyCells();
assert.sameValue(fg.cleanupSome(undefined), undefined, 'undefined, explicit');
var poisonedFg = new FinalizationGroup(poisoned);
emptyCells(poisonedFg);
assert.sameValue(poisonedFg.cleanupSome(cb), undefined, 'regular callback on poisoned FG cleanup callback');
emptyCells(poisonedFg);
assert.sameValue(poisonedFg.cleanupSome(poisoned), undefined, 'poisoned callback on poisoned FG cleanup callback');

View File

@ -11,7 +11,7 @@ info: |
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).
5. Perform ? CleanupFinalizationGroup(finalizationGroup, callback).
6. Return undefined.
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class]
---*/