diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/ForeachTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/ForeachTest.java index 9c59d9c417c..0d8fe7247ff 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/ForeachTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/ForeachTest.java @@ -25,10 +25,6 @@ public final class ForeachTest extends AbstractExpressionTest { super("for/"); } - public void TODO_testForUpTo() throws Exception { - fooBoxIsValue(10); - } - public void testForIteratesOverArray() throws Exception { fooBoxTest(); } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java index 10a497e40a9..618ca4dd5a5 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/RangeTest.java @@ -44,4 +44,8 @@ public final class RangeTest extends SingleFileTranslationTest { public void testIteratingOverRanges() throws Exception { fooBoxTest(); } + + public void testIntUpTo() throws Exception { + fooBoxTest(); + } } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java index afa4de9275f..19cceea3a37 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java @@ -50,6 +50,7 @@ public final class FunctionIntrinsics { register(ArrayFIF.INSTANCE); register(TopLevelFIF.INSTANCE); register(NumberConversionFIF.INSTANCE); + register(RangesFIF.INSTANCE); } private boolean register(@NotNull FunctionIntrinsicFactory instance) { diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/factories/RangesFIF.java b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/factories/RangesFIF.java new file mode 100644 index 00000000000..ef436de6393 --- /dev/null +++ b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/factories/RangesFIF.java @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.k2js.translate.intrinsic.functions.factories; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.k2js.translate.intrinsic.functions.basic.CallStandardMethodIntrinsic; + +import static org.jetbrains.k2js.translate.intrinsic.functions.patterns.PatternBuilder.pattern; + +/** + * @author Pavel Talanov + */ +public final class RangesFIF extends CompositeFIF { + + @NotNull + public static final FunctionIntrinsicFactory INSTANCE = new RangesFIF(); + + private RangesFIF() { + add(pattern("Int.upto"), new CallStandardMethodIntrinsic("Kotlin.intUpto", true, 1)); + } +} diff --git a/js/js.translator/testFiles/expression/for/cases/forUpTo.kt b/js/js.translator/testFiles/expression/for/cases/forUpTo.kt deleted file mode 100644 index ed3692a21a1..00000000000 --- a/js/js.translator/testFiles/expression/for/cases/forUpTo.kt +++ /dev/null @@ -1,9 +0,0 @@ -package foo - -fun box() : Int { - var sum = 0 - for (i in 0.upto(5)) { - sum += i - } - return sum -} \ No newline at end of file diff --git a/js/js.translator/testFiles/kotlin_lib.js b/js/js.translator/testFiles/kotlin_lib.js index 32ef95b8964..06fa523c236 100644 --- a/js/js.translator/testFiles/kotlin_lib.js +++ b/js/js.translator/testFiles/kotlin_lib.js @@ -42,8 +42,8 @@ var kotlin = {set:function (receiver, key, value) { return answer; }; - Kotlin.upto = function (from, limit, reversed) { - return Kotlin.$new(Kotlin.NumberRange)(from, limit - from, reversed).iterator(); + Kotlin.intUpto = function (from, limit) { + return Kotlin.$new(Kotlin.NumberRange)(from, limit - from + 1); }; Kotlin.modules = {}; diff --git a/js/js.translator/testFiles/range/cases/intUpTo.kt b/js/js.translator/testFiles/range/cases/intUpTo.kt new file mode 100644 index 00000000000..ccab799f1f7 --- /dev/null +++ b/js/js.translator/testFiles/range/cases/intUpTo.kt @@ -0,0 +1,11 @@ +package foo + +import java.util.ArrayList + +fun box() : Boolean { + var elems = ArrayList() + for (i in 0 upto 5) { + elems.add(i) + } + return elems[0] == 0 && elems[1] == 1 && elems[2] == 2 && elems[3] == 3 && elems[4] == 4 && elems[5] == 5 +} \ No newline at end of file