diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KotlinReflectionInternalError.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KotlinReflectionInternalError.kt index 7818f77631f..c385ac1eb41 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KotlinReflectionInternalError.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KotlinReflectionInternalError.kt @@ -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) \ No newline at end of file diff --git a/js/js.libraries/src/core/core.kt b/js/js.libraries/src/core/core.kt index f2fdacecef3..88e0474cf24 100644 --- a/js/js.libraries/src/core/core.kt +++ b/js/js.libraries/src/core/core.kt @@ -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) diff --git a/js/js.libraries/src/core/date.kt b/js/js.libraries/src/core/date.kt index ef5ac5ae5cc..449568fffd2 100644 --- a/js/js.libraries/src/core/date.kt +++ b/js/js.libraries/src/core/date.kt @@ -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 } diff --git a/js/js.libraries/src/core/debug.kt b/js/js.libraries/src/core/debug.kt index dc48d442c08..b57ff051fb8 100644 --- a/js/js.libraries/src/core/debug.kt +++ b/js/js.libraries/src/core/debug.kt @@ -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 diff --git a/js/js.libraries/src/core/dynamic.kt b/js/js.libraries/src/core/dynamic.kt index 0a79b90beae..8ea21cea14f 100644 --- a/js/js.libraries/src/core/dynamic.kt +++ b/js/js.libraries/src/core/dynamic.kt @@ -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 diff --git a/js/js.libraries/src/core/json.kt b/js/js.libraries/src/core/json.kt index 8a538995103..355ff921d11 100644 --- a/js/js.libraries/src/core/json.kt +++ b/js/js.libraries/src/core/json.kt @@ -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): Json { val res: dynamic = js("({})") for ((name, value) in pairs) { @@ -13,6 +55,10 @@ public fun json(vararg pairs: Pair): 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 = 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 diff --git a/js/js.libraries/src/core/math.kt b/js/js.libraries/src/core/math.kt index b57ef960c00..eb8355fcc61 100644 --- a/js/js.libraries/src/core/math.kt +++ b/js/js.libraries/src/core/math.kt @@ -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 \ No newline at end of file + +/** + * Returns the greater of two values. + */ +public fun Math.max(a: Long, b: Long): Long = if (a >= b) a else b diff --git a/js/js.libraries/src/core/promise.kt b/js/js.libraries/src/core/promise.kt index 94a668078dc..f411b55d827 100644 --- a/js/js.libraries/src/core/promise.kt +++ b/js/js.libraries/src/core/promise.kt @@ -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(executor: (resolve: (T) -> Unit, reject: (Throwable) -> Unit) -> Unit) { companion object { public fun all(promise: Array>): Promise> diff --git a/js/js.libraries/src/core/regexp.kt b/js/js.libraries/src/core/regexp.kt index d64ffd69967..038ab82f9b0 100644 --- a/js/js.libraries/src/core/regexp.kt +++ b/js/js.libraries/src/core/regexp.kt @@ -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 = unsafeCast>() \ No newline at end of file +/** + * 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 = unsafeCast>() diff --git a/js/js.libraries/src/reflect/JsClass.kt b/js/js.libraries/src/reflect/JsClass.kt index 77e84deeeca..b4fa17d8f63 100644 --- a/js/js.libraries/src/reflect/JsClass.kt +++ b/js/js.libraries/src/reflect/JsClass.kt @@ -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 { + /** + * Returns the unqualified name of the class represented by this instance. + */ val name: String } @@ -31,8 +37,14 @@ external fun jsClass(): JsClass val T.jsClass: JsClass get() = js("Object").getPrototypeOf(this).constructor +/** + * Obtains a constructor reference for the given `KClass`. + */ val KClass.js: JsClass get() = (this as KClassImpl).jClass +/** + * Obtains a `KClass` instance for the given constructor reference. + */ val JsClass.kotlin: KClass get() = getKClass(this) diff --git a/libraries/stdlib/src/Module.md b/libraries/stdlib/src/Module.md index dd19f2342d3..2aa8ea683f6 100644 --- a/libraries/stdlib/src/Module.md +++ b/libraries/stdlib/src/Module.md @@ -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/). + diff --git a/libraries/stdlib/src/kotlin/coroutines/experimental/jvm/internal/CoroutineImpl.kt b/libraries/stdlib/src/kotlin/coroutines/experimental/jvm/internal/CoroutineImpl.kt index 2898b2585da..f8f9964ded3 100644 --- a/libraries/stdlib/src/kotlin/coroutines/experimental/jvm/internal/CoroutineImpl.kt +++ b/libraries/stdlib/src/kotlin/coroutines/experimental/jvm/internal/CoroutineImpl.kt @@ -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 diff --git a/libraries/stdlib/src/kotlin/coroutines/experimental/jvm/internal/CoroutineIntrinsics.kt b/libraries/stdlib/src/kotlin/coroutines/experimental/jvm/internal/CoroutineIntrinsics.kt index 48bff355ef0..d3170fd094a 100644 --- a/libraries/stdlib/src/kotlin/coroutines/experimental/jvm/internal/CoroutineIntrinsics.kt +++ b/libraries/stdlib/src/kotlin/coroutines/experimental/jvm/internal/CoroutineIntrinsics.kt @@ -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 normalizeContinuation(continuation: Continuation): Continuation = (continuation as? CoroutineImpl)?.facade ?: continuation