bigint-number-mix-errors.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. load("test-common.js");
  2. try {
  3. [1, null, undefined].forEach(value => {
  4. assertThrowsError(
  5. () => {
  6. 1n + value;
  7. },
  8. {
  9. error: TypeError,
  10. message: "Cannot use addition operator with BigInt and other type",
  11. }
  12. );
  13. assertThrowsError(
  14. () => {
  15. 1n - value;
  16. },
  17. {
  18. error: TypeError,
  19. message: "Cannot use subtraction operator with BigInt and other type",
  20. }
  21. );
  22. assertThrowsError(
  23. () => {
  24. 1n * value;
  25. },
  26. {
  27. error: TypeError,
  28. message: "Cannot use multiplication operator with BigInt and other type",
  29. }
  30. );
  31. assertThrowsError(
  32. () => {
  33. 1n / value;
  34. },
  35. {
  36. error: TypeError,
  37. message: "Cannot use division operator with BigInt and other type",
  38. }
  39. );
  40. assertThrowsError(
  41. () => {
  42. 1n % value;
  43. },
  44. {
  45. error: TypeError,
  46. message: "Cannot use modulo operator with BigInt and other type",
  47. }
  48. );
  49. assertThrowsError(
  50. () => {
  51. 1n ** value;
  52. },
  53. {
  54. error: TypeError,
  55. message: "Cannot use exponentiation operator with BigInt and other type",
  56. }
  57. );
  58. assertThrowsError(
  59. () => {
  60. 1n | value;
  61. },
  62. {
  63. error: TypeError,
  64. message: "Cannot use bitwise OR operator with BigInt and other type",
  65. }
  66. );
  67. assertThrowsError(
  68. () => {
  69. 1n & value;
  70. },
  71. {
  72. error: TypeError,
  73. message: "Cannot use bitwise AND operator with BigInt and other type",
  74. }
  75. );
  76. assertThrowsError(
  77. () => {
  78. 1n ^ value;
  79. },
  80. {
  81. error: TypeError,
  82. message: "Cannot use bitwise XOR operator with BigInt and other type",
  83. }
  84. );
  85. assertThrowsError(
  86. () => {
  87. 1n << value;
  88. },
  89. {
  90. error: TypeError,
  91. message: "Cannot use left-shift operator with BigInt and other type",
  92. }
  93. );
  94. assertThrowsError(
  95. () => {
  96. 1n >> value;
  97. },
  98. {
  99. error: TypeError,
  100. message: "Cannot use right-shift operator with BigInt and other type",
  101. }
  102. );
  103. assertThrowsError(
  104. () => {
  105. 1n >>> value;
  106. },
  107. {
  108. error: TypeError,
  109. message: "Cannot use unsigned right-shift operator with BigInt",
  110. }
  111. );
  112. });
  113. console.log("PASS");
  114. } catch (e) {
  115. console.log("FAIL: " + e);
  116. }