diff --git a/translator/test/org/jetbrains/k2js/test/ArrayListTest.java b/translator/test/org/jetbrains/k2js/test/ArrayListTest.java index 0af3d08c21a..6dd62470913 100644 --- a/translator/test/org/jetbrains/k2js/test/ArrayListTest.java +++ b/translator/test/org/jetbrains/k2js/test/ArrayListTest.java @@ -1,6 +1,7 @@ package org.jetbrains.k2js.test; import org.junit.Test; +import org.mozilla.javascript.JavaScriptException; /** * @author Talanov Pavel @@ -43,4 +44,9 @@ public final class ArrayListTest extends JavaClassesTest { public void remove() throws Exception { testFooBoxIsTrue("remove.kt"); } + + @Test(expected = JavaScriptException.class) + public void indexOOB() throws Exception { + testFooBoxIsTrue("indexOOB.kt"); + } } diff --git a/translator/testFiles/java/arrayList/cases/indexOOB.kt b/translator/testFiles/java/arrayList/cases/indexOOB.kt new file mode 100644 index 00000000000..212642fa3e9 --- /dev/null +++ b/translator/testFiles/java/arrayList/cases/indexOOB.kt @@ -0,0 +1,12 @@ +namespace foo + +import java.util.ArrayList; + +fun box() : Boolean { + val arr = ArrayList(); + var i = 0; + while (i++ < 10) { + arr.add(i); + } + return (arr[10] == 11) +} \ No newline at end of file diff --git a/translator/testFiles/java/arrayList/cases/iterate.kt b/translator/testFiles/java/arrayList/cases/iterate.kt index 3bb40c235d0..61ffc196f44 100644 --- a/translator/testFiles/java/arrayList/cases/iterate.kt +++ b/translator/testFiles/java/arrayList/cases/iterate.kt @@ -12,5 +12,5 @@ fun box() : Boolean { for (a in arr) { sum += a; } - return (sum == 55) + return (sum == 55) && (arr.size() == 10) } \ No newline at end of file diff --git a/translator/testFiles/kotlin_lib.js b/translator/testFiles/kotlin_lib.js index 2504235b1d5..53a3e00535d 100644 --- a/translator/testFiles/kotlin_lib.js +++ b/translator/testFiles/kotlin_lib.js @@ -463,13 +463,13 @@ Kotlin.Array = Class.create({ } }, get:function (index) { - if ((index < 0) || (index > this.array.length)) { + if ((index < 0) || (index >= this.array.length)) { throw Kotlin.Exceptions.IndexOutOfBounds; } return (this.array)[index]; }, set:function (index, value) { - if ((index < 0) || (index > this.array.length)) { + if ((index < 0) || (index >= this.array.length)) { throw Kotlin.Exceptions.IndexOutOfBounds; } (this.array)[index] = value; @@ -489,13 +489,13 @@ Kotlin.ArrayList = Class.create({ this.$size = 0; }, get:function (index) { - if ((index < 0) || (index > this.$size)) { + if ((index < 0) || (index >= this.$size)) { throw Kotlin.Exceptions.IndexOutOfBounds; } return (this.array)[index]; }, set:function (index, value) { - if ((index < 0) || (index > this.$size)) { + if ((index < 0) || (index >= this.$size)) { throw Kotlin.Exceptions.IndexOutOfBounds; } (this.array)[index] = value;