@@ -17,6 +17,10 @@ import scala.scalajs.js.annotation._
17
17
18
18
import org .junit .Test
19
19
import org .junit .Assert ._
20
+ import org .junit .Assume ._
21
+
22
+ import org .scalajs .testsuite .utils .AssertThrows .assertThrows
23
+ import org .scalajs .testsuite .utils .Platform ._
20
24
21
25
class RegressionJSTest {
22
26
import RegressionJSTest ._
@@ -96,6 +100,43 @@ class RegressionJSTest {
96
100
assertEquals(6 , obj2.bar)
97
101
}
98
102
103
+ @ Test def preserveSideEffectsOfJSOpsWithBigInts_Issue4621 (): Unit = {
104
+ assumeTrue(" requires BigInts support" , jsBigInts)
105
+
106
+ @ noinline def bi (x : Int ): js.BigInt = js.BigInt (x)
107
+
108
+ // These must be stored as `val`s first in order to trigger the original problem
109
+ val bi5 : Any = bi(5 )
110
+ val bi0 : Any = bi(0 )
111
+ val bi1 : Any = bi(1 )
112
+
113
+ assertThrows(classOf [js.JavaScriptException ], {
114
+ bi5.asInstanceOf [js.Dynamic ] / bi0.asInstanceOf [js.Dynamic ]
115
+ fail(" unreachable" ) // required for the above line to be in statement position
116
+ })
117
+ assertThrows(classOf [js.JavaScriptException ], {
118
+ + bi5.asInstanceOf [js.Dynamic ]
119
+ fail(" unreachable" )
120
+ })
121
+ }
122
+
123
+ @ Test def preserveSideEffectsOfJSOpsWithCustomValueOf_Issue4621 (): Unit = {
124
+ // This must be a `val` in order to trigger the original problem
125
+ val obj : Any = new js.Object {
126
+ override def valueOf (): Double =
127
+ throw new UnsupportedOperationException ()
128
+ }
129
+
130
+ assertThrows(classOf [UnsupportedOperationException ], {
131
+ obj.asInstanceOf [js.Dynamic ] + 5 .asInstanceOf [js.Dynamic ]
132
+ fail(" unreachable" )
133
+ })
134
+ assertThrows(classOf [UnsupportedOperationException ], {
135
+ - obj.asInstanceOf [js.Dynamic ]
136
+ fail(" unreachable" )
137
+ })
138
+ }
139
+
99
140
}
100
141
101
142
object RegressionJSTest {
0 commit comments