summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/FinalizationRegistry/target-not-callable-throws.js
blob: e68fecc72e217eb337c05d5cb8504333357b3d45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// |reftest| skip-if(!this.hasOwnProperty('FinalizationRegistry')||!this.hasOwnProperty('WeakRef')) -- FinalizationRegistry,WeakRef is not enabled unconditionally
// 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
description: >
  Throws a TypeError if target is not callable
info: |
  FinalizationRegistry ( cleanupCallback )

  1. If NewTarget is undefined, throw a TypeError exception.
  2. If IsCallable(cleanupCallback) is false, throw a TypeError exception.
  ...
features: [FinalizationRegistry, WeakRef]
---*/

assert.sameValue(
  typeof FinalizationRegistry, 'function',
  'typeof FinalizationRegistry is function'
);

assert.throws(TypeError, function() {
  new FinalizationRegistry({});
}, 'ordinary object');

assert.throws(TypeError, function() {
  new FinalizationRegistry(WeakRef.prototype);
}, 'WeakRef.prototype');

assert.throws(TypeError, function() {
  new FinalizationRegistry(FinalizationRegistry.prototype);
}, 'FinalizationRegistry.prototype');

assert.throws(TypeError, function() {
  new FinalizationRegistry([]);
}, 'Array');

assert.throws(TypeError, function() {
  new FinalizationRegistry();
}, 'implicit undefined');

assert.throws(TypeError, function() {
  new FinalizationRegistry(undefined);
}, 'explicit undefined');

assert.throws(TypeError, function() {
  new FinalizationRegistry(null);
}, 'null');

assert.throws(TypeError, function() {
  new FinalizationRegistry(1);
}, 'number');

assert.throws(TypeError, function() {
  new FinalizationRegistry('Object');
}, 'string');

var s = Symbol();
assert.throws(TypeError, function() {
  new FinalizationRegistry(s);
}, 'symbol');

assert.throws(TypeError, function() {
  new FinalizationRegistry(true);
}, 'Boolean, true');

assert.throws(TypeError, function() {
  new FinalizationRegistry(false);
}, 'Boolean, false');

reportCompare(0, 0);