Minor: reformat code in JS stdlib
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package kotlin.js
|
package kotlin.js
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*
|
||||||
|
|
||||||
@native
|
@native
|
||||||
public val noImpl: Nothing
|
public val noImpl: Nothing
|
||||||
@@ -16,18 +16,22 @@ public val undefined: Nothing? = noImpl
|
|||||||
|
|
||||||
@library
|
@library
|
||||||
public fun println() {}
|
public fun println() {}
|
||||||
|
|
||||||
@library
|
@library
|
||||||
public fun println(s : Any?) {}
|
public fun println(s: Any?) {}
|
||||||
|
|
||||||
@library
|
@library
|
||||||
public fun print(s : Any?) {}
|
public fun print(s: Any?) {}
|
||||||
|
|
||||||
//TODO: consistent parseInt
|
//TODO: consistent parseInt
|
||||||
@native
|
@native
|
||||||
public fun parseInt(s: String, radix: Int = 10): Int = noImpl
|
public fun parseInt(s: String, radix: Int = 10): Int = noImpl
|
||||||
|
|
||||||
@library
|
@library
|
||||||
public fun safeParseInt(s : String) : Int? = noImpl
|
public fun safeParseInt(s: String): Int? = noImpl
|
||||||
|
|
||||||
@library
|
@library
|
||||||
public fun safeParseDouble(s : String) : Double? = noImpl
|
public fun safeParseDouble(s: String): Double? = noImpl
|
||||||
|
|
||||||
@native
|
@native
|
||||||
public fun js(code: String): dynamic = noImpl
|
public fun js(code: String): dynamic = noImpl
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ package kotlin.js
|
|||||||
|
|
||||||
@native
|
@native
|
||||||
public class Date() {
|
public class Date() {
|
||||||
public fun getTime() : Int = noImpl
|
public fun getTime(): Int = noImpl
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ public class IOException(message: String = "") : Exception() {}
|
|||||||
|
|
||||||
@library
|
@library
|
||||||
public interface Closeable {
|
public interface Closeable {
|
||||||
public open fun close() : Unit;
|
public open fun close(): Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Serializable
|
interface Serializable
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package java.lang
|
package java.lang
|
||||||
|
|
||||||
@library
|
@library
|
||||||
open public class Error(message: String? = null): Throwable(message) {}
|
open public class Error(message: String? = null) : Throwable(message) {}
|
||||||
|
|
||||||
@library
|
@library
|
||||||
open public class Exception(message: String? = null): Throwable(message) {}
|
open public class Exception(message: String? = null) : Throwable(message) {}
|
||||||
|
|
||||||
@library
|
@library
|
||||||
open public class RuntimeException(message: String? = null) : Exception(message) {}
|
open public class RuntimeException(message: String? = null) : Exception(message) {}
|
||||||
@@ -32,7 +32,7 @@ public class AssertionError(message: String? = null) : Error(message) {}
|
|||||||
|
|
||||||
@library
|
@library
|
||||||
public interface Runnable {
|
public interface Runnable {
|
||||||
public open fun run() : Unit;
|
public open fun run(): Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun Runnable(action: () -> Unit): Runnable = object : Runnable {
|
public fun Runnable(action: () -> Unit): Runnable = object : Runnable {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ private val DEFAULT_LOAD_FACTOR = 0.75f
|
|||||||
|
|
||||||
@library
|
@library
|
||||||
public interface Comparator<T> {
|
public interface Comparator<T> {
|
||||||
public fun compare(obj1: T, obj2: T): Int;
|
public fun compare(obj1: T, obj2: T): Int
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline fun <T> Comparator(crossinline comparison: (T, T) -> Int): Comparator<T> = object : Comparator<T> {
|
public inline fun <T> Comparator(crossinline comparison: (T, T) -> Int): Comparator<T> = object : Comparator<T> {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package kotlin.js
|
|||||||
|
|
||||||
public fun json(vararg pairs: Pair<String, Any?>): Json {
|
public fun json(vararg pairs: Pair<String, Any?>): Json {
|
||||||
val res: dynamic = js("({})")
|
val res: dynamic = js("({})")
|
||||||
for((name, value) in pairs) {
|
for ((name, value) in pairs) {
|
||||||
res[name] = value
|
res[name] = value
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
@@ -19,15 +19,15 @@ public fun Json.add(other: Json): Json = noImpl
|
|||||||
@native
|
@native
|
||||||
public interface JsonClass {
|
public interface JsonClass {
|
||||||
public fun stringify(o: Any): String
|
public fun stringify(o: Any): String
|
||||||
public fun stringify(o: Any, replacer: (key: String, value: Any?)->Any?): String
|
public fun stringify(o: Any, replacer: (key: String, value: Any?) -> Any?): String
|
||||||
public fun stringify(o: Any, replacer: (key: String, value: Any?)->Any?, space: Int): String
|
public fun stringify(o: Any, replacer: (key: String, value: Any?) -> Any?, space: Int): String
|
||||||
public fun stringify(o: Any, replacer: (key: String, value: Any?)->Any?, space: String): String
|
public fun stringify(o: Any, replacer: (key: String, value: Any?) -> Any?, space: String): String
|
||||||
public fun stringify(o: Any, replacer: Array<String>): String
|
public fun stringify(o: Any, replacer: Array<String>): String
|
||||||
public fun stringify(o: Any, replacer: Array<String>, space: Int): String
|
public fun stringify(o: Any, replacer: Array<String>, space: Int): String
|
||||||
public fun stringify(o: Any, replacer: Array<String>, space: String): String
|
public fun stringify(o: Any, replacer: Array<String>, space: String): String
|
||||||
|
|
||||||
public fun <T> parse(text: String): T
|
public fun <T> parse(text: String): T
|
||||||
public fun <T> parse(text: String, reviver: ((key: String, value: Any?)->Any?)): T
|
public fun <T> parse(text: String, reviver: ((key: String, value: Any?) -> Any?)): T
|
||||||
}
|
}
|
||||||
|
|
||||||
@native
|
@native
|
||||||
|
|||||||
@@ -3,28 +3,28 @@ package kotlin.js
|
|||||||
//TODO: declare using number
|
//TODO: declare using number
|
||||||
@native
|
@native
|
||||||
public class MathClass() {
|
public class MathClass() {
|
||||||
public val PI : Double = noImpl;
|
public val PI: Double = noImpl
|
||||||
public fun random() : Double = noImpl;
|
public fun random(): Double = noImpl
|
||||||
public fun abs(value : Double) : Double = noImpl
|
public fun abs(value: Double): Double = noImpl
|
||||||
public fun acos(value : Double) : Double = noImpl
|
public fun acos(value: Double): Double = noImpl
|
||||||
public fun asin(value : Double) : Double = noImpl
|
public fun asin(value: Double): Double = noImpl
|
||||||
public fun atan(value : Double) : Double = noImpl
|
public fun atan(value: Double): Double = noImpl
|
||||||
public fun atan2(x : Double, y : Double) : Double = noImpl
|
public fun atan2(x: Double, y: Double): Double = noImpl
|
||||||
public fun cos(value : Double) : Double = noImpl
|
public fun cos(value: Double): Double = noImpl
|
||||||
public fun sin(value : Double) : Double = noImpl
|
public fun sin(value: Double): Double = noImpl
|
||||||
public fun exp(value : Double) : Double = noImpl
|
public fun exp(value: Double): Double = noImpl
|
||||||
public fun max(vararg values : Double) : Double = noImpl
|
public fun max(vararg values: Double): Double = noImpl
|
||||||
public fun max(vararg values : Int) : Int = noImpl
|
public fun max(vararg values: Int): Int = noImpl
|
||||||
public fun min(vararg values : Int) : Int = noImpl
|
public fun min(vararg values: Int): Int = noImpl
|
||||||
public fun min(vararg values : Double) : Double = noImpl
|
public fun min(vararg values: Double): Double = noImpl
|
||||||
public fun sqrt(value : Double) : Double = noImpl
|
public fun sqrt(value: Double): Double = noImpl
|
||||||
public fun tan(value : Double) : Double = noImpl
|
public fun tan(value: Double): Double = noImpl
|
||||||
public fun log(value : Double) : Double = noImpl
|
public fun log(value: Double): Double = noImpl
|
||||||
public fun pow(base : Double, exp : Double) : Double = noImpl
|
public fun pow(base: Double, exp: Double): Double = noImpl
|
||||||
public fun round(value : Number) : Int = noImpl
|
public fun round(value: Number): Int = noImpl
|
||||||
public fun floor(value : Number) : Int = noImpl
|
public fun floor(value: Number): Int = noImpl
|
||||||
public fun ceil(value : Number) : Int = noImpl
|
public fun ceil(value: Number): Int = noImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@native
|
@native
|
||||||
public val Math: MathClass = MathClass();
|
public val Math: MathClass = MathClass()
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
|
|||||||
* @param limit The maximum number of times the split can occur.
|
* @param limit The maximum number of times the split can occur.
|
||||||
*/
|
*/
|
||||||
public fun split(input: CharSequence, limit: Int = 0): List<String> {
|
public fun split(input: CharSequence, limit: Int = 0): List<String> {
|
||||||
require(limit >= 0, { "Limit must be non-negative, but was $limit" } )
|
require(limit >= 0) { "Limit must be non-negative, but was $limit" }
|
||||||
val matches = findAll(input).let { if (limit == 0) it else it.take(limit - 1) }
|
val matches = findAll(input).let { if (limit == 0) it else it.take(limit - 1) }
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
var lastStart = 0
|
var lastStart = 0
|
||||||
@@ -166,8 +166,10 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
|
|||||||
companion object {
|
companion object {
|
||||||
/** Returns a literal regex for the specified [literal] string. */
|
/** Returns a literal regex for the specified [literal] string. */
|
||||||
public fun fromLiteral(literal: String): Regex = Regex(escape(literal))
|
public fun fromLiteral(literal: String): Regex = Regex(escape(literal))
|
||||||
|
|
||||||
/** Returns a literal pattern for the specified [literal] string. */
|
/** Returns a literal pattern for the specified [literal] string. */
|
||||||
public fun escape(literal: String): String = literal.nativeReplace(patternEscape, "\\$&")
|
public fun escape(literal: String): String = literal.nativeReplace(patternEscape, "\\$&")
|
||||||
|
|
||||||
/** Returns a literal replacement exression for the specified [literal] string. */
|
/** Returns a literal replacement exression for the specified [literal] string. */
|
||||||
public fun escapeReplacement(literal: String): String = literal.nativeReplace(replacementEscape, "$$$$")
|
public fun escapeReplacement(literal: String): String = literal.nativeReplace(replacementEscape, "$$$$")
|
||||||
|
|
||||||
@@ -190,7 +192,7 @@ private fun RegExp.findNext(input: String, from: Int): MatchResult? {
|
|||||||
val match = exec(input)
|
val match = exec(input)
|
||||||
if (match == null) return null
|
if (match == null) return null
|
||||||
val reMatch = match as RegExpMatch
|
val reMatch = match as RegExpMatch
|
||||||
val range = reMatch.index..lastIndex-1
|
val range = reMatch.index..lastIndex - 1
|
||||||
|
|
||||||
return object : MatchResult {
|
return object : MatchResult {
|
||||||
override val range: IntRange = range
|
override val range: IntRange = range
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ internal class ConstrainedOnceSequence<T>(sequence: Sequence<T>) : Sequence<T> {
|
|||||||
//private val lock = Any()
|
//private val lock = Any()
|
||||||
|
|
||||||
//TODO: Synchronize with the synchonized() method
|
//TODO: Synchronize with the synchonized() method
|
||||||
override fun iterator(): Iterator<T> {
|
override fun iterator(): Iterator<T> {
|
||||||
val sequence = sequenceRef ?: throw IllegalStateException("This sequence can be consumed only once.")
|
val sequence = sequenceRef ?: throw IllegalStateException("This sequence can be consumed only once.")
|
||||||
sequenceRef = null
|
sequenceRef = null
|
||||||
return sequence.iterator()
|
return sequence.iterator()
|
||||||
|
|||||||
@@ -3,18 +3,19 @@ package kotlin.text
|
|||||||
import kotlin.text.js.RegExp
|
import kotlin.text.js.RegExp
|
||||||
|
|
||||||
|
|
||||||
@native public fun String.toUpperCase() : String = noImpl
|
@native public fun String.toUpperCase(): String = noImpl
|
||||||
|
|
||||||
@native public fun String.toLowerCase() : String = noImpl
|
@native public fun String.toLowerCase(): String = noImpl
|
||||||
|
|
||||||
@native("indexOf")
|
@native("indexOf")
|
||||||
internal fun String.nativeIndexOf(str : String, fromIndex : Int) : Int = noImpl
|
internal fun String.nativeIndexOf(str: String, fromIndex: Int): Int = noImpl
|
||||||
|
|
||||||
@native("lastIndexOf")
|
@native("lastIndexOf")
|
||||||
internal fun String.nativeLastIndexOf(str : String, fromIndex : Int) : Int = noImpl
|
internal fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int = noImpl
|
||||||
|
|
||||||
@native("startsWith")
|
@native("startsWith")
|
||||||
internal fun String.nativeStartsWith(s: String, position: Int): Boolean = noImpl
|
internal fun String.nativeStartsWith(s: String, position: Int): Boolean = noImpl
|
||||||
|
|
||||||
@native("endsWith")
|
@native("endsWith")
|
||||||
internal fun String.nativeEndsWith(s: String): Boolean = noImpl
|
internal fun String.nativeEndsWith(s: String): Boolean = noImpl
|
||||||
|
|
||||||
@@ -26,12 +27,12 @@ public fun String.splitWithRegex(regex: String): Array<String> = noImpl
|
|||||||
@library("splitString")
|
@library("splitString")
|
||||||
public fun String.splitWithRegex(regex: String, limit: Int): Array<String> = noImpl
|
public fun String.splitWithRegex(regex: String, limit: Int): Array<String> = noImpl
|
||||||
|
|
||||||
@native public fun String.substring(startIndex : Int) : String = noImpl
|
@native public fun String.substring(startIndex: Int): String = noImpl
|
||||||
@native public fun String.substring(startIndex : Int, endIndex : Int) : String = noImpl
|
@native public fun String.substring(startIndex: Int, endIndex: Int): String = noImpl
|
||||||
|
|
||||||
@native public fun String.concat(str : String) : String = noImpl
|
@native public fun String.concat(str: String): String = noImpl
|
||||||
|
|
||||||
@native public fun String.match(regex : String) : Array<String> = noImpl
|
@native public fun String.match(regex: String): Array<String> = noImpl
|
||||||
|
|
||||||
//native public fun String.trim() : String = noImpl
|
//native public fun String.trim() : String = noImpl
|
||||||
//TODO: String.replace to implement effective trimLeading and trimTrailing
|
//TODO: String.replace to implement effective trimLeading and trimTrailing
|
||||||
@@ -40,8 +41,6 @@ public fun String.splitWithRegex(regex: String, limit: Int): Array<String> = noI
|
|||||||
public val CharSequence.size: Int get() = noImpl
|
public val CharSequence.size: Int get() = noImpl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@native("replace")
|
@native("replace")
|
||||||
internal fun String.nativeReplace(pattern: RegExp, replacement: String): String = noImpl
|
internal fun String.nativeReplace(pattern: RegExp, replacement: String): String = noImpl
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ fun Document?.elements(namespaceUri: String, localName: String): List<Element> {
|
|||||||
@Deprecated("Use non-null function instead with elvis", ReplaceWith("this?.asList() ?: emptyList()"))
|
@Deprecated("Use non-null function instead with elvis", ReplaceWith("this?.asList() ?: emptyList()"))
|
||||||
fun NodeList?.asList(): List<Node> = this?.asList() ?: emptyList()
|
fun NodeList?.asList(): List<Node> = this?.asList() ?: emptyList()
|
||||||
|
|
||||||
fun NodeList.asList() : List<Node> = NodeListAsList(this)
|
fun NodeList.asList(): List<Node> = NodeListAsList(this)
|
||||||
|
|
||||||
@Deprecated("Use asElementList() instead", ReplaceWith("this?.asElementList() ?: emptyList()"))
|
@Deprecated("Use asElementList() instead", ReplaceWith("this?.asElementList() ?: emptyList()"))
|
||||||
fun NodeList?.toElementList(): List<Element> = this?.asElementList() ?: emptyList()
|
fun NodeList?.toElementList(): List<Element> = this?.asElementList() ?: emptyList()
|
||||||
@@ -86,6 +86,7 @@ fun NodeList.asElementList(): List<Element> = if (length == 0) emptyList() else
|
|||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun List<Node>.filterElements(): List<Element> = filter { it.isElement } as List<Element>
|
fun List<Node>.filterElements(): List<Element> = filter { it.isElement } as List<Element>
|
||||||
|
|
||||||
fun NodeList.filterElements(): List<Element> = asList().filterElements()
|
fun NodeList.filterElements(): List<Element> = asList().filterElements()
|
||||||
|
|
||||||
private class NodeListAsList(private val delegate: NodeList) : AbstractList<Node>() {
|
private class NodeListAsList(private val delegate: NodeList) : AbstractList<Node>() {
|
||||||
@@ -149,7 +150,7 @@ private class PreviousSiblings(private var node: Node) : Iterable<Node> {
|
|||||||
/**
|
/**
|
||||||
* it is *true* when [Node.nodeType] is TEXT_NODE or CDATA_SECTION_NODE
|
* it is *true* when [Node.nodeType] is TEXT_NODE or CDATA_SECTION_NODE
|
||||||
*/
|
*/
|
||||||
val Node.isText : Boolean
|
val Node.isText: Boolean
|
||||||
get() = nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE
|
get() = nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ private class CloseableEventListener(
|
|||||||
private val listener: EventListener,
|
private val listener: EventListener,
|
||||||
private val name: String,
|
private val name: String,
|
||||||
private val capture: Boolean
|
private val capture: Boolean
|
||||||
) : Closeable {
|
) : Closeable {
|
||||||
public override fun close() {
|
public override fun close() {
|
||||||
target.removeEventListener(name, listener, capture)
|
target.removeEventListener(name, listener, capture)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ fun Element.addText(text: String): Element = appendText(text)
|
|||||||
/**
|
/**
|
||||||
* Creates text node and append it to the element
|
* Creates text node and append it to the element
|
||||||
*/
|
*/
|
||||||
fun Element.appendText(text: String, doc : Document? = null): Element {
|
fun Element.appendText(text: String, doc: Document? = null): Element {
|
||||||
appendChild(ownerDocument(doc).createTextNode(text))
|
appendChild(ownerDocument(doc).createTextNode(text))
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ private object DoubleCompanionObject {
|
|||||||
private object FloatCompanionObject {
|
private object FloatCompanionObject {
|
||||||
val MIN_VALUE: Float = js("Number.MIN_VALUE")
|
val MIN_VALUE: Float = js("Number.MIN_VALUE")
|
||||||
val MAX_VALUE: Float = js("Number.MAX_VALUE")
|
val MAX_VALUE: Float = js("Number.MAX_VALUE")
|
||||||
val POSITIVE_INFINITY : Float = js("Number.POSITIVE_INFINITY")
|
val POSITIVE_INFINITY: Float = js("Number.POSITIVE_INFINITY")
|
||||||
val NEGATIVE_INFINITY : Float = js("Number.NEGATIVE_INFINITY")
|
val NEGATIVE_INFINITY: Float = js("Number.NEGATIVE_INFINITY")
|
||||||
val NaN : Float = js("Number.NaN")
|
val NaN: Float = js("Number.NaN")
|
||||||
}
|
}
|
||||||
|
|
||||||
private object IntCompanionObject {
|
private object IntCompanionObject {
|
||||||
@@ -62,4 +62,5 @@ private object CharCompanionObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private object StringCompanionObject {}
|
private object StringCompanionObject {}
|
||||||
|
|
||||||
private object EnumCompanionObject {}
|
private object EnumCompanionObject {}
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ package QUnit
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@native
|
@native
|
||||||
public fun ok(actual: Boolean, message: String?): Unit = noImpl;
|
public fun ok(actual: Boolean, message: String?): Unit = noImpl
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package kotlin.test
|
|||||||
* Comments out a block of test code until it is implemented while keeping a link to the code
|
* Comments out a block of test code until it is implemented while keeping a link to the code
|
||||||
* to implement in your unit test output
|
* to implement in your unit test output
|
||||||
*/
|
*/
|
||||||
public fun todo(block: ()-> Any) {
|
public fun todo(block: () -> Any) {
|
||||||
// println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block)
|
// println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block)
|
||||||
println("TODO at " + block)
|
println("TODO at " + block)
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ public fun todo(block: ()-> Any) {
|
|||||||
*/
|
*/
|
||||||
public var asserter: Asserter = QUnitAsserter()
|
public var asserter: Asserter = QUnitAsserter()
|
||||||
|
|
||||||
public class QUnitAsserter(): Asserter {
|
public class QUnitAsserter() : Asserter {
|
||||||
|
|
||||||
public override fun assertTrue(lazyMessage: () -> String?, actual: Boolean) {
|
public override fun assertTrue(lazyMessage: () -> String?, actual: Boolean) {
|
||||||
assertTrue(actual, lazyMessage())
|
assertTrue(actual, lazyMessage())
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class RegExpTest {
|
|||||||
assertFalse(re2.global)
|
assertFalse(re2.global)
|
||||||
assertFalse(re2.ignoreCase)
|
assertFalse(re2.ignoreCase)
|
||||||
assertFalse(re2.multiline)
|
assertFalse(re2.multiline)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test fun regExpTest() {
|
@test fun regExpTest() {
|
||||||
@@ -69,6 +68,4 @@ class RegExpTest {
|
|||||||
assertEquals(0, re.lastIndex)
|
assertEquals(0, re.lastIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user