bigint-number-mix-errors.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. load("test-common.js");
  2. try {
  3. [1, null, undefined].forEach(value => {
  4. assertThrowsError(() => {
  5. 1n + value;
  6. }, {
  7. error: TypeError,
  8. message: "Cannot use addition operator with BigInt and other type"
  9. });
  10. assertThrowsError(() => {
  11. 1n - value;
  12. }, {
  13. error: TypeError,
  14. message: "Cannot use subtraction operator with BigInt and other type"
  15. });
  16. assertThrowsError(() => {
  17. 1n * value;
  18. }, {
  19. error: TypeError,
  20. message: "Cannot use multiplication operator with BigInt and other type"
  21. });
  22. assertThrowsError(() => {
  23. 1n / value;
  24. }, {
  25. error: TypeError,
  26. message: "Cannot use division operator with BigInt and other type"
  27. });
  28. assertThrowsError(() => {
  29. 1n % value;
  30. }, {
  31. error: TypeError,
  32. message: "Cannot use modulo operator with BigInt and other type"
  33. });
  34. assertThrowsError(() => {
  35. 1n ** value;
  36. }, {
  37. error: TypeError,
  38. message: "Cannot use exponentiation operator with BigInt and other type"
  39. });
  40. assertThrowsError(() => {
  41. 1n | value;
  42. }, {
  43. error: TypeError,
  44. message: "Cannot use bitwise OR operator with BigInt and other type"
  45. });
  46. assertThrowsError(() => {
  47. 1n & value;
  48. }, {
  49. error: TypeError,
  50. message: "Cannot use bitwise AND operator with BigInt and other type"
  51. });
  52. assertThrowsError(() => {
  53. 1n ^ value;
  54. }, {
  55. error: TypeError,
  56. message: "Cannot use bitwise XOR operator with BigInt and other type"
  57. });
  58. assertThrowsError(() => {
  59. 1n << value;
  60. }, {
  61. error: TypeError,
  62. message: "Cannot use left-shift operator with BigInt and other type"
  63. });
  64. assertThrowsError(() => {
  65. 1n >> value;
  66. }, {
  67. error: TypeError,
  68. message: "Cannot use right-shift operator with BigInt and other type"
  69. });
  70. assertThrowsError(() => {
  71. 1n >>> value;
  72. }, {
  73. error: TypeError,
  74. message: "Cannot use unsigned right-shift operator with BigInt"
  75. });
  76. });
  77. console.log("PASS");
  78. } catch (e) {
  79. console.log("FAIL: " + e);
  80. }