From 3019dc502f5e0f4509e9f1fd74aeb2bc83590fd2 Mon Sep 17 00:00:00 2001 From: Pavel Talanov Date: Wed, 7 Dec 2011 17:02:52 +0400 Subject: [PATCH] Array throws indexOutOfBoundsExceptions --- .idea/workspace.xml | 186 +++++++++--------- .../k2js/test/StandardClassesTest.java | 8 + translator/testFiles/kotlin_lib.js | 16 ++ .../cases/arrayThrowsExceptionOnOOBaccess.kt | 8 + 4 files changed, 128 insertions(+), 90 deletions(-) create mode 100644 translator/testFiles/standardClasses/cases/arrayThrowsExceptionOnOOBaccess.kt diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e63a5363cf0..f2237039113 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,10 @@ + - + + @@ -200,13 +202,24 @@ - + - + + + + + + + + + + + + @@ -241,15 +254,6 @@ - - - - - - - - - @@ -299,24 +303,6 @@ - - - - - - - - - - - - - - - - - - @@ -344,10 +330,19 @@ - + - + + + + + + + + + + @@ -384,10 +379,19 @@ - + - + + + + + + + + + + @@ -414,15 +418,12 @@ @@ -1238,7 +1242,7 @@ @@ -1285,41 +1289,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1327,13 +1296,6 @@ - - - - - - - @@ -1384,13 +1346,6 @@ - - - - - - - @@ -1398,10 +1353,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + diff --git a/translator/test/org/jetbrains/k2js/test/StandardClassesTest.java b/translator/test/org/jetbrains/k2js/test/StandardClassesTest.java index 3a6292cdf90..5a5a0522930 100644 --- a/translator/test/org/jetbrains/k2js/test/StandardClassesTest.java +++ b/translator/test/org/jetbrains/k2js/test/StandardClassesTest.java @@ -1,6 +1,7 @@ package org.jetbrains.k2js.test; import org.junit.Test; +import org.mozilla.javascript.JavaScriptException; /** * @author Talanov Pavel @@ -37,4 +38,11 @@ public class StandardClassesTest extends TranslationTest { public void arraySize() throws Exception { testFooBoxIsTrue("arraySize.kt"); } + + @Test(expected = JavaScriptException.class) + public void arrayThrowsExceptionOnOOBaccess() throws Exception { + testFooBoxIsTrue("arrayThrowsExceptionOnOOBaccess.kt"); + } + + } diff --git a/translator/testFiles/kotlin_lib.js b/translator/testFiles/kotlin_lib.js index 189a7a2ad86..155f90662f5 100644 --- a/translator/testFiles/kotlin_lib.js +++ b/translator/testFiles/kotlin_lib.js @@ -477,6 +477,22 @@ Kotlin.Array = Class.create({ }, size:function () { return this.array.length; + }, + iterator:function () { + return new Kotlin.ArrayIterator(this); + } +}); + +Kotlin.ArrayIterator = Class.create({ + initialize:function (array) { + this.array = array; + this.index = 0; + }, + next:function () { + return this.array.get(this.index++); + }, + hasNext:function () { + return (this.array.size() > this.index); } }); diff --git a/translator/testFiles/standardClasses/cases/arrayThrowsExceptionOnOOBaccess.kt b/translator/testFiles/standardClasses/cases/arrayThrowsExceptionOnOOBaccess.kt new file mode 100644 index 00000000000..ff5a3187a56 --- /dev/null +++ b/translator/testFiles/standardClasses/cases/arrayThrowsExceptionOnOOBaccess.kt @@ -0,0 +1,8 @@ +namespace foo + +class A() {} + +val a1 = Array(3) +val a2 = Array(2) + +fun box() = (a1[4] == null) \ No newline at end of file