!! 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
|
* @author Pavel Talanov
|
||||||
* <p/>
|
* <p/>
|
||||||
* This class contains tests that do not fall in any particular category
|
* A messy class where all new tests go before they are sorted which never happens.
|
||||||
* most probably because that functionality has very little support
|
|
||||||
*/
|
*/
|
||||||
public final class MiscTest extends AbstractExpressionTest {
|
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;
|
package org.jetbrains.k2js.translate.context;
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
import com.google.dart.compiler.backend.js.ast.*;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
|
||||||
import com.google.dart.compiler.backend.js.ast.JsScope;
|
|
||||||
import com.google.dart.compiler.util.AstUtil;
|
import com.google.dart.compiler.util.AstUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -44,6 +42,7 @@ public final class Namer {
|
|||||||
private static final String ROOT_NAMESPACE = "Root";
|
private static final String ROOT_NAMESPACE = "Root";
|
||||||
private static final String RECEIVER_PARAMETER_NAME = "receiver";
|
private static final String RECEIVER_PARAMETER_NAME = "receiver";
|
||||||
private static final String CLASSES_OBJECT_NAME = "classes";
|
private static final String CLASSES_OBJECT_NAME = "classes";
|
||||||
|
private static final String THROW_NPE_FUN_NAME = "throwNPE";
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String getReceiverParameterName() {
|
public static String getReceiverParameterName() {
|
||||||
@@ -123,25 +122,32 @@ public final class Namer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsNameRef classCreationMethodReference() {
|
public JsExpression classCreationMethodReference() {
|
||||||
return kotlin(createMethodReference(className));
|
return kotlin(createMethodReference(className));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsNameRef traitCreationMethodReference() {
|
public JsExpression traitCreationMethodReference() {
|
||||||
return kotlin(createMethodReference(traitName));
|
return kotlin(createMethodReference(traitName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsNameRef namespaceCreationMethodReference() {
|
public JsExpression namespaceCreationMethodReference() {
|
||||||
return kotlin(createMethodReference(namespaceName));
|
return kotlin(createMethodReference(namespaceName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsNameRef objectCreationMethodReference() {
|
public JsExpression objectCreationMethodReference() {
|
||||||
return kotlin(createMethodReference(objectName));
|
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
|
@NotNull
|
||||||
private static JsNameRef createMethodReference(@NotNull JsName name) {
|
private static JsNameRef createMethodReference(@NotNull JsName name) {
|
||||||
JsNameRef qualifier = name.makeRef();
|
JsNameRef qualifier = name.makeRef();
|
||||||
@@ -151,7 +157,7 @@ public final class Namer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsNameRef kotlin(@NotNull JsNameRef reference) {
|
private JsExpression kotlin(@NotNull JsExpression reference) {
|
||||||
JsNameRef kotlinReference = kotlinName.makeRef();
|
JsNameRef kotlinReference = kotlinName.makeRef();
|
||||||
setQualifier(reference, kotlinReference);
|
setQualifier(reference, kotlinReference);
|
||||||
return reference;
|
return reference;
|
||||||
@@ -163,7 +169,7 @@ public final class Namer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsNameRef isOperationReference() {
|
public JsExpression isOperationReference() {
|
||||||
return kotlin(AstUtil.newQualifiedNameRef("isType"));
|
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) {
|
private static JsExpression translateExclExclOperator(@NotNull JetUnaryExpression expression, @NotNull TranslationContext context) {
|
||||||
JsExpression translatedExpression = translateAsExpression(getBaseExpression(expression), context);
|
JsExpression translatedExpression = translateAsExpression(getBaseExpression(expression), context);
|
||||||
JsBinaryOperation notNullCheck = notNullCheck(context, translatedExpression);
|
JsBinaryOperation notNullCheck = notNullCheck(context, translatedExpression);
|
||||||
return new JsConditional(notNullCheck, translatedExpression, translatedExpression);
|
return new JsConditional(notNullCheck, translatedExpression, context.namer().throwNPEFunctionCall());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -286,7 +286,12 @@ var Kotlin;
|
|||||||
|
|
||||||
Kotlin.Exceptions = {};
|
Kotlin.Exceptions = {};
|
||||||
Kotlin.Exception = Kotlin.Class.create();
|
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({
|
Kotlin.ArrayList = Class.create({
|
||||||
|
|||||||
Reference in New Issue
Block a user