[WASM] Fix invalid exception type for IOOB array access

This commit is contained in:
Igor Yakovlev
2021-11-25 13:19:11 +01:00
committed by TeamCityServer
parent 2e78a1cd90
commit 86daff8ae8
2 changed files with 45 additions and 18 deletions
@@ -40,8 +40,10 @@ public class Array<T> constructor(size: Int) {
* where the behavior is unspecified.
*/
@Suppress("UNCHECKED_CAST")
public operator fun get(index: Int): T =
storage.get(index) as T
public operator fun get(index: Int): T {
if (index < 0 || index >= storage.len()) throw IndexOutOfBoundsException()
return storage.get(index) as T
}
/**
* Sets the array element at the specified [index] to the specified [value]. This method can
@@ -54,6 +56,7 @@ public class Array<T> constructor(size: Int) {
* where the behavior is unspecified.
*/
public operator fun set(index: Int, value: T) {
if (index < 0 || index >= storage.len()) throw IndexOutOfBoundsException()
storage.set(index, value)
}