summaryrefslogtreecommitdiff
path: root/test/built-ins/BigInt/prototype/toString/thisbigintvalue-not-valid-throws.js
blob: 78ae9bd6807660d6002435cc390b9e57917b0b4e (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
// Copyright 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-bigint.prototype.tostring
description: Throws a TypeError if the this value is not a BigInt
info: |
  BigInt.prototype.toString ( [ radix ] )

  1. Let x be ? thisBigIntValue(this value).
  ...

  The abstract operation thisBigIntValue(value) performs the following steps:

  1. If Type(value) is BigInt, return value.
  2. If Type(value) is Object and value has a [[BigIntData]] internal slot, then
    ...
  3. Throw a TypeError exception.
features: [BigInt, Symbol.toPrimitive]
---*/

var toString = BigInt.prototype.toString;

assert.throws(TypeError, function() {
  toString.call({x: 1n});
}, '{x: 1n}');

assert.throws(TypeError, function() {
  toString.call([1n]);
}, '[1n]');

var obj = {
  valueOf: function() { throw new Test262Error('no [[BigIntData]]') },
  toString: function() { throw new Test262Error('no [[BigIntData]]') },
  [Symbol.toPrimitive]: function() { throw new Test262Error('no [[BigIntData]]') }
};
assert.throws(TypeError, function() {
  toString.call(obj);
}, '{valueOf, toString, toPrimitive}');

assert.throws(TypeError, function() {
  toString.call(0);
}, '0');

assert.throws(TypeError, function() {
  toString.call(1);
}, '1');

assert.throws(TypeError, function() {
  toString.call(NaN);
}, 'NaN');

assert.throws(TypeError, function() {
  toString.call(undefined);
}, 'undefined');

assert.throws(TypeError, function() {
  toString.call(null);
}, 'null');

assert.throws(TypeError, function() {
  toString.call(true);
}, 'true');

assert.throws(TypeError, function() {
  toString.call(false);
}, 'false');