test262/test/built-ins/FinalizationRegistry/target-not-callable-throws.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-06-03 22:59:39 +02:00
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-finalization-registry-target
2019-06-03 22:59:39 +02:00
description: >
Throws a TypeError if target is not callable
info: |
FinalizationRegistry ( cleanupCallback )
2019-06-03 22:59:39 +02:00
1. If NewTarget is undefined, throw a TypeError exception.
2. If IsCallable(cleanupCallback) is false, throw a TypeError exception.
...
features: [FinalizationRegistry, WeakRef]
2019-06-03 22:59:39 +02:00
---*/
assert.sameValue(
typeof FinalizationRegistry, 'function',
'typeof FinalizationRegistry is function'
2019-06-03 22:59:39 +02:00
);
assert.throws(TypeError, function() {
new FinalizationRegistry({});
2019-06-03 22:59:39 +02:00
}, 'ordinary object');
assert.throws(TypeError, function() {
new FinalizationRegistry(WeakRef.prototype);
2019-06-03 22:59:39 +02:00
}, 'WeakRef.prototype');
assert.throws(TypeError, function() {
new FinalizationRegistry(FinalizationRegistry.prototype);
}, 'FinalizationRegistry.prototype');
2019-06-03 22:59:39 +02:00
assert.throws(TypeError, function() {
new FinalizationRegistry([]);
2019-06-03 22:59:39 +02:00
}, 'Array');
assert.throws(TypeError, function() {
new FinalizationRegistry();
2019-06-03 22:59:39 +02:00
}, 'implicit undefined');
assert.throws(TypeError, function() {
new FinalizationRegistry(undefined);
2019-06-03 22:59:39 +02:00
}, 'explicit undefined');
assert.throws(TypeError, function() {
new FinalizationRegistry(null);
2019-06-03 22:59:39 +02:00
}, 'null');
assert.throws(TypeError, function() {
new FinalizationRegistry(1);
2019-06-03 22:59:39 +02:00
}, 'number');
assert.throws(TypeError, function() {
new FinalizationRegistry('Object');
2019-06-03 22:59:39 +02:00
}, 'string');
var s = Symbol();
assert.throws(TypeError, function() {
new FinalizationRegistry(s);
2019-06-03 22:59:39 +02:00
}, 'symbol');
assert.throws(TypeError, function() {
new FinalizationRegistry(true);
2019-06-03 22:59:39 +02:00
}, 'Boolean, true');
assert.throws(TypeError, function() {
new FinalizationRegistry(false);
2019-06-03 22:59:39 +02:00
}, 'Boolean, false');