Debian Codegraph @

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

raw
1 // |reftest| skip-if(!this.hasOwnProperty('FinalizationRegistry')||!this.hasOwnProperty('WeakRef')) -- FinalizationRegistry,WeakRef is not enabled unconditionally
2 // Copyright (C) 2019 Leo Balter. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-finalization-registry-target
7 description: >
8 Throws a TypeError if target is not callable
9 info: |
10 FinalizationRegistry ( cleanupCallback )
11
12 1. If NewTarget is undefined, throw a TypeError exception.
13 2. If IsCallable(cleanupCallback) is false, throw a TypeError exception.
14 ...
15 features: [FinalizationRegistry, WeakRef]
16 ---*/
17
18 assert.sameValue(
19 typeof FinalizationRegistry, 'function',
20 'typeof FinalizationRegistry is function'
21 );
22
23 assert.throws(TypeError, function() {
24 new FinalizationRegistry({});
25 }, 'ordinary object');
26
27 assert.throws(TypeError, function() {
28 new FinalizationRegistry(WeakRef.prototype);
29 }, 'WeakRef.prototype');
30
31 assert.throws(TypeError, function() {
32 new FinalizationRegistry(FinalizationRegistry.prototype);
33 }, 'FinalizationRegistry.prototype');
34
35 assert.throws(TypeError, function() {
36 new FinalizationRegistry([]);
37 }, 'Array');
38
39 assert.throws(TypeError, function() {
40 new FinalizationRegistry();
41 }, 'implicit undefined');
42
43 assert.throws(TypeError, function() {
44 new FinalizationRegistry(undefined);
45 }, 'explicit undefined');
46
47 assert.throws(TypeError, function() {
48 new FinalizationRegistry(null);
49 }, 'null');
50
51 assert.throws(TypeError, function() {
52 new FinalizationRegistry(1);
53 }, 'number');
54
55 assert.throws(TypeError, function() {
56 new FinalizationRegistry('Object');
57 }, 'string');
58
59 var s = Symbol();
60 assert.throws(TypeError, function() {
61 new FinalizationRegistry(s);
62 }, 'symbol');
63
64 assert.throws(TypeError, function() {
65 new FinalizationRegistry(true);
66 }, 'Boolean, true');
67
68 assert.throws(TypeError, function() {
69 new FinalizationRegistry(false);
70 }, 'Boolean, false');
71
72 reportCompare(0, 0);