[stdlib] Explicit visibility and return types: Wasm

This commit is contained in:
Ilya Gorbunov
2023-11-12 02:09:15 +01:00
committed by Space Team
parent 381a8fd55f
commit cfa8a1dc0f
15 changed files with 54 additions and 54 deletions
@@ -35,7 +35,7 @@ public actual inline fun <T : AutoCloseable?, R> T.use(block: (T) -> R): R {
@SinceKotlin("1.8")
@ExperimentalStdlibApi
@PublishedApi
internal fun AutoCloseable?.closeFinally(cause: Throwable?) = when {
internal fun AutoCloseable?.closeFinally(cause: Throwable?): Unit = when {
this == null -> {}
cause == null -> close()
else ->
@@ -33,4 +33,4 @@ package kotlin.native
AnnotationTarget.TYPEALIAS,
)
@Retention(AnnotationRetention.BINARY)
actual annotation class FreezingIsDeprecated
public actual annotation class FreezingIsDeprecated
@@ -14,14 +14,14 @@ public actual interface Appendable {
*
* @param value the character to append.
*/
actual fun append(value: Char): Appendable
public actual fun append(value: Char): Appendable
/**
* Appends the specified character sequence [value] to this Appendable and returns this instance.
*
* @param value the character sequence to append. If [value] is `null`, then the four characters `"null"` are appended to this Appendable.
*/
actual fun append(value: CharSequence?): Appendable
public actual fun append(value: CharSequence?): Appendable
/**
* Appends a subsequence of the specified character sequence [value] to this Appendable and returns this instance.
@@ -33,5 +33,5 @@ public actual interface Appendable {
*
* @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of the [value] character sequence indices or when `startIndex > endIndex`.
*/
actual fun append(value: CharSequence?, startIndex: Int, endIndex: Int): Appendable
public actual fun append(value: CharSequence?, startIndex: Int, endIndex: Int): Appendable
}
@@ -56,7 +56,7 @@ public actual enum class RegexOption(internal val value: Int, internal val mask:
* @param value The value of captured group.
* @param range The range of indices in the input string where group was captured.
*/
public actual data class MatchGroup(actual val value: String, val range: IntRange)
public actual data class MatchGroup(public actual val value: String, val range: IntRange)
/**
@@ -90,42 +90,42 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
}
/** Creates a regular expression from the specified [pattern] string and the default options. */
actual constructor(pattern: String): this(Pattern(pattern))
public actual constructor(pattern: String): this(Pattern(pattern))
/** Creates a regular expression from the specified [pattern] string and the specified single [option]. */
actual constructor(pattern: String, option: RegexOption): this(Pattern(pattern, option.value))
public actual constructor(pattern: String, option: RegexOption): this(Pattern(pattern, option.value))
/** Creates a regular expression from the specified [pattern] string and the specified set of [options]. */
actual constructor(pattern: String, options: Set<RegexOption>): this(Pattern(pattern, options.toInt()))
public actual constructor(pattern: String, options: Set<RegexOption>): this(Pattern(pattern, options.toInt()))
/** The pattern string of this regular expression. */
actual val pattern: String
public actual val pattern: String
get() = nativePattern.pattern
private val startNode = nativePattern.startNode
/** The set of options that were used to create this regular expression. */
actual val options: Set<RegexOption> = fromInt(nativePattern.flags)
public actual val options: Set<RegexOption> = fromInt(nativePattern.flags)
actual companion object {
public actual companion object {
/**
* Returns a regular expression that matches the specified [literal] string literally.
* No characters of that string will have special meaning when searching for an occurrence of the regular expression.
*/
actual fun fromLiteral(literal: String): Regex = Regex(literal, RegexOption.LITERAL)
public actual fun fromLiteral(literal: String): Regex = Regex(literal, RegexOption.LITERAL)
/**
* Returns a regular expression pattern string that matches the specified [literal] string literally.
* No characters of that string will have special meaning when searching for an occurrence of the regular expression.
*/
actual fun escape(literal: String): String = Pattern.quote(literal)
public actual fun escape(literal: String): String = Pattern.quote(literal)
/**
* Returns a literal replacement expression for the specified [literal] string.
* No characters of that string will have special meaning when it is used as a replacement string in [Regex.replace] function.
*/
actual fun escapeReplacement(literal: String): String {
public actual fun escapeReplacement(literal: String): String {
if (!literal.contains('\\') && !literal.contains('$'))
return literal
@@ -155,10 +155,10 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
}
/** Indicates whether the regular expression matches the entire [input]. */
actual infix fun matches(input: CharSequence): Boolean = doMatch(input, Mode.MATCH) != null
public actual infix fun matches(input: CharSequence): Boolean = doMatch(input, Mode.MATCH) != null
/** Indicates whether the regular expression can find at least one match in the specified [input]. */
actual fun containsMatchIn(input: CharSequence): Boolean = find(input) != null
public actual fun containsMatchIn(input: CharSequence): Boolean = find(input) != null
@SinceKotlin("1.7")
@WasExperimental(ExperimentalStdlibApi::class)
@@ -175,7 +175,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
* @sample samples.text.Regexps.find
*/
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult? {
public actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult? {
if (startIndex < 0 || startIndex > input.length) {
throw IndexOutOfBoundsException("Start index is out of bounds: $startIndex, input length: ${input.length}")
}
@@ -199,7 +199,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
* @sample samples.text.Regexps.findAll
*/
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> {
public actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> {
if (startIndex < 0 || startIndex > input.length) {
throw IndexOutOfBoundsException("Start index is out of bounds: $startIndex, input length: ${input.length}")
}
@@ -211,7 +211,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
*
* @return An instance of [MatchResult] if the entire input matches or `null` otherwise.
*/
actual fun matchEntire(input: CharSequence): MatchResult?= doMatch(input, Mode.MATCH)
public actual fun matchEntire(input: CharSequence): MatchResult?= doMatch(input, Mode.MATCH)
@SinceKotlin("1.7")
@WasExperimental(ExperimentalStdlibApi::class)
@@ -249,7 +249,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
* @return the result of replacing each occurrence of this regular expression in [input] with the result of evaluating the [replacement] expression
* @throws RuntimeException if [replacement] expression is malformed, or capturing group with specified `name` or `index` does not exist
*/
actual fun replace(input: CharSequence, replacement: String): String
public actual fun replace(input: CharSequence, replacement: String): String
= replace(input) { match -> substituteGroupRefs(match, replacement) }
/**
@@ -257,7 +257,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
* the given function [transform] that takes [MatchResult] and returns a string to be used as a
* replacement for that match.
*/
actual fun replace(input: CharSequence, transform: (MatchResult) -> CharSequence): String {
public actual fun replace(input: CharSequence, transform: (MatchResult) -> CharSequence): String {
var match: MatchResult? = find(input) ?: return input.toString()
var lastStart = 0
@@ -297,7 +297,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
* @return the result of replacing the first occurrence of this regular expression in [input] with the result of evaluating the [replacement] expression
* @throws RuntimeException if [replacement] expression is malformed, or capturing group with specified `name` or `index` does not exist
*/
actual fun replaceFirst(input: CharSequence, replacement: String): String {
public actual fun replaceFirst(input: CharSequence, replacement: String): String {
val match = find(input) ?: return input.toString()
val length = input.length
val result = StringBuilder(length)
@@ -316,7 +316,7 @@ public actual class Regex internal constructor(internal val nativePattern: Patte
* Zero by default means no limit is set.
*/
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
actual fun split(input: CharSequence, limit: Int = 0): List<String> {
public actual fun split(input: CharSequence, limit: Int = 0): List<String> {
requireNonNegativeLimit(limit)
var match: MatchResult? = find(input)
@@ -23,7 +23,7 @@ internal suspend fun <T> returnIfSuspended(argument: Any?): T =
internal fun <T> interceptContinuationIfNeeded(
context: CoroutineContext,
continuation: Continuation<T>
) = context[ContinuationInterceptor]?.interceptContinuation(continuation) ?: continuation
): Continuation<T> = context[ContinuationInterceptor]?.interceptContinuation(continuation) ?: continuation
@PublishedApi
@@ -68,6 +68,6 @@ internal fun <R, P, T> startCoroutineUninterceptedOrReturnIntrinsic2(
@PublishedApi
@SinceKotlin("1.3")
internal val EmptyContinuation = Continuation<Any?>(EmptyCoroutineContext) { result ->
internal val EmptyContinuation: Continuation<Any?> = Continuation(EmptyCoroutineContext) { result ->
result.getOrThrow()
}
@@ -15,12 +15,12 @@ import kotlin.wasm.internal.jsToKotlinStringAdapter
* @param message the detail message string.
* @param cause the cause of this throwable.
*/
public open class Throwable(open val message: String?, open val cause: kotlin.Throwable?) {
constructor(message: String?) : this(message, null)
public open class Throwable(public open val message: String?, public open val cause: kotlin.Throwable?) {
public constructor(message: String?) : this(message, null)
constructor(cause: Throwable?) : this(cause?.toString(), cause)
public constructor(cause: Throwable?) : this(cause?.toString(), cause)
constructor() : this(null, null)
public constructor() : this(null, null)
internal val jsStack: ExternalInterfaceType = captureStackTrace()
@@ -17,14 +17,14 @@ public external interface Dynamic : JsAny
* Reinterprets this value as a value of the Dynamic type.
*/
@Deprecated("If value is a subtype of JsAny, use JsAny instead. Otherwise, use toJsReference", level = DeprecationLevel.ERROR)
fun Any.asDynamic(): JsAny = this.toJsReference()
public fun Any.asDynamic(): JsAny = this.toJsReference()
/**
* Reinterprets this value as a value of the Dynamic type.
*/
@Deprecated("Use toJsString instead", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("this.toJsString()"))
@kotlin.internal.InlineOnly
fun String.asDynamic(): JsString = this.toJsString()
public fun String.asDynamic(): JsString = this.toJsString()
private fun jsThrow(e: JsAny) {
js("throw e;")
@@ -8,7 +8,7 @@ package kotlin.js
/** JavaScript Array */
@JsName("Array")
public external class JsArray<T : JsAny?> : JsAny {
val length: Int
public val length: Int
}
public operator fun <T : JsAny?> JsArray<T>.get(index: Int): T? =
@@ -20,7 +20,7 @@ public external class Promise<out T : JsAny?>(executor: (resolve: (T) -> Unit, r
public fun <S : JsAny?> catch(onRejected: (JsAny) -> S): Promise<S>
public fun finally(onFinally: () -> Unit): Promise<T>
companion object {
public companion object {
public fun <S : JsAny?> all(promise: JsArray<out Promise<S>>): Promise<JsArray<out S>>
public fun <S : JsAny?> race(promise: JsArray<out Promise<S>>): Promise<S>
public fun reject(e: JsAny): Promise<Nothing>
+6 -6
View File
@@ -140,33 +140,33 @@ public actual inline fun Long.rotateRight(bitCount: Int): Long =
* Returns `true` if the specified number is a
* Not-a-Number (NaN) value, `false` otherwise.
*/
actual fun Double.isNaN(): Boolean = this != this
public actual fun Double.isNaN(): Boolean = this != this
/**
* Returns `true` if the specified number is a
* Not-a-Number (NaN) value, `false` otherwise.
*/
actual fun Float.isNaN(): Boolean = this != this
public actual fun Float.isNaN(): Boolean = this != this
/**
* Returns `true` if this value is infinitely large in magnitude.
*/
actual fun Double.isInfinite(): Boolean = (this == Double.POSITIVE_INFINITY) || (this == Double.NEGATIVE_INFINITY)
public actual fun Double.isInfinite(): Boolean = (this == Double.POSITIVE_INFINITY) || (this == Double.NEGATIVE_INFINITY)
/**
* Returns `true` if this value is infinitely large in magnitude.
*/
actual fun Float.isInfinite(): Boolean = (this == Float.POSITIVE_INFINITY) || (this == Float.NEGATIVE_INFINITY)
public actual fun Float.isInfinite(): Boolean = (this == Float.POSITIVE_INFINITY) || (this == Float.NEGATIVE_INFINITY)
/**
* Returns `true` if the argument is a finite floating-point value; returns `false` otherwise (for `NaN` and infinity arguments).
*/
actual fun Double.isFinite(): Boolean = !isInfinite() && !isNaN()
public actual fun Double.isFinite(): Boolean = !isInfinite() && !isNaN()
/**
* Returns `true` if the argument is a finite floating-point value; returns `false` otherwise (for `NaN` and infinity arguments).
*/
actual fun Float.isFinite(): Boolean = !isInfinite() && !isNaN()
public actual fun Float.isFinite(): Boolean = !isInfinite() && !isNaN()
/**
* Returns a bit representation of the specified floating-point value as [Long]
@@ -7,8 +7,8 @@ package kotlin.coroutines.cancellation
@SinceKotlin("1.4")
public actual open class CancellationException : IllegalStateException {
actual constructor() : super()
actual constructor(message: String?) : super(message)
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
public actual constructor() : super()
public actual constructor(message: String?) : super(message)
public constructor(message: String?, cause: Throwable?) : super(message, cause)
public constructor(cause: Throwable?) : super(cause)
}
@@ -11,5 +11,5 @@ package kotlin.text
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
public actual open class CharacterCodingException(message: String?) : Exception(message) {
actual constructor() : this(null)
public actual constructor() : this(null)
}
@@ -13,13 +13,13 @@ import kotlin.wasm.internal.wasm_f32_demote_f64
*
* There are also strict versions of the function available on non-nullable String, [toBooleanStrict] and [toBooleanStrictOrNull].
*/
actual fun String?.toBoolean(): Boolean = this != null && this.lowercase() == "true"
public actual fun String?.toBoolean(): Boolean = this != null && this.lowercase() == "true"
/**
* Parses the string as a signed [Byte] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
actual fun String.toByte(): Byte = toByteOrNull() ?: numberFormatError(this)
public actual fun String.toByte(): Byte = toByteOrNull() ?: numberFormatError(this)
/**
* Parses the string as a signed [Byte] number and returns the result.
@@ -119,7 +119,7 @@ public actual fun Short.toString(radix: Int): String = this.toLong().toString(ra
* @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
*/
@SinceKotlin("1.2")
actual fun Int.toString(radix: Int): String = toLong().toString(radix)
public actual fun Int.toString(radix: Int): String = toLong().toString(radix)
/**
* Returns a string representation of this [Long] value in the specified [radix].
@@ -127,7 +127,7 @@ actual fun Int.toString(radix: Int): String = toLong().toString(radix)
* @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
*/
@SinceKotlin("1.2")
actual fun Long.toString(radix: Int): String {
public actual fun Long.toString(radix: Int): String {
checkRadix(radix)
fun Long.getChar() = toInt().let { if (it < 10) '0' + it else 'a' + (it - 10) }
@@ -513,7 +513,7 @@ public actual fun CharSequence.isBlank(): Boolean = length == 0 || indices.all {
* @param otherOffset the start offset in the other char sequence of the substring to compare.
* @param length the length of the substring to compare.
*/
actual fun CharSequence.regionMatches(
public actual fun CharSequence.regionMatches(
thisOffset: Int,
other: CharSequence,
otherOffset: Int,
@@ -13,12 +13,12 @@ import kotlin.wasm.internal.getSimpleName
* @param message the detail message string.
* @param cause the cause of this throwable.
*/
public open class Throwable(open val message: String?, open val cause: kotlin.Throwable?) {
constructor(message: String?) : this(message, null)
public open class Throwable(public open val message: String?, public open val cause: kotlin.Throwable?) {
public constructor(message: String?) : this(message, null)
constructor(cause: Throwable?) : this(cause?.toString(), cause)
public constructor(cause: Throwable?) : this(cause?.toString(), cause)
constructor() : this(null, null)
public constructor() : this(null, null)
//TODO: Investigate possibility to make WASI stack discoverable (KT-60965)
internal val stack: String get() = ""