!! operator
kotlin_lib.js modified, truthful description of MiscTest class added. #KT-1960 fixed
This commit is contained in:
@@ -25,8 +25,7 @@ import static org.jetbrains.k2js.test.utils.JsTestUtils.failsOnEcmaV5;
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
* <p/>
|
||||
* 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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user