mirror of https://github.com/tc39/test262.git
Add tests for cleanupSome
This commit is contained in:
parent
dcac20d8ed
commit
ca11ac4a43
57
test/built-ins/FinalizationGroup/prototype/cleanupSome/callback-not-callable-throws.js
vendored
Normal file
57
test/built-ins/FinalizationGroup/prototype/cleanupSome/callback-not-callable-throws.js
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
// 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: Throws a TypeError if callback is not callable
|
||||
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.
|
||||
...
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.cleanupSome, 'function');
|
||||
|
||||
var fg = new FinalizationGroup(function() {});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg(undefined);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg(null);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg(true);
|
||||
}, 'true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg(false);
|
||||
}, 'false');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg(1);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg('object');
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
fg(s);
|
||||
}, 'symbol');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg({});
|
||||
}, 'object');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
fg(FinalizationGroup.prototype);
|
||||
}, 'FinalizationGroup.prototype');
|
|
@ -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.cleanupSome
|
||||
description: Return values applying custom this
|
||||
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]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var cleanupSome = FinalizationGroup.prototype.cleanupSome;
|
||||
var fg = new FinalizationGroup(fn);
|
||||
|
||||
var cb = function() {};
|
||||
|
||||
assert.sameValue(cleanupSome.call(fg, cb), undefined);
|
||||
assert.sameValue(cleanupSome.call(fg, fn), undefined), 'reuse the same cleanup callback fn';
|
|
@ -0,0 +1,32 @@
|
|||
// 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: FinalizationGroup.prototype.cleanupSome.length property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome ( [ callback ] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
Every built-in function object, including constructors, has a length
|
||||
property whose value is an integer. Unless otherwise specified, this
|
||||
value is equal to the largest number of named arguments shown in the
|
||||
subclause headings for the function description. Optional parameters
|
||||
(which are indicated with brackets: [ ]) or rest parameters (which
|
||||
are shown using the form «...name») are not included in the default
|
||||
argument count.
|
||||
|
||||
Unless otherwise specified, the length property of a built-in
|
||||
function object has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype.cleanupSome, 'length', {
|
||||
value: 0,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
// 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: FinalizationGroup.prototype.cleanupSome.name property descriptor
|
||||
info: |
|
||||
FinalizationGroup.prototype.cleanupSome.name value and property descriptor
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
Every built-in function object, including constructors, that is not
|
||||
identified as an anonymous function has a name property whose value
|
||||
is a String. Unless otherwise specified, this value is the name that
|
||||
is given to the function in this specification. For functions that
|
||||
are specified as properties of objects, the name value is the
|
||||
property name string used to access the function. [...]
|
||||
|
||||
Unless otherwise specified, the name property of a built-in function
|
||||
object, if it exists, has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype.cleanupSome, 'name', {
|
||||
value: 'cleanupSome',
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
// 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: >
|
||||
Property descriptor of FinalizationGroup.prototype.cleanupSome
|
||||
info: |
|
||||
17 ECMAScript Standard Built-in Objects:
|
||||
|
||||
Every other data property described in clauses 18 through 26 and in Annex B.2
|
||||
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.cleanupSome, 'function');
|
||||
|
||||
verifyProperty(FinalizationGroup.prototype, 'cleanupSome', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
});
|
|
@ -0,0 +1,41 @@
|
|||
// 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 undefined regardless the result of 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.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var fn = function() {};
|
||||
var cb = function() {};
|
||||
var poisoned = function() { throw new Test262Error(); };
|
||||
var fg = new FinalizationGroup(fn);
|
||||
|
||||
assert.sameValue(fg.cleanupSome(cb), undefined, 'regular callback');
|
||||
assert.sameValue(fg.cleanupSome(fn), undefined, 'regular callback, same FG cleanup function');
|
||||
|
||||
assert.sameValue(fg.cleanupSome(() => {}), undefined, 'arrow function');
|
||||
assert.sameValue(fg.cleanupSome(fg.cleanupSome), undefined, 'cleanupSome itself');
|
||||
assert.sameValue(fg.cleanupSome(poisoned), undefined, 'poisoned');
|
||||
assert.sameValue(fg.cleanupSome(class {}), undefined, 'class expression');
|
||||
assert.sameValue(fg.cleanupSome(async function() {}), undefined, 'async function');
|
||||
assert.sameValue(fg.cleanupSome(function *() {}), undefined, 'generator');
|
||||
assert.sameValue(fg.cleanupSome(async function *() {}), undefined, 'async generator');
|
||||
|
||||
assert.sameValue(fg.cleanupSome(), undefined, 'undefined, implicit');
|
||||
assert.sameValue(fg.cleanupSome(undefined), undefined, 'undefined, explicit');
|
||||
|
||||
var poisonedFg = new FinalizationGroup(poisoned);
|
||||
|
||||
assert.sameValue(poisonedFg.cleanupSome(cb), undefined, 'regular callback on poisoned FG cleanup callback');
|
||||
assert.sameValue(poisonedFg.cleanupSome(poisoned), undefined, 'poisoned callback on poisoned FG cleanup callback');
|
|
@ -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: Throws a TypeError if this does not have a [[Cells]] internal slot
|
||||
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.
|
||||
...
|
||||
features: [FinalizationGroup, WeakRef]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.cleanupSome, 'function');
|
||||
|
||||
var cleanupSome = FinalizationGroup.prototype.cleanupSome;
|
||||
var cb = function() {};
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call({ ['[[Cells]]']: {} }, cb);
|
||||
}, 'Ordinary object without [[Cells]]');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(WeakRef.prototype, cb);
|
||||
}, 'WeakRef.prototype does not have a [[Cells]] internal slot');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(WeakRef, cb);
|
||||
}, 'WeakRef does not have a [[Cells]] internal slot');
|
||||
|
||||
var wr = new WeakRef({});
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(wr, cb);
|
||||
}, 'WeakRef instance');
|
||||
|
||||
var wm = new WeakMap();
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(wm, cb);
|
||||
}, 'WeakMap instance');
|
||||
|
||||
var ws = new WeakSet();
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(ws, cb);
|
||||
}, 'WeakSet instance');
|
50
test/built-ins/FinalizationGroup/prototype/cleanupSome/this-not-object-throws.js
vendored
Normal file
50
test/built-ins/FinalizationGroup/prototype/cleanupSome/this-not-object-throws.js
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
// 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: Throws a TypeError if this is not an Object
|
||||
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.
|
||||
...
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof FinalizationGroup.prototype.cleanupSome, 'function');
|
||||
|
||||
var cleanupSome = FinalizationGroup.prototype.cleanupSome;
|
||||
var cb = function() {};
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(undefined, cb);
|
||||
}, 'undefined');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(null, cb);
|
||||
}, 'null');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(true, cb);
|
||||
}, 'true');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(false, cb);
|
||||
}, 'false');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(1, cb);
|
||||
}, 'number');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call('object', cb);
|
||||
}, 'string');
|
||||
|
||||
var s = Symbol();
|
||||
assert.throws(TypeError, function() {
|
||||
cleanupSome.call(s, cb);
|
||||
}, 'symbol');
|
|
@ -24,6 +24,7 @@ features: [FinalizationGroup]
|
|||
var cleanupCallback = function() {};
|
||||
var fg = new FinalizationGroup(cleanupCallback);
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype);
|
||||
assert.notSameValue(fg, cleanupCallback, 'does not return the same function');
|
||||
assert.sameValue(fg instanceof FinalizationGroup, true, 'instanceof');
|
||||
|
||||
|
@ -36,5 +37,3 @@ for (let key of Object.getOwnPropertySymbols(fg)) {
|
|||
}
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype);
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// 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-target
|
||||
description: >
|
||||
Normal completion even if the cleanupCallback fn is poisoned
|
||||
info: |
|
||||
FinalizationGroup ( cleanupCallback )
|
||||
|
||||
...
|
||||
3. Let finalizationGroup be ? OrdinaryCreateFromConstructor(NewTarget, "%FinalizationGroupPrototype%", « [[Realm]], [[CleanupCallback]], [[Cells]], [[IsFinalizationGroupCleanupJobActive]] »).
|
||||
...
|
||||
9. Return finalizationGroup.
|
||||
features: [FinalizationGroup]
|
||||
---*/
|
||||
|
||||
var cleanupCallback = function() { throw new Test262Error('should not throw yet'); };
|
||||
var fg = new FinalizationGroup(cleanupCallback);
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype);
|
||||
assert.notSameValue(fg, cleanupCallback, 'does not return the same function');
|
||||
assert.sameValue(fg instanceof FinalizationGroup, true, 'instanceof');
|
||||
|
||||
for (let key of Object.getOwnPropertyNames(fg)) {
|
||||
assert(false, `should not set any own named properties: ${key}`);
|
||||
}
|
||||
|
||||
for (let key of Object.getOwnPropertySymbols(fg)) {
|
||||
assert(false, `should not set any own symbol properties: ${String(key)}`);
|
||||
}
|
||||
|
||||
assert.sameValue(Object.getPrototypeOf(fg), FinalizationGroup.prototype);
|
Loading…
Reference in New Issue