ticaiolima@gmail.com | 009b198 | 2018-05-17 04:27:28 +0000 | [diff] [blame] | 1 | //@ runBigIntEnabled |
| 2 | |
| 3 | function assert(a, message) { |
| 4 | if (!a) |
| 5 | throw new Error(message); |
| 6 | } |
| 7 | |
| 8 | function 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 | |
| 17 | assertThrowTypeError(30n, "foo", "BigInt / String"); |
| 18 | assertThrowTypeError("bar", 18757382984821n, "String / BigInt"); |
| 19 | assertThrowTypeError(30n, Symbol("foo"), "BigInt / Symbol"); |
| 20 | assertThrowTypeError(Symbol("bar"), 18757382984821n, "Symbol / BigInt"); |
| 21 | assertThrowTypeError(30n, 3320, "BigInt / Int32"); |
| 22 | assertThrowTypeError(33256, 18757382984821n, "Int32 / BigInt"); |
| 23 | assertThrowTypeError(30n, 0.543, "BigInt / Double"); |
| 24 | assertThrowTypeError(230.19293, 18757382984821n, "Double / BigInt"); |
| 25 | assertThrowTypeError(30n, NaN, "BigInt / NaN"); |
| 26 | assertThrowTypeError(NaN, 18757382984821n, "NaN / BigInt"); |
| 27 | assertThrowTypeError(30n, NaN, "BigInt / NaN"); |
| 28 | assertThrowTypeError(NaN, 18757382984821n, "NaN / BigInt"); |
| 29 | assertThrowTypeError(30n, +Infinity, "BigInt / NaN"); |
| 30 | assertThrowTypeError(+Infinity, 18757382984821n, "NaN / BigInt"); |
| 31 | assertThrowTypeError(30n, -Infinity, "BigInt / -Infinity"); |
| 32 | assertThrowTypeError(-Infinity, 18757382984821n, "-Infinity / BigInt"); |
| 33 | assertThrowTypeError(30n, null, "BigInt / null"); |
| 34 | assertThrowTypeError(null, 18757382984821n, "null / BigInt"); |
| 35 | assertThrowTypeError(30n, undefined, "BigInt / undefined"); |
| 36 | assertThrowTypeError(undefined, 18757382984821n, "undefined / BigInt"); |
| 37 | assertThrowTypeError(30n, true, "BigInt * true"); |
| 38 | assertThrowTypeError(true, 18757382984821n, "true / BigInt"); |
| 39 | assertThrowTypeError(30n, false, "BigInt / false"); |
| 40 | assertThrowTypeError(false, 18757382984821n, "false / BigInt"); |
| 41 | |
| 42 | // Error when returning from object |
| 43 | |
| 44 | let o = { |
| 45 | valueOf: function () { return Symbol("Foo"); } |
| 46 | }; |
| 47 | |
| 48 | assertThrowTypeError(30n, o, "BigInt / Object.valueOf returning Symbol"); |
| 49 | assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Symbol / BigInt"); |
| 50 | |
| 51 | o = { |
| 52 | valueOf: function () { return 33256; } |
| 53 | }; |
| 54 | |
| 55 | assertThrowTypeError(30n, o, "BigInt / Object.valueOf returning Int32"); |
| 56 | assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Int32 / BigInt"); |
| 57 | |
| 58 | o = { |
| 59 | valueOf: function () { return 0.453; } |
| 60 | }; |
| 61 | |
| 62 | assertThrowTypeError(30n, o, "BigInt / Object.valueOf returning Double"); |
| 63 | assertThrowTypeError(o, 18757382984821n, "Object.valueOf returning Double / BigInt"); |
| 64 | |
| 65 | o = { |
| 66 | toString: function () { return Symbol("Foo"); } |
| 67 | }; |
| 68 | |
| 69 | assertThrowTypeError(30n, o, "BigInt / Object.toString returning Symbol"); |
| 70 | assertThrowTypeError(o, 18757382984821n, "Object.toString returning Symbol / BigInt"); |
| 71 | |
| 72 | o = { |
| 73 | toString: function () { return 33256; } |
| 74 | }; |
| 75 | |
| 76 | assertThrowTypeError(30n, o, "BigInt / Object.toString returning Int32"); |
| 77 | assertThrowTypeError(o, 18757382984821n, "Object.toString returning Int32 / BigInt"); |
| 78 | |
| 79 | o = { |
| 80 | toString: function () { return 0.453; } |
| 81 | }; |
| 82 | |
| 83 | assertThrowTypeError(30n, o, "BigInt / Object.toString returning Double"); |
| 84 | assertThrowTypeError(o, 18757382984821n, "Object.toString returning Double / BigInt"); |
| 85 | |
| 86 | o = { |
| 87 | [Symbol.toPrimitive]: function () { return Symbol("Foo"); } |
| 88 | }; |
| 89 | |
| 90 | assertThrowTypeError(30n, o, "BigInt / Object.@@toPrimitive returning Symbol"); |
| 91 | assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Symbol / BigInt"); |
| 92 | |
| 93 | o = { |
| 94 | [Symbol.toPrimitive]: function () { return 33256; } |
| 95 | }; |
| 96 | |
| 97 | assertThrowTypeError(30n, o, "BigInt / Object.@@toPrimitive returning Int32"); |
| 98 | assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Int32 / BigInt"); |
| 99 | |
| 100 | o = { |
| 101 | [Symbol.toPrimitive]: function () { return 0.453; } |
| 102 | }; |
| 103 | |
| 104 | assertThrowTypeError(30n, o, "BigInt / Object.@@toPrimitive returning Double"); |
| 105 | assertThrowTypeError(o, 18757382984821n, "Object.@@toPrimitive returning Double / BigInt"); |
| 106 | |