mirror of https://github.com/tc39/test262.git
Fix tests for FinalizationGroup
This commit is contained in:
parent
166d5ac589
commit
7c7d3f756c
58
test/built-ins/FinalizationGroup/prototype/cleanupSome/poisoned-callback-throws.js
vendored
Normal file
58
test/built-ins/FinalizationGroup/prototype/cleanupSome/poisoned-callback-throws.js
vendored
Normal 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');
|
52
test/built-ins/FinalizationGroup/prototype/cleanupSome/poisoned-cleanup-callback-throws.js
vendored
Normal file
52
test/built-ins/FinalizationGroup/prototype/cleanupSome/poisoned-cleanup-callback-throws.js
vendored
Normal 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');
|
|
@ -11,7 +11,7 @@ info: |
|
||||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
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.
|
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.
|
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.
|
6. Return undefined.
|
||||||
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class, host-gc-required]
|
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class, host-gc-required]
|
||||||
---*/
|
---*/
|
||||||
|
@ -25,17 +25,13 @@ var cb = function() {
|
||||||
called += 1;
|
called += 1;
|
||||||
return 42;
|
return 42;
|
||||||
};
|
};
|
||||||
var poisoned = function() { throw new Test262Error(); };
|
|
||||||
var fg = new FinalizationGroup(fn);
|
var fg = new FinalizationGroup(fn);
|
||||||
|
|
||||||
function emptyCells(custom) {
|
function emptyCells() {
|
||||||
called = 0;
|
called = 0;
|
||||||
if (!custom) {
|
|
||||||
custom = fg;
|
|
||||||
}
|
|
||||||
(function() {
|
(function() {
|
||||||
var o = {};
|
var o = {};
|
||||||
custom.register(o);
|
fg.register(o);
|
||||||
})();
|
})();
|
||||||
$262.gc();
|
$262.gc();
|
||||||
}
|
}
|
||||||
|
@ -54,9 +50,6 @@ assert.sameValue(fg.cleanupSome(() => 1), undefined, 'arrow function');
|
||||||
emptyCells();
|
emptyCells();
|
||||||
assert.sameValue(fg.cleanupSome(fg.cleanupSome), undefined, 'cleanupSome itself');
|
assert.sameValue(fg.cleanupSome(fg.cleanupSome), undefined, 'cleanupSome itself');
|
||||||
|
|
||||||
emptyCells();
|
|
||||||
assert.sameValue(fg.cleanupSome(poisoned), undefined, 'poisoned');
|
|
||||||
|
|
||||||
emptyCells();
|
emptyCells();
|
||||||
assert.sameValue(fg.cleanupSome(class {}), undefined, 'class expression');
|
assert.sameValue(fg.cleanupSome(class {}), undefined, 'class expression');
|
||||||
|
|
||||||
|
@ -74,11 +67,3 @@ assert.sameValue(fg.cleanupSome(), undefined, 'undefined, implicit');
|
||||||
|
|
||||||
emptyCells();
|
emptyCells();
|
||||||
assert.sameValue(fg.cleanupSome(undefined), undefined, 'undefined, explicit');
|
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');
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ info: |
|
||||||
2. If Type(finalizationGroup) is not Object, throw a TypeError exception.
|
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.
|
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.
|
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.
|
6. Return undefined.
|
||||||
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class]
|
features: [FinalizationGroup, arrow-function, async-functions, async-iteration, class]
|
||||||
---*/
|
---*/
|
||||||
|
|
Loading…
Reference in New Issue