Throw IOOB on invalid index in JS StringBuilder.get to adhere contract

This commit is contained in:
Abduqodiri Qurbonzoda
2019-03-13 22:00:01 +03:00
parent 814d6cf39c
commit a369496aca
2 changed files with 14 additions and 1 deletions
+2 -1
View File
@@ -24,7 +24,8 @@ public actual class StringBuilder(content: String = "") : Appendable, CharSequen
actual override val length: Int
get() = string.asDynamic().length
actual override fun get(index: Int): Char = string[index]
actual override fun get(index: Int): Char =
string.getOrElse(index) { throw IndexOutOfBoundsException("index: $index, length: $length}") }
actual override fun subSequence(startIndex: Int, endIndex: Int): CharSequence = string.substring(startIndex, endIndex)