JS/RTTI. Fix runtime checking against kotlin.CharSequence
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ import com.google.common.base.Predicate
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
interface TypePredicate : Predicate<KotlinType> {
|
||||
public interface TypePredicate : Predicate<KotlinType> {
|
||||
override fun apply(type: KotlinType?): Boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ public final class Namer {
|
||||
public static final String PRIMITIVE_COMPARE_TO = "primitiveCompareTo";
|
||||
public static final String IS_CHAR = "isChar";
|
||||
public static final String IS_NUMBER = "isNumber";
|
||||
public static final String IS_CHAR_SEQUENCE = "isCharSequence";
|
||||
|
||||
public static final String CALLEE_NAME = "$fun";
|
||||
|
||||
@@ -412,6 +413,11 @@ public final class Namer {
|
||||
return kotlin("isComparable");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression isCharSequence() {
|
||||
return kotlin(IS_CHAR_SEQUENCE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsExpression invokeFunctionAndSetTypeCheckMetadata(
|
||||
@NotNull String functionName,
|
||||
|
||||
+2
@@ -163,6 +163,8 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
|
||||
if (isArray(type)) return Namer.IS_ARRAY_FUN_REF;
|
||||
|
||||
if (TypePredicatesKt.getCHAR_SEQUENCE().apply(type)) return namer().isCharSequence();
|
||||
|
||||
if (TypePredicatesKt.getCOMPARABLE().apply(type)) return namer().isComparable();
|
||||
|
||||
return null;
|
||||
|
||||
+7
-1
@@ -17,6 +17,8 @@
|
||||
(function (Kotlin) {
|
||||
"use strict";
|
||||
|
||||
Kotlin.CharSequence = Kotlin.createTraitNow(null);
|
||||
|
||||
// Shims for String
|
||||
if (typeof String.prototype.startsWith === "undefined") {
|
||||
String.prototype.startsWith = function(searchString, position) {
|
||||
@@ -134,6 +136,10 @@
|
||||
Kotlin.isNumber(value) ||
|
||||
Kotlin.isType(value, Kotlin.Comparable);
|
||||
};
|
||||
|
||||
Kotlin.isCharSequence = function (value) {
|
||||
return typeof value === "string" || Kotlin.isType(value, Kotlin.CharSequence);
|
||||
};
|
||||
|
||||
Kotlin.charInc = function (value) {
|
||||
return String.fromCharCode(value.charCodeAt(0)+1);
|
||||
@@ -1140,7 +1146,7 @@
|
||||
};
|
||||
|
||||
|
||||
Kotlin.StringBuilder = Kotlin.createClassNow(null,
|
||||
Kotlin.StringBuilder = Kotlin.createClassNow([Kotlin.CharSequence],
|
||||
function (content) {
|
||||
this.string = typeof(content) == "string" ? content : "";
|
||||
}, {
|
||||
|
||||
Reference in New Issue
Block a user