diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java index feaffab05bf..04c8335fc9f 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/MiscTest.java @@ -25,8 +25,7 @@ import static org.jetbrains.k2js.test.utils.JsTestUtils.failsOnEcmaV5; /** * @author Pavel Talanov *

- * This class contains tests that do not fall in any particular category - * most probably because that functionality has very little support + * A messy class where all new tests go before they are sorted which never happens. */ public final class MiscTest extends AbstractExpressionTest { @@ -148,4 +147,12 @@ public final class MiscTest extends AbstractExpressionTest { } + public void testExclExclThrows() throws Exception { + try { + fooBoxTest(); + fail(); + } + catch (JavaScriptException e) { + } + } } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/context/Namer.java b/js/js.translator/src/org/jetbrains/k2js/translate/context/Namer.java index dc8c52adffe..3d792f17527 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/context/Namer.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/context/Namer.java @@ -16,9 +16,7 @@ package org.jetbrains.k2js.translate.context; -import com.google.dart.compiler.backend.js.ast.JsName; -import com.google.dart.compiler.backend.js.ast.JsNameRef; -import com.google.dart.compiler.backend.js.ast.JsScope; +import com.google.dart.compiler.backend.js.ast.*; import com.google.dart.compiler.util.AstUtil; import org.jetbrains.annotations.NotNull; @@ -44,6 +42,7 @@ public final class Namer { private static final String ROOT_NAMESPACE = "Root"; private static final String RECEIVER_PARAMETER_NAME = "receiver"; private static final String CLASSES_OBJECT_NAME = "classes"; + private static final String THROW_NPE_FUN_NAME = "throwNPE"; @NotNull public static String getReceiverParameterName() { @@ -123,25 +122,32 @@ public final class Namer { } @NotNull - public JsNameRef classCreationMethodReference() { + public JsExpression classCreationMethodReference() { return kotlin(createMethodReference(className)); } @NotNull - public JsNameRef traitCreationMethodReference() { + public JsExpression traitCreationMethodReference() { return kotlin(createMethodReference(traitName)); } @NotNull - public JsNameRef namespaceCreationMethodReference() { + public JsExpression namespaceCreationMethodReference() { return kotlin(createMethodReference(namespaceName)); } @NotNull - public JsNameRef objectCreationMethodReference() { + public JsExpression objectCreationMethodReference() { return kotlin(createMethodReference(objectName)); } + @NotNull + public JsExpression throwNPEFunctionCall() { + JsNameRef reference = AstUtil.newQualifiedNameRef(THROW_NPE_FUN_NAME); + JsInvocation invocation = AstUtil.newInvocation(reference); + return kotlin(invocation); + } + @NotNull private static JsNameRef createMethodReference(@NotNull JsName name) { JsNameRef qualifier = name.makeRef(); @@ -151,7 +157,7 @@ public final class Namer { } @NotNull - private JsNameRef kotlin(@NotNull JsNameRef reference) { + private JsExpression kotlin(@NotNull JsExpression reference) { JsNameRef kotlinReference = kotlinName.makeRef(); setQualifier(reference, kotlinReference); return reference; @@ -163,7 +169,7 @@ public final class Namer { } @NotNull - public JsNameRef isOperationReference() { + public JsExpression isOperationReference() { return kotlin(AstUtil.newQualifiedNameRef("isType")); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/operation/UnaryOperationTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/operation/UnaryOperationTranslator.java index dee9b1b2b32..8d5bba28ff9 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/operation/UnaryOperationTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/operation/UnaryOperationTranslator.java @@ -64,7 +64,7 @@ public final class UnaryOperationTranslator { private static JsExpression translateExclExclOperator(@NotNull JetUnaryExpression expression, @NotNull TranslationContext context) { JsExpression translatedExpression = translateAsExpression(getBaseExpression(expression), context); JsBinaryOperation notNullCheck = notNullCheck(context, translatedExpression); - return new JsConditional(notNullCheck, translatedExpression, translatedExpression); + return new JsConditional(notNullCheck, translatedExpression, context.namer().throwNPEFunctionCall()); } @NotNull diff --git a/js/js.translator/testFiles/kotlin_lib.js b/js/js.translator/testFiles/kotlin_lib.js index af8de4b708f..8453ae4410c 100644 --- a/js/js.translator/testFiles/kotlin_lib.js +++ b/js/js.translator/testFiles/kotlin_lib.js @@ -286,7 +286,12 @@ var Kotlin; Kotlin.Exceptions = {}; Kotlin.Exception = Kotlin.Class.create(); - Kotlin.Exceptions.IndexOutOfBounds = {}; + Kotlin.Exceptions.IndexOutOfBounds = Kotlin.Class.create(Kotlin.Exception); + Kotlin.Exceptions.NullPointerException = Kotlin.Class.create(Kotlin.Exception); + + Kotlin.throwNPE = function() { + throw new Kotlin.Exceptions.NullPointerException(); + }; Kotlin.ArrayList = Class.create({