Assorted stdlib KDocs

This commit is contained in:
Dmitry Jemerov
2017-02-27 14:20:38 +01:00
parent 1d86bd5610
commit 322379e6ae
13 changed files with 207 additions and 9 deletions
@@ -20,5 +20,6 @@ import kotlin.reflect.KotlinReflectionInternalError
/**
* Signals that Kotlin reflection had reached an inconsistent state from which it cannot recover.
* @suppress
*/
class KotlinReflectionInternalError(message: String) : KotlinReflectionInternalError(message)
+6
View File
@@ -5,8 +5,14 @@ public external val noImpl: Nothing
public external val definedExternally: Nothing
/**
* Exposes the JavaScript [eval function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) to Kotlin.
*/
public external fun eval(expr: String): dynamic
/**
* Exposes the JavaScript [undefined property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined) to Kotlin.
*/
public external val undefined: Nothing?
@Deprecated("Use toInt() instead.", ReplaceWith("s.toInt()"), level = DeprecationLevel.ERROR)
+3
View File
@@ -1,5 +1,8 @@
package kotlin.js
/**
* Exposes the [Date API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) to Kotlin.
*/
public external class Date() {
public fun getTime(): Double
}
+6 -1
View File
@@ -1,6 +1,8 @@
package kotlin.js
// https://developer.mozilla.org/en/DOM/console
/**
* Exposes the [console API](https://developer.mozilla.org/en/DOM/console) to Kotlin.
*/
external public interface Console {
public fun dir(o: Any): Unit
public fun error(vararg o: Any?): Unit
@@ -9,4 +11,7 @@ external public interface Console {
public fun warn(vararg o: Any?): Unit
}
/**
* Exposes the [console API](https://developer.mozilla.org/en/DOM/console) to Kotlin.
*/
public external val console: Console
+3
View File
@@ -16,6 +16,9 @@
package kotlin.js
/**
* Reinterprets this value as a value of the [dynamic type](/docs/reference/dynamic-type.html).
*/
@kotlin.internal.InlineOnly
public inline fun Any?.asDynamic(): dynamic = this
+49
View File
@@ -1,10 +1,52 @@
package kotlin.js
/**
* An interface for indexing access to a collection of key-value pairs, where type of key is [String] and type of value is [Any?].
*/
public external interface Json {
/**
* Calls to the function will be translated to indexing operation (square brackets) on the receiver with [propertyName] as the argument.
*
* E.g. for next code:
* ```kotlin
* fun test(j: Json, p: String) = j["prop"] + j.get(p)
* ```
*
* will be generated:
* ```js
* function test(j, p) {
* return j["prop"] + j[p];
* }
* ```
*/
operator fun get(propertyName: String): Any?
/**
* Calls of the function will be translated to an assignment of [value] to the receiver indexed (with square brackets/index operation) with [propertyName].
*
* E.g. for the following code:
* ```kotlin
* fun test(j: Json, p: String, newValue: Any) {
* j["prop"] = 1
* j.set(p, newValue)
* }
* ```
*
* will be generated:
* ```js
* function test(j, p, newValue) {
* j["prop"] = 1;
* j[p] = newValue;
* }
* }
* ```
*/
operator fun set(propertyName: String, value: Any?): Unit
}
/**
* Returns a simple JavaScript object (as [Json]) using provided key-value pairs as names and values of its properties.
*/
public fun json(vararg pairs: Pair<String, Any?>): Json {
val res: dynamic = js("({})")
for ((name, value) in pairs) {
@@ -13,6 +55,10 @@ public fun json(vararg pairs: Pair<String, Any?>): Json {
return res
}
/**
* Adds key-value pairs from [other] to [this].
* Returns the original receiver.
*/
public fun Json.add(other: Json): Json {
val keys: Array<String> = js("Object").keys(other)
for (key in keys) {
@@ -23,6 +69,9 @@ public fun Json.add(other: Json): Json {
return this
}
/**
* Exposes the JavaScript [JSON object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON) to Kotlin.
*/
public external object JSON {
public fun stringify(o: Any?): String
public fun stringify(o: Any?, replacer: (key: String, value: Any?) -> Any?): String
+11 -1
View File
@@ -1,6 +1,9 @@
package kotlin.js
//TODO: declare using number
/**
* Exposes the JavaScript [Math object](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math) to Kotlin.
*/
public external object Math {
public val PI: Double
public fun random(): Double
@@ -27,5 +30,12 @@ public external object Math {
public fun ceil(value: Number): Int
}
/**
* Returns the smaller of two values.
*/
public fun Math.min(a: Long, b: Long): Long = if (a <= b) a else b
public fun Math.max(a: Long, b: Long): Long = if (a >= b) a else b
/**
* Returns the greater of two values.
*/
public fun Math.max(a: Long, b: Long): Long = if (a >= b) a else b
+3
View File
@@ -16,6 +16,9 @@
package kotlin.js
/**
* Exposes the JavaScript [Promise object](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) to Kotlin.
*/
public open external class Promise<out T>(executor: (resolve: (T) -> Unit, reject: (Throwable) -> Unit) -> Unit) {
companion object {
public fun <S> all(promise: Array<out Promise<S>>): Promise<Array<in S>>
+18 -2
View File
@@ -16,7 +16,9 @@
package kotlin.js
/**
* Exposes the JavaScript [RegExp object](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp) to Kotlin.
*/
public external class RegExp(pattern: String, flags: String? = definedExternally) {
public fun test(str: String): Boolean
@@ -35,17 +37,31 @@ public external class RegExp(pattern: String, flags: String? = definedExternally
public val multiline: Boolean
}
/**
* Resets the regular expression so that subsequent [RegExp.test] and [RegExp.exec] calls will match starting with the beginning of the input string.
*/
public fun RegExp.reset() {
lastIndex = 0
}
// TODO: Inherit from array or introduce asArray() extension
/**
* Represents the return value of [RegExp.exec].
*/
public external interface RegExpMatch {
public val index: Int
public val input: String
public val length: Int
}
/**
* Returns the entire text matched by [RegExp.exec] if the [index] parameter is 0, or the text matched by the capturing parenthesis
* at the given index.
*/
public inline operator fun RegExpMatch.get(index: Int): String? = asDynamic()[index]
public inline fun RegExpMatch.asArray(): Array<out String?> = unsafeCast<Array<out String?>>()
/**
* Converts the result of [RegExp.exec] to an array where the first element contains the entire matched text and each subsequent
* element is the text matched by each capturing parenthesis.
*/
public inline fun RegExpMatch.asArray(): Array<out String?> = unsafeCast<Array<out String?>>()
+12
View File
@@ -20,7 +20,13 @@ import getKClass
import kotlin.reflect.KClass
import kotlin.reflect.js.internal.KClassImpl
/**
* Represents the constructor of a class. Instances of `JsClass` can be passed to JavaScript APIs that expect a constructor reference.
*/
external interface JsClass<T : Any> {
/**
* Returns the unqualified name of the class represented by this instance.
*/
val name: String
}
@@ -31,8 +37,14 @@ external fun <T : Any> jsClass(): JsClass<T>
val <T : Any> T.jsClass: JsClass<T>
get() = js("Object").getPrototypeOf(this).constructor
/**
* Obtains a constructor reference for the given `KClass`.
*/
val <T : Any> KClass<T>.js: JsClass<T>
get() = (this as KClassImpl<T>).jClass
/**
* Obtains a `KClass` instance for the given constructor reference.
*/
val <T : Any> JsClass<T>.kotlin: KClass<T>
get() = getKClass(this)
+85 -1
View File
@@ -17,6 +17,10 @@ Core functions and types, available on all supported platforms.
Library support for the Kotlin annotation facility.
# Package kotlin.browser
Access to top-level properties (`document`, `window` etc.) in the browser environment.
# Package kotlin.collections
Collection types, such as [Iterable][kotlin.collections.Iterable], [Collection][kotlin.collections.Collection],
@@ -30,10 +34,30 @@ Helper functions for creating [Comparator][java.util.Comparator] instances.
Utility functions for concurrent programming.
# Package kotlin.coroutines.experimental
Library support for coroutines, including support for lazy sequences.
# Package kotlin.coroutines.experimental.intrinsics
Low-level building blocks for libraries that provide coroutine-based APIs.
# Package kotlin.dom
Utility functions for working with the browser DOM.
# Package kotlin.experimental
Experimental APIs, subject to change in future versions of Kotlin.
# Package kotlin.io
IO API for working with files and streams.
# Package kotlin.js
Functions and other APIs specific to the JavaScript platform.
# Package kotlin.jvm
Functions and annotations specific to the Java platform.
@@ -51,16 +75,24 @@ and helper functions for implementing custom delegates.
Runtime API for [Kotlin reflection](/docs/reference/reflection.html)
# Package kotlin.reflect.full
Extensions for [Kotlin reflection](/docs/reference/reflection.html) provided by `kotlin-reflect` library.
# Package kotlin.reflect.jvm
Runtime API for interoperability between [Kotlin reflection](/docs/reference/reflection.html) and
Java reflection.
Java reflection provided by `kotlin-reflect` library.
# Package kotlin.sequences
[Sequence][kotlin.sequences.Sequence] type that represents lazily evaluated collections. Top-level functions for instantiating sequences
and extension functions for sequences.
# Package kotlin.streams
Utility functions for working with Java 8 [streams](https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html).
# Package kotlin.system
System-related utility functions.
@@ -73,3 +105,55 @@ Functions for writing test assertions.
Functions for working with text and regular expressions.
# Package org.khronos.webgl
Kotlin JavaScript wrappers for the WebGL API.
# Package org.w3c.dom
Kotlin JavaScript wrappers for the DOM API.
# Package org.w3c.dom.css
Kotlin JavaScript wrappers for the DOM CSS API.
# Package org.w3c.dom.events
Kotlin JavaScript wrappers for the DOM events API.
# Package org.w3c.dom.parsing
Kotlin JavaScript wrappers for the DOM parsing API.
# Package org.w3c.dom.svg
Kotlin JavaScript wrappers for the DOM SVG API.
# Package org.w3c.dom.url
Kotlin JavaScript wrappers for the DOM URL API.
# Package org.w3c.fetch
Kotlin JavaScript wrappers for the [W3C fetch API](https://fetch.spec.whatwg.org).
# Package org.w3c.files
Kotlin JavaScript wrappers for the [W3C file API](https://www.w3.org/TR/FileAPI/).
# Package org.w3c.notifications
Kotlin JavaScript wrappers for the [Web Notifications API](https://www.w3.org/TR/notifications/).
# Package org.w3c.performance
Kotlin JavaScript wrappers for the [Navigation Timing API](https://www.w3.org/TR/navigation-timing/).
# Package org.w3c.workers
Kotlin JavaScript wrappers for the [Web Workers API](https://www.w3.org/TR/workers/).
# Package org.w3c.xhr
Kotlin JavaScript wrappers for the [XMLHttpRequest API](https://www.w3.org/TR/XMLHttpRequest/).
@@ -18,10 +18,14 @@
package kotlin.coroutines.experimental.jvm.internal
import java.lang.IllegalStateException
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.jvm.internal.interceptContinuationIfNeeded
import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.CoroutineContext
import kotlin.coroutines.experimental.processBareContinuationResume
import kotlin.jvm.internal.Lambda
/**
* @suppress
*/
abstract class CoroutineImpl(
arity: Int,
@JvmField
@@ -19,10 +19,12 @@
package kotlin.coroutines.experimental.jvm.internal
import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.CoroutineContext
import kotlin.coroutines.experimental.ContinuationInterceptor
import kotlin.coroutines.experimental.jvm.internal.CoroutineImpl
import kotlin.coroutines.experimental.CoroutineContext
/**
* @suppress
*/
fun <T> normalizeContinuation(continuation: Continuation<T>): Continuation<T> =
(continuation as? CoroutineImpl)?.facade ?: continuation