blob: 27982cd78e030150eafaa4f9346e4f667d5e661b [file] [log] [blame]
ticaiolima@gmail.com009b1982018-05-17 04:27:28 +00001//@ runBigIntEnabled
2
3function assert(a, message) {
4 if (!a)
5 throw new Error(message);
6}
7
8function assertThrowTypeError(a, b, message) {
9 try {
10 let n = a / b;
11 assert(false, message + ": Should throw TypeError, but executed without exception");
12 } catch (e) {
13 assert(e instanceof TypeError, message + ": expected TypeError, got: " + e);
14 }
15}
16
17assertThrowTypeError(30n, "foo", "BigInt / String");
18assertThrowTypeError("bar", 18757382984821n, "String / BigInt");
19assertThrowTypeError(30n, Symbol("foo"), "BigInt / Symbol");
20assertThrowTypeError(Symbol("bar"), 18757382984821n, "Symbol / BigInt");
21assertThrowTypeError(30n, 3320, "BigInt / Int32");
22assertThrowTypeError(33256, 18757382984821n, "Int32 / BigInt");
23assertThrowTypeError(30n, 0.543, "BigInt / Double");
24assertThrowTypeError(230.19293, 18757382984821n, "Double / BigInt");
25assertThrowTypeError(30n, NaN, "BigInt / NaN");
26assertThrowTypeError(NaN, 18757382984821n, "NaN / BigInt");
27assertThrowTypeError(30n, NaN, "BigInt / NaN");
28assertThrowTypeError(NaN, 18757382984821n, "NaN / BigInt");
29assertThrowTypeError(30n, +Infinity, "BigInt / NaN");
30assertThrowTypeError(+Infinity, 18757382984821n, "NaN / BigInt");
31assertThrowTypeError(30n, -Infinity, "BigInt / -Infinity");
32assertThrowTypeError(-Infinity, 18757382984821n, "-Infinity / BigInt");
33assertThrowTypeError(30n, null, "BigInt / null");
34assertThrowTypeError(null, 18757382984821n, "null / BigInt");
35assertThrowTypeError(30n, undefined, "BigInt / undefined");
36assertThrowTypeError(undefined, 18757382984821n, "undefined / BigInt");
37assertThrowTypeError(30n, true, "BigInt * true");
38assertThrowTypeError(true, 18757382984821n, "true / BigInt");
39assertThrowTypeError(30n, false, "BigInt / false");
40assertThrowTypeError(false, 18757382984821n, "false / BigInt");
41
42// Error when returning from object
43
44let o = {
45 valueOf: function () { return Symbol("Foo"); }
46};
47
48assertThrowTypeError(30n, o, "BigInt / Object.valueOf returning Symbol");
49assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Symbol / BigInt");
50
51o = {
52 valueOf: function () { return 33256; }
53};
54
55assertThrowTypeError(30n, o, "BigInt / Object.valueOf returning Int32");
56assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Int32 / BigInt");
57
58o = {
59 valueOf: function () { return 0.453; }
60};
61
62assertThrowTypeError(30n, o, "BigInt / Object.valueOf returning Double");
63assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Double / BigInt");
64
65o = {
66 toString: function () { return Symbol("Foo"); }
67};
68
69assertThrowTypeError(30n, o, "BigInt / Object.toString returning Symbol");
70assertThrowTypeError(o, 18757382984821n, "Object.toString returning Symbol / BigInt");
71
72o = {
73 toString: function () { return 33256; }
74};
75
76assertThrowTypeError(30n, o, "BigInt / Object.toString returning Int32");
77assertThrowTypeError(o, 18757382984821n, "Object.toString returning Int32 / BigInt");
78
79o = {
80 toString: function () { return 0.453; }
81};
82
83assertThrowTypeError(30n, o, "BigInt / Object.toString returning Double");
84assertThrowTypeError(o, 18757382984821n, "Object.toString returning Double / BigInt");
85
86o = {
87 [Symbol.toPrimitive]: function () { return Symbol("Foo"); }
88};
89
90assertThrowTypeError(30n, o, "BigInt / Object.@@toPrimitive returning Symbol");
91assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Symbol / BigInt");
92
93o = {
94 [Symbol.toPrimitive]: function () { return 33256; }
95};
96
97assertThrowTypeError(30n, o, "BigInt / Object.@@toPrimitive returning Int32");
98assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Int32 / BigInt");
99
100o = {
101 [Symbol.toPrimitive]: function () { return 0.453; }
102};
103
104assertThrowTypeError(30n, o, "BigInt / Object.@@toPrimitive returning Double");
105assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Double / BigInt");
106