From ee9608f8dbb893e27e43263c7793184d0a91c3fb Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 24 Jan 2018 21:25:37 +0300 Subject: [PATCH] stdlib-js: add actual modifiers where required --- libraries/stdlib/js/src/kotlin/Comparator.kt | 6 +- .../stdlib/js/src/kotlin/annotationsJVM.kt | 11 +- libraries/stdlib/js/src/kotlin/char.kt | 10 +- libraries/stdlib/js/src/kotlin/collections.kt | 30 +-- .../kotlin/collections/AbstractMutableList.kt | 26 +-- .../kotlin/collections/AbstractMutableMap.kt | 4 +- .../kotlin/collections/AbstractMutableSet.kt | 2 +- .../js/src/kotlin/collections/ArrayList.kt | 41 ++-- .../js/src/kotlin/collections/HashMap.kt | 28 +-- .../js/src/kotlin/collections/HashSet.kt | 24 ++- .../src/kotlin/collections/LinkedHashMap.kt | 25 ++- .../src/kotlin/collections/LinkedHashSet.kt | 10 +- .../js/src/kotlin/collections/RandomAccess.kt | 2 +- libraries/stdlib/js/src/kotlin/concurrent.kt | 2 +- libraries/stdlib/js/src/kotlin/console.kt | 6 +- libraries/stdlib/js/src/kotlin/coroutines.kt | 14 +- .../js/src/kotlin/coroutinesIntrinsics.kt | 8 +- libraries/stdlib/js/src/kotlin/exceptions.kt | 138 ++++++------- libraries/stdlib/js/src/kotlin/grouping.kt | 2 +- libraries/stdlib/js/src/kotlin/io.kt | 2 +- libraries/stdlib/js/src/kotlin/kotlin.kt | 6 +- libraries/stdlib/js/src/kotlin/math.kt | 188 +++++++++--------- .../stdlib/js/src/kotlin/numberConversions.kt | 30 +-- libraries/stdlib/js/src/kotlin/numbers.kt | 24 +-- libraries/stdlib/js/src/kotlin/regex.kt | 40 ++-- libraries/stdlib/js/src/kotlin/sequence.kt | 4 +- libraries/stdlib/js/src/kotlin/string.kt | 12 +- libraries/stdlib/js/src/kotlin/stringsCode.kt | 24 +-- libraries/stdlib/js/src/kotlin/text.kt | 32 +-- 29 files changed, 383 insertions(+), 368 deletions(-) diff --git a/libraries/stdlib/js/src/kotlin/Comparator.kt b/libraries/stdlib/js/src/kotlin/Comparator.kt index 052a762036c..8e32f09a125 100644 --- a/libraries/stdlib/js/src/kotlin/Comparator.kt +++ b/libraries/stdlib/js/src/kotlin/Comparator.kt @@ -17,10 +17,10 @@ package kotlin -public interface Comparator { - @JsName("compare") fun compare(a: T, b: T): Int +public actual interface Comparator { + @JsName("compare") actual fun compare(a: T, b: T): Int } -public inline fun Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator = object : Comparator { +public actual inline fun Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator = object : Comparator { override fun compare(a: T, b: T): Int = comparison(a, b) } diff --git a/libraries/stdlib/js/src/kotlin/annotationsJVM.kt b/libraries/stdlib/js/src/kotlin/annotationsJVM.kt index 0ca155ad7f5..18194bd4c5b 100644 --- a/libraries/stdlib/js/src/kotlin/annotationsJVM.kt +++ b/libraries/stdlib/js/src/kotlin/annotationsJVM.kt @@ -25,22 +25,25 @@ internal annotation class JvmOverloads @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FILE) @Retention(AnnotationRetention.SOURCE) @MustBeDocumented -internal annotation class JvmName(public val name: String) +@Suppress("ACTUAL_WITHOUT_EXPECT") // TODO: KT-19507 +internal actual annotation class JvmName(public actual val name: String) @Target(AnnotationTarget.FILE) @Retention(AnnotationRetention.SOURCE) @MustBeDocumented -internal annotation class JvmMultifileClass +@Suppress("ACTUAL_WITHOUT_EXPECT") // TODO: KT-19507 +internal actual annotation class JvmMultifileClass @Target(AnnotationTarget.FIELD) @Retention(AnnotationRetention.SOURCE) @MustBeDocumented -internal annotation class JvmField +@Suppress("ACTUAL_WITHOUT_EXPECT") // TODO: KT-19507 +internal actual annotation class JvmField @Target(AnnotationTarget.FIELD) @Retention(AnnotationRetention.SOURCE) -public annotation class Volatile +public actual annotation class Volatile @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) @Retention(AnnotationRetention.SOURCE) diff --git a/libraries/stdlib/js/src/kotlin/char.kt b/libraries/stdlib/js/src/kotlin/char.kt index 93417ccbb7f..065621903cc 100644 --- a/libraries/stdlib/js/src/kotlin/char.kt +++ b/libraries/stdlib/js/src/kotlin/char.kt @@ -17,20 +17,20 @@ package kotlin.text // actually \s is enough to match all whitespace, but \xA0 added because of different regexp behavior of Rhino used in Selenium tests -public fun Char.isWhitespace(): Boolean = toString().matches("[\\s\\xA0]") +public actual fun Char.isWhitespace(): Boolean = toString().matches("[\\s\\xA0]") @kotlin.internal.InlineOnly -public inline fun Char.toLowerCase(): Char = js("String.fromCharCode")(this).toLowerCase().charCodeAt(0) +public actual inline fun Char.toLowerCase(): Char = js("String.fromCharCode")(this).toLowerCase().charCodeAt(0) @kotlin.internal.InlineOnly -public inline fun Char.toUpperCase(): Char = js("String.fromCharCode")(this).toUpperCase().charCodeAt(0) +public actual inline fun Char.toUpperCase(): Char = js("String.fromCharCode")(this).toUpperCase().charCodeAt(0) /** * Returns `true` if this character is a Unicode high-surrogate code unit (also known as leading-surrogate code unit). */ -public fun Char.isHighSurrogate(): Boolean = this in Char.MIN_HIGH_SURROGATE..Char.MAX_HIGH_SURROGATE +public actual fun Char.isHighSurrogate(): Boolean = this in Char.MIN_HIGH_SURROGATE..Char.MAX_HIGH_SURROGATE /** * Returns `true` if this character is a Unicode low-surrogate code unit (also known as trailing-surrogate code unit). */ -public fun Char.isLowSurrogate(): Boolean = this in Char.MIN_LOW_SURROGATE..Char.MAX_LOW_SURROGATE +public actual fun Char.isLowSurrogate(): Boolean = this in Char.MIN_LOW_SURROGATE..Char.MAX_LOW_SURROGATE diff --git a/libraries/stdlib/js/src/kotlin/collections.kt b/libraries/stdlib/js/src/kotlin/collections.kt index e1b141b92e8..a73ffdcccc4 100644 --- a/libraries/stdlib/js/src/kotlin/collections.kt +++ b/libraries/stdlib/js/src/kotlin/collections.kt @@ -21,10 +21,10 @@ import kotlin.math.floor /** Returns the array if it's not `null`, or an empty array otherwise. */ @kotlin.internal.InlineOnly -public inline fun Array?.orEmpty(): Array = this ?: emptyArray() +public actual inline fun Array?.orEmpty(): Array = this ?: emptyArray() @kotlin.internal.InlineOnly -public inline fun Collection.toTypedArray(): Array = copyToArray(this) +public actual inline fun Collection.toTypedArray(): Array = copyToArray(this) @JsName("copyToArray") @PublishedApi @@ -36,7 +36,7 @@ internal fun copyToArray(collection: Collection): Array { } @JsName("copyToArrayImpl") -internal fun copyToArrayImpl(collection: Collection<*>): Array { +internal actual fun copyToArrayImpl(collection: Collection<*>): Array { val array = emptyArray() val iterator = collection.iterator() while (iterator.hasNext()) @@ -45,7 +45,7 @@ internal fun copyToArrayImpl(collection: Collection<*>): Array { } @JsName("copyToExistingArrayImpl") -internal fun copyToArrayImpl(collection: Collection<*>, array: Array): Array { +internal actual fun copyToArrayImpl(collection: Collection<*>, array: Array): Array { if (array.size < collection.size) return copyToArrayImpl(collection).unsafeCast>() @@ -86,7 +86,7 @@ public fun mapOf(pair: Pair): Map = hashMapOf(pair) * Each element in the list gets replaced with the [value]. */ @SinceKotlin("1.2") -public fun MutableList.fill(value: T): Unit { +public actual fun MutableList.fill(value: T): Unit { for (index in 0..lastIndex) { this[index] = value } @@ -98,7 +98,7 @@ public fun MutableList.fill(value: T): Unit { * See: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm */ @SinceKotlin("1.2") -public fun MutableList.shuffle(): Unit { +public actual fun MutableList.shuffle(): Unit { for (i in lastIndex downTo 1) { val j = rand(i + 1) val copy = this[i] @@ -112,19 +112,19 @@ private fun rand(upperBound: Int) = floor(kotlin.js.Math.random() * upperBound). * Returns a new list with the elements of this list randomly shuffled. */ @SinceKotlin("1.2") -public fun Iterable.shuffled(): List = toMutableList().apply { shuffle() } +public actual fun Iterable.shuffled(): List = toMutableList().apply { shuffle() } /** * Sorts elements in the list in-place according to their natural sort order. */ -public fun > MutableList.sort(): Unit { +public actual fun > MutableList.sort(): Unit { collectionsSort(this, naturalOrder()) } /** * Sorts elements in the list in-place according to the order specified with [comparator]. */ -public fun MutableList.sortWith(comparator: Comparator): Unit { +public actual fun MutableList.sortWith(comparator: Comparator): Unit { collectionsSort(this, comparator) } @@ -140,16 +140,20 @@ private fun collectionsSort(list: MutableList, comparator: Comparator arrayOfNulls(reference: Array, size: Int): Array { +internal actual fun arrayOfNulls(reference: Array, size: Int): Array { return arrayOfNulls(size).unsafeCast>() } // no singleton map implementation in js, return map as is -internal inline fun Map.toSingletonMapOrSelf(): Map = this +@Suppress("NOTHING_TO_INLINE") +internal actual inline fun Map.toSingletonMapOrSelf(): Map = this -internal inline fun Map.toSingletonMap(): Map = this.toMutableMap() +@Suppress("NOTHING_TO_INLINE") +internal actual inline fun Map.toSingletonMap(): Map = this.toMutableMap() -internal inline fun Array.copyToArrayOfAny(isVarargs: Boolean): Array = + +@Suppress("NOTHING_TO_INLINE") +internal actual inline fun Array.copyToArrayOfAny(isVarargs: Boolean): Array = if (isVarargs) // no need to copy vararg array in JS this diff --git a/libraries/stdlib/js/src/kotlin/collections/AbstractMutableList.kt b/libraries/stdlib/js/src/kotlin/collections/AbstractMutableList.kt index af34d7e9185..4587cf401b5 100644 --- a/libraries/stdlib/js/src/kotlin/collections/AbstractMutableList.kt +++ b/libraries/stdlib/js/src/kotlin/collections/AbstractMutableList.kt @@ -26,19 +26,19 @@ package kotlin.collections * * @param E the type of elements contained in the list. The list is invariant on its element type. */ -public abstract class AbstractMutableList protected constructor() : AbstractMutableCollection(), MutableList { +public actual abstract class AbstractMutableList protected actual constructor() : AbstractMutableCollection(), MutableList { protected var modCount: Int = 0 abstract override fun add(index: Int, element: E): Unit abstract override fun removeAt(index: Int): E abstract override fun set(index: Int, element: E): E - override fun add(element: E): Boolean { + actual override fun add(element: E): Boolean { add(size, element) return true } - override fun addAll(index: Int, elements: Collection): Boolean { + actual override fun addAll(index: Int, elements: Collection): Boolean { var _index = index var changed = false for (e in elements) { @@ -48,19 +48,19 @@ public abstract class AbstractMutableList protected constructor() : AbstractM return changed } - override fun clear() { + actual override fun clear() { removeRange(0, size) } - override fun removeAll(elements: Collection): Boolean = removeAll { it in elements } - override fun retainAll(elements: Collection): Boolean = removeAll { it !in elements } + actual override fun removeAll(elements: Collection): Boolean = removeAll { it in elements } + actual override fun retainAll(elements: Collection): Boolean = removeAll { it !in elements } - override fun iterator(): MutableIterator = IteratorImpl() + actual override fun iterator(): MutableIterator = IteratorImpl() - override fun contains(element: E): Boolean = indexOf(element) >= 0 + actual override fun contains(element: E): Boolean = indexOf(element) >= 0 - override fun indexOf(element: E): Int { + actual override fun indexOf(element: E): Int { for (index in 0..lastIndex) { if (get(index) == element) { return index @@ -69,7 +69,7 @@ public abstract class AbstractMutableList protected constructor() : AbstractM return -1 } - override fun lastIndexOf(element: E): Int { + actual override fun lastIndexOf(element: E): Int { for (index in lastIndex downTo 0) { if (get(index) == element) { return index @@ -78,11 +78,11 @@ public abstract class AbstractMutableList protected constructor() : AbstractM return -1 } - override fun listIterator(): MutableListIterator = listIterator(0) - override fun listIterator(index: Int): MutableListIterator = ListIteratorImpl(index) + actual override fun listIterator(): MutableListIterator = listIterator(0) + actual override fun listIterator(index: Int): MutableListIterator = ListIteratorImpl(index) - override fun subList(fromIndex: Int, toIndex: Int): MutableList = SubList(this, fromIndex, toIndex) + actual override fun subList(fromIndex: Int, toIndex: Int): MutableList = SubList(this, fromIndex, toIndex) /** * Removes the range of elements from this list starting from [fromIndex] and ending with but not including [toIndex]. diff --git a/libraries/stdlib/js/src/kotlin/collections/AbstractMutableMap.kt b/libraries/stdlib/js/src/kotlin/collections/AbstractMutableMap.kt index a24a211abaf..eee05806882 100644 --- a/libraries/stdlib/js/src/kotlin/collections/AbstractMutableMap.kt +++ b/libraries/stdlib/js/src/kotlin/collections/AbstractMutableMap.kt @@ -28,7 +28,7 @@ package kotlin.collections * @param K the type of map keys. The map is invariant on its key type. * @param V the type of map values. The map is invariant on its value type. */ -public abstract class AbstractMutableMap protected constructor() : AbstractMap(), MutableMap { +public actual abstract class AbstractMutableMap protected actual constructor() : AbstractMap(), MutableMap { /** * A mutable [Map.Entry] shared by several [Map] implementations. @@ -90,7 +90,7 @@ public abstract class AbstractMutableMap protected constructor() : Abstrac return _keys!! } - abstract override fun put(key: K, value: V): V? + actual abstract override fun put(key: K, value: V): V? override fun putAll(from: Map) { for ((key, value) in from) { diff --git a/libraries/stdlib/js/src/kotlin/collections/AbstractMutableSet.kt b/libraries/stdlib/js/src/kotlin/collections/AbstractMutableSet.kt index 7692853afb1..5585d98cf03 100644 --- a/libraries/stdlib/js/src/kotlin/collections/AbstractMutableSet.kt +++ b/libraries/stdlib/js/src/kotlin/collections/AbstractMutableSet.kt @@ -20,7 +20,7 @@ package kotlin.collections * * @param E the type of elements contained in the set. The set is invariant on its element type. */ -public abstract class AbstractMutableSet protected constructor() : AbstractMutableCollection(), MutableSet { +public actual abstract class AbstractMutableSet protected actual constructor() : AbstractMutableCollection(), MutableSet { /** * Compares this set with another set instance with the unordered structural equality. diff --git a/libraries/stdlib/js/src/kotlin/collections/ArrayList.kt b/libraries/stdlib/js/src/kotlin/collections/ArrayList.kt index 1d7f21ba451..6bd9fee887c 100644 --- a/libraries/stdlib/js/src/kotlin/collections/ArrayList.kt +++ b/libraries/stdlib/js/src/kotlin/collections/ArrayList.kt @@ -23,42 +23,47 @@ package kotlin.collections * There is no speed advantage to pre-allocating array sizes in JavaScript, so this implementation does not include any of the * capacity and "growth increment" concepts. */ -public open class ArrayList internal constructor(private var array: Array) : AbstractMutableList(), RandomAccess { +public actual open class ArrayList internal constructor(private var array: Array) : AbstractMutableList(), MutableList, RandomAccess { /** * Creates an empty [ArrayList]. - * @param capacity initial capacity (ignored) */ - public constructor(@Suppress("UNUSED_PARAMETER") capacity: Int = 0) : this(emptyArray()) {} + public actual constructor() : this(emptyArray()) {} + + /** + * Creates an empty [ArrayList]. + * @param initialCapacity initial capacity (ignored) + */ + public actual constructor(@Suppress("UNUSED_PARAMETER") initialCapacity: Int) : this(emptyArray()) {} /** * Creates an [ArrayList] filled from the [elements] collection. */ - public constructor(elements: Collection) : this(elements.toTypedArray()) {} + public actual constructor(elements: Collection) : this(elements.toTypedArray()) {} /** Does nothing in this ArrayList implementation. */ - public fun trimToSize() {} + public actual fun trimToSize() {} /** Does nothing in this ArrayList implementation. */ - public fun ensureCapacity(@Suppress("UNUSED_PARAMETER") minCapacity: Int) {} + public actual fun ensureCapacity(@Suppress("UNUSED_PARAMETER") minCapacity: Int) {} - override val size: Int get() = array.size - override fun get(index: Int): E = array[rangeCheck(index)] as E - override fun set(index: Int, element: E): E { + actual override val size: Int get() = array.size + actual override fun get(index: Int): E = array[rangeCheck(index)] as E + actual override fun set(index: Int, element: E): E { rangeCheck(index) return array[index].apply { array[index] = element } as E } - override fun add(element: E): Boolean { + actual override fun add(element: E): Boolean { array.asDynamic().push(element) modCount++ return true } - override fun add(index: Int, element: E): Unit { + actual override fun add(index: Int, element: E): Unit { array.asDynamic().splice(insertionRangeCheck(index), 0, element) modCount++ } - override fun addAll(elements: Collection): Boolean { + actual override fun addAll(elements: Collection): Boolean { if (elements.isEmpty()) return false array += elements.toTypedArray() @@ -66,7 +71,7 @@ public open class ArrayList internal constructor(private var array: Array): Boolean { + actual override fun addAll(index: Int, elements: Collection): Boolean { insertionRangeCheck(index) if (index == size) return addAll(elements) @@ -81,7 +86,7 @@ public open class ArrayList internal constructor(private var array: Array internal constructor(private var array: Array internal constructor(private var array: Array = js("[]").slice.call(array) diff --git a/libraries/stdlib/js/src/kotlin/collections/HashMap.kt b/libraries/stdlib/js/src/kotlin/collections/HashMap.kt index 250959d8841..b14c82dbfd7 100644 --- a/libraries/stdlib/js/src/kotlin/collections/HashMap.kt +++ b/libraries/stdlib/js/src/kotlin/collections/HashMap.kt @@ -20,7 +20,6 @@ package kotlin.collections -import kotlin.collections.Map.Entry import kotlin.collections.MutableMap.MutableEntry /** @@ -28,7 +27,7 @@ import kotlin.collections.MutableMap.MutableEntry * * This implementation makes no guarantees regarding the order of enumeration of [keys], [values] and [entries] collections. */ -public open class HashMap : AbstractMutableMap { +public actual open class HashMap : AbstractMutableMap, MutableMap { private inner class EntrySet : AbstractMutableSet>() { @@ -68,7 +67,7 @@ public open class HashMap : AbstractMutableMap { /** * Constructs an empty [HashMap] instance. */ - constructor() : this(InternalHashCodeMap(EqualityComparator.HashCode)) + actual constructor() : this(InternalHashCodeMap(EqualityComparator.HashCode)) /** * Constructs an empty [HashMap] instance. @@ -78,30 +77,33 @@ public open class HashMap : AbstractMutableMap { * * @throws IllegalArgumentException if the initial capacity or load factor are negative */ - constructor(initialCapacity: Int, loadFactor: Float = 0f) : this() { + actual constructor(initialCapacity: Int, loadFactor: Float) : this() { // This implementation of HashMap has no need of load factors or capacities. require(initialCapacity >= 0) { "Negative initial capacity" } require(loadFactor >= 0) { "Non-positive load factor" } } + actual constructor(initialCapacity: Int) : this(initialCapacity, 0.0f) + + /** * Constructs an instance of [HashMap] filled with the contents of the specified [original] map. */ - constructor(original: Map) : this() { + actual constructor(original: Map) : this() { this.putAll(original) } - override fun clear() { + actual override fun clear() { internalMap.clear() // structureChanged(this) } - override fun containsKey(key: K): Boolean = internalMap.contains(key) + actual override fun containsKey(key: K): Boolean = internalMap.contains(key) - override fun containsValue(value: V): Boolean = internalMap.any { equality.equals(it.value, value) } + actual override fun containsValue(value: V): Boolean = internalMap.any { equality.equals(it.value, value) } private var _entries: MutableSet>? = null - override val entries: MutableSet> get() { + actual override val entries: MutableSet> get() { if (_entries == null) { _entries = createEntrySet() } @@ -110,13 +112,13 @@ public open class HashMap : AbstractMutableMap { protected open fun createEntrySet(): MutableSet> = EntrySet() - override operator fun get(key: K): V? = internalMap.get(key) + actual override operator fun get(key: K): V? = internalMap.get(key) - override fun put(key: K, value: V): V? = internalMap.put(key, value) + actual override fun put(key: K, value: V): V? = internalMap.put(key, value) - override fun remove(key: K): V? = internalMap.remove(key) + actual override fun remove(key: K): V? = internalMap.remove(key) - override val size: Int get() = internalMap.size + actual override val size: Int get() = internalMap.size } diff --git a/libraries/stdlib/js/src/kotlin/collections/HashSet.kt b/libraries/stdlib/js/src/kotlin/collections/HashSet.kt index 1a15197f305..70188bcf2a4 100644 --- a/libraries/stdlib/js/src/kotlin/collections/HashSet.kt +++ b/libraries/stdlib/js/src/kotlin/collections/HashSet.kt @@ -23,21 +23,21 @@ package kotlin.collections /** * The implementation of the [MutableSet] interface, backed by a [HashMap] instance. */ -public open class HashSet : AbstractMutableSet { +public actual open class HashSet : AbstractMutableSet, MutableSet { private val map: HashMap /** * Constructs a new empty [HashSet]. */ - constructor() { + actual constructor() { map = HashMap() } /** * Constructs a new [HashSet] filled with the elements of the specified collection. */ - constructor(elements: Collection) { + actual constructor(elements: Collection) { map = HashMap(elements.size) addAll(elements) } @@ -50,10 +50,12 @@ public open class HashSet : AbstractMutableSet { * * @throws IllegalArgumentException if the initial capacity or load factor are negative */ - constructor(initialCapacity: Int, loadFactor: Float = 0.0f) { + actual constructor(initialCapacity: Int, loadFactor: Float) { map = HashMap(initialCapacity, loadFactor) } + actual constructor(initialCapacity: Int) : this(initialCapacity, 0.0f) + /** * Protected constructor to specify the underlying map. This is used by * LinkedHashSet. @@ -64,12 +66,12 @@ public open class HashSet : AbstractMutableSet { this.map = map } - override fun add(element: E): Boolean { + actual override fun add(element: E): Boolean { val old = map.put(element, this) return old == null } - override fun clear() { + actual override fun clear() { map.clear() } @@ -77,15 +79,15 @@ public open class HashSet : AbstractMutableSet { // return HashSet(this) // } - override operator fun contains(element: E): Boolean = map.containsKey(element) + actual override operator fun contains(element: E): Boolean = map.containsKey(element) - override fun isEmpty(): Boolean = map.isEmpty() + actual override fun isEmpty(): Boolean = map.isEmpty() - override fun iterator(): MutableIterator = map.keys.iterator() + actual override fun iterator(): MutableIterator = map.keys.iterator() - override fun remove(element: E): Boolean = map.remove(element) != null + actual override fun remove(element: E): Boolean = map.remove(element) != null - override val size: Int get() = map.size + actual override val size: Int get() = map.size } diff --git a/libraries/stdlib/js/src/kotlin/collections/LinkedHashMap.kt b/libraries/stdlib/js/src/kotlin/collections/LinkedHashMap.kt index 6be99e0a0f0..45918233a2e 100644 --- a/libraries/stdlib/js/src/kotlin/collections/LinkedHashMap.kt +++ b/libraries/stdlib/js/src/kotlin/collections/LinkedHashMap.kt @@ -27,7 +27,7 @@ import kotlin.collections.MutableMap.MutableEntry * * The insertion order is preserved by maintaining a doubly-linked list of all of its entries. */ -public open class LinkedHashMap : HashMap, Map { +public actual open class LinkedHashMap : HashMap, MutableMap { /** * The entry we use includes next/prev pointers for a doubly-linked circular @@ -169,7 +169,7 @@ public open class LinkedHashMap : HashMap, Map { /** * Constructs an empty [LinkedHashMap] instance. */ - constructor() : super() { + actual constructor() : super() { map = HashMap>() } @@ -186,19 +186,21 @@ public open class LinkedHashMap : HashMap, Map { * * @throws IllegalArgumentException if the initial capacity or load factor are negative */ - constructor(initialCapacity: Int, loadFactor: Float = 0f) : super(initialCapacity, loadFactor) { + actual constructor(initialCapacity: Int, loadFactor: Float) : super(initialCapacity, loadFactor) { map = HashMap>() } + actual constructor(initialCapacity: Int) : this(initialCapacity, 0.0f) + /** * Constructs an instance of [LinkedHashMap] filled with the contents of the specified [original] map. */ - constructor(original: Map) { + actual constructor(original: Map) { map = HashMap>() this.putAll(original) } - override fun clear() { + actual override fun clear() { map.clear() head = null } @@ -208,9 +210,10 @@ public open class LinkedHashMap : HashMap, Map { // return LinkedHashMap(this) // } - override fun containsKey(key: K): Boolean = map.containsKey(key) - override fun containsValue(value: V): Boolean { + actual override fun containsKey(key: K): Boolean = map.containsKey(key) + + actual override fun containsValue(value: V): Boolean { var node: ChainEntry = head ?: return false do { if (node.value == value) { @@ -224,9 +227,9 @@ public open class LinkedHashMap : HashMap, Map { override fun createEntrySet(): MutableSet> = EntrySet() - override operator fun get(key: K): V? = map.get(key)?.value + actual override operator fun get(key: K): V? = map.get(key)?.value - override fun put(key: K, value: V): V? { + actual override fun put(key: K, value: V): V? { val old = map.get(key) if (old == null) { val newEntry = ChainEntry(key, value) @@ -239,7 +242,7 @@ public open class LinkedHashMap : HashMap, Map { } } - override fun remove(key: K): V? { + actual override fun remove(key: K): V? { val entry = map.remove(key) if (entry != null) { entry.remove() @@ -248,7 +251,7 @@ public open class LinkedHashMap : HashMap, Map { return null } - override val size: Int get() = map.size + actual override val size: Int get() = map.size } diff --git a/libraries/stdlib/js/src/kotlin/collections/LinkedHashSet.kt b/libraries/stdlib/js/src/kotlin/collections/LinkedHashSet.kt index f31b25efc94..b2986781683 100644 --- a/libraries/stdlib/js/src/kotlin/collections/LinkedHashSet.kt +++ b/libraries/stdlib/js/src/kotlin/collections/LinkedHashSet.kt @@ -25,19 +25,19 @@ package kotlin.collections * * This implementation preserves the insertion order of elements during the iteration. */ -public open class LinkedHashSet : HashSet { +public actual open class LinkedHashSet : HashSet, MutableSet { internal constructor(map: LinkedHashMap) : super(map) /** * Constructs a new empty [LinkedHashSet]. */ - constructor() : super(LinkedHashMap()) + actual constructor() : super(LinkedHashMap()) /** * Constructs a new [LinkedHashSet] filled with the elements of the specified collection. */ - constructor(elements: Collection) : super(LinkedHashMap()) { + actual constructor(elements: Collection) : super(LinkedHashMap()) { addAll(elements) } /** @@ -48,7 +48,9 @@ public open class LinkedHashSet : HashSet { * * @throws IllegalArgumentException if the initial capacity or load factor are negative */ - constructor(initialCapacity: Int, loadFactor: Float = 0.0f) : super(LinkedHashMap(initialCapacity, loadFactor)) + actual constructor(initialCapacity: Int, loadFactor: Float) : super(LinkedHashMap(initialCapacity, loadFactor)) + + actual constructor(initialCapacity: Int) : this(initialCapacity, 0.0f) // public override fun clone(): Any { // return LinkedHashSet(this) diff --git a/libraries/stdlib/js/src/kotlin/collections/RandomAccess.kt b/libraries/stdlib/js/src/kotlin/collections/RandomAccess.kt index 6da6377f9a5..85f64cd4a3a 100644 --- a/libraries/stdlib/js/src/kotlin/collections/RandomAccess.kt +++ b/libraries/stdlib/js/src/kotlin/collections/RandomAccess.kt @@ -19,4 +19,4 @@ package kotlin.collections /** * Marker interface indicating that the [List] implementation supports fast indexed access. */ -public interface RandomAccess \ No newline at end of file +public actual interface RandomAccess \ No newline at end of file diff --git a/libraries/stdlib/js/src/kotlin/concurrent.kt b/libraries/stdlib/js/src/kotlin/concurrent.kt index e20b93d9c3e..f3469a7e9a3 100644 --- a/libraries/stdlib/js/src/kotlin/concurrent.kt +++ b/libraries/stdlib/js/src/kotlin/concurrent.kt @@ -23,4 +23,4 @@ public typealias Synchronized = kotlin.jvm.Synchronized public typealias Volatile = kotlin.jvm.Volatile @kotlin.internal.InlineOnly -public inline fun synchronized(@Suppress("UNUSED_PARAMETER") lock: Any, block: () -> R): R = block() +public actual inline fun synchronized(@Suppress("UNUSED_PARAMETER") lock: Any, block: () -> R): R = block() diff --git a/libraries/stdlib/js/src/kotlin/console.kt b/libraries/stdlib/js/src/kotlin/console.kt index 26ce742ff17..ee09b253e85 100644 --- a/libraries/stdlib/js/src/kotlin/console.kt +++ b/libraries/stdlib/js/src/kotlin/console.kt @@ -98,16 +98,16 @@ private var output = run { private inline fun String(value: Any?): String = js("String")(value) /** Prints a newline to the standard output stream. */ -public fun println() { +public actual fun println() { output.println() } /** Prints the given message and newline to the standard output stream. */ -public fun println(message: Any?) { +public actual fun println(message: Any?) { output.println(message) } /** Prints the given message to the standard output stream. */ -public fun print(message: Any?) { +public actual fun print(message: Any?) { output.print(message) } diff --git a/libraries/stdlib/js/src/kotlin/coroutines.kt b/libraries/stdlib/js/src/kotlin/coroutines.kt index 4b4016400ef..e62a98d2e97 100644 --- a/libraries/stdlib/js/src/kotlin/coroutines.kt +++ b/libraries/stdlib/js/src/kotlin/coroutines.kt @@ -52,21 +52,21 @@ private val RESUMED: Any? = Any() private class Fail(val exception: Throwable) @PublishedApi -internal class SafeContinuation -internal constructor( +internal actual class SafeContinuation +internal actual constructor( private val delegate: Continuation, initialResult: Any? ) : Continuation { @PublishedApi - internal constructor(delegate: Continuation) : this(delegate, UNDECIDED) + internal actual constructor(delegate: Continuation) : this(delegate, UNDECIDED) - public override val context: CoroutineContext + public actual override val context: CoroutineContext get() = delegate.context private var result: Any? = initialResult - override fun resume(value: T) { + actual override fun resume(value: T) { when { result === UNDECIDED -> { result = value @@ -81,7 +81,7 @@ internal constructor( } } - override fun resumeWithException(exception: Throwable) { + actual override fun resumeWithException(exception: Throwable) { when { result === UNDECIDED -> { result = Fail(exception) @@ -97,7 +97,7 @@ internal constructor( } @PublishedApi - internal fun getResult(): Any? { + internal actual fun getResult(): Any? { if (result === UNDECIDED) { result = COROUTINE_SUSPENDED } diff --git a/libraries/stdlib/js/src/kotlin/coroutinesIntrinsics.kt b/libraries/stdlib/js/src/kotlin/coroutinesIntrinsics.kt index 0a129c2350e..f834b51dfff 100644 --- a/libraries/stdlib/js/src/kotlin/coroutinesIntrinsics.kt +++ b/libraries/stdlib/js/src/kotlin/coroutinesIntrinsics.kt @@ -21,25 +21,25 @@ import kotlin.coroutines.experimental.Continuation @SinceKotlin("1.1") @Suppress("UNCHECKED_CAST") @kotlin.internal.InlineOnly -public inline fun (suspend () -> T).startCoroutineUninterceptedOrReturn( +public actual inline fun (suspend () -> T).startCoroutineUninterceptedOrReturn( completion: Continuation ): Any? = this.asDynamic()(completion, false) @SinceKotlin("1.1") @Suppress("UNCHECKED_CAST") @kotlin.internal.InlineOnly -public inline fun (suspend R.() -> T).startCoroutineUninterceptedOrReturn( +public actual inline fun (suspend R.() -> T).startCoroutineUninterceptedOrReturn( receiver: R, completion: Continuation ): Any? = this.asDynamic()(receiver, completion, false) @SinceKotlin("1.1") -public fun (suspend R.() -> T).createCoroutineUnchecked( +public actual fun (suspend R.() -> T).createCoroutineUnchecked( receiver: R, completion: Continuation ): Continuation = this.asDynamic()(receiver, completion, true).facade @SinceKotlin("1.1") -public fun (suspend () -> T).createCoroutineUnchecked( +public actual fun (suspend () -> T).createCoroutineUnchecked( completion: Continuation ): Continuation = this.asDynamic()(completion, true).facade diff --git a/libraries/stdlib/js/src/kotlin/exceptions.kt b/libraries/stdlib/js/src/kotlin/exceptions.kt index 50552885230..6cdfcf90188 100644 --- a/libraries/stdlib/js/src/kotlin/exceptions.kt +++ b/libraries/stdlib/js/src/kotlin/exceptions.kt @@ -31,102 +31,102 @@ public open class MyException : Exception { // TODO: remove primary constructors, make all secondary KT-22055 @Suppress("USELESS_ELVIS_RIGHT_IS_NULL") -public open class Error(message: String?, cause: Throwable?) : Throwable(message, cause ?: null) { - constructor() : this(null, null) { +public actual open class Error actual constructor(message: String?, cause: Throwable?) : Throwable(message, cause ?: null) { + actual constructor() : this(null, null) { Error::class.js.asDynamic().call(this, null, null) } - constructor(message: String?) : this(message, null) { + actual constructor(message: String?) : this(message, null) { Error::class.js.asDynamic().call(this, message, null) } - constructor(cause: Throwable?) : this(undefined, cause) { + actual constructor(cause: Throwable?) : this(undefined, cause) { Error::class.js.asDynamic().call(this, undefined, cause) } } @Suppress("USELESS_ELVIS_RIGHT_IS_NULL") -public open class Exception(message: String?, cause: Throwable?) : Throwable(message, cause ?: null) { - constructor() : this(null, null) { +public actual open class Exception actual constructor(message: String?, cause: Throwable?) : Throwable(message, cause ?: null) { + actual constructor() : this(null, null) { Exception::class.js.asDynamic().call(this, null, null) } - constructor(message: String?) : this(message, null) { + actual constructor(message: String?) : this(message, null) { Exception::class.js.asDynamic().call(this, message, null) } - constructor(cause: Throwable?) : this(undefined, cause) { + actual constructor(cause: Throwable?) : this(undefined, cause) { Exception::class.js.asDynamic().call(this, undefined, cause) } } -public open class RuntimeException(message: String?, cause: Throwable?) : Exception(message, cause) { - constructor() : this(null, null) +public actual open class RuntimeException actual constructor(message: String?, cause: Throwable?) : Exception(message, cause) { + actual constructor() : this(null, null) + actual constructor(message: String?) : this(message, null) + actual constructor(cause: Throwable?) : this(undefined, cause) +} + +public actual open class IllegalArgumentException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) { + actual constructor() : this(null, null) + actual constructor(message: String?) : this(message, null) + actual constructor(cause: Throwable?) : this(undefined, cause) +} + +public actual open class IllegalStateException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) { + actual constructor() : this(null, null) + actual constructor(message: String?) : this(message, null) + actual constructor(cause: Throwable?) : this(undefined, cause) +} + +public actual open class IndexOutOfBoundsException actual constructor(message: String?) : RuntimeException(message) { + actual constructor() : this(null) +} + +public actual open class ConcurrentModificationException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) { + actual constructor() : this(null, null) + actual constructor(message: String?) : this(message, null) + actual constructor(cause: Throwable?) : this(undefined, cause) +} + +public actual open class UnsupportedOperationException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) { + actual constructor() : this(null, null) + actual constructor(message: String?) : this(message, null) + actual constructor(cause: Throwable?) : this(undefined, cause) +} + + +public actual open class NumberFormatException actual constructor(message: String?) : IllegalArgumentException(message) { + actual constructor() : this(null) +} + + +public actual open class NullPointerException actual constructor(message: String?) : RuntimeException(message) { + actual constructor() : this(null) +} + +public actual open class ClassCastException actual constructor(message: String?) : RuntimeException(message) { + actual constructor() : this(null) +} + +public actual open class AssertionError private constructor(message: String?, cause: Throwable?) : Error(message, cause) { + actual constructor() : this(null) constructor(message: String?) : this(message, null) - constructor(cause: Throwable?) : this(undefined, cause) + actual constructor(message: Any?) : this(message.toString(), message as? Throwable) } -public open class IllegalArgumentException(message: String?, cause: Throwable?) : RuntimeException(message, cause) { - constructor() : this(null, null) - constructor(message: String?) : this(message, null) - constructor(cause: Throwable?) : this(undefined, cause) -} - -public open class IllegalStateException(message: String?, cause: Throwable?) : RuntimeException(message, cause) { - constructor() : this(null, null) - constructor(message: String?) : this(message, null) - constructor(cause: Throwable?) : this(undefined, cause) -} - -public open class IndexOutOfBoundsException(message: String?) : RuntimeException(message) { - constructor() : this(null) -} - -public open class ConcurrentModificationException(message: String?, cause: Throwable?) : RuntimeException(message, cause) { - constructor() : this(null, null) - constructor(message: String?) : this(message, null) - constructor(cause: Throwable?) : this(undefined, cause) -} - -public open class UnsupportedOperationException(message: String?, cause: Throwable?) : RuntimeException(message, cause) { - constructor() : this(null, null) - constructor(message: String?) : this(message, null) - constructor(cause: Throwable?) : this(undefined, cause) +public actual open class NoSuchElementException actual constructor(message: String?) : RuntimeException(message) { + actual constructor() : this(null) } -public open class NumberFormatException(message: String?) : IllegalArgumentException(message) { - constructor() : this(null) +public actual open class NoWhenBranchMatchedException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) { + actual constructor() : this(null, null) + actual constructor(message: String?) : this(message, null) + actual constructor(cause: Throwable?) : this(undefined, cause) } - -public open class NullPointerException(message: String?) : RuntimeException(message) { - constructor() : this(null) -} - -public open class ClassCastException(message: String?) : RuntimeException(message) { - constructor() : this(null) -} - -public open class AssertionError private constructor(message: String?, cause: Throwable?) : Error(message, cause) { - constructor() : this(null) - constructor(message: String?) : this(message, null) - constructor(message: Any?) : this(message.toString(), message as? Throwable) -} - -public open class NoSuchElementException(message: String?) : RuntimeException(message) { - constructor() : this(null) -} - - -public open class NoWhenBranchMatchedException(message: String?, cause: Throwable?) : RuntimeException(message, cause) { - constructor() : this(null, null) - constructor(message: String?) : this(message, null) - constructor(cause: Throwable?) : this(undefined, cause) -} - -public open class UninitializedPropertyAccessException(message: String?, cause: Throwable?) : RuntimeException(message, cause) { - constructor() : this(null, null) - constructor(message: String?) : this(message, null) - constructor(cause: Throwable?) : this(undefined, cause) +public actual open class UninitializedPropertyAccessException actual constructor(message: String?, cause: Throwable?) : RuntimeException(message, cause) { + actual constructor() : this(null, null) + actual constructor(message: String?) : this(message, null) + actual constructor(cause: Throwable?) : this(undefined, cause) } diff --git a/libraries/stdlib/js/src/kotlin/grouping.kt b/libraries/stdlib/js/src/kotlin/grouping.kt index c5feb7a92a2..fd3500516f5 100644 --- a/libraries/stdlib/js/src/kotlin/grouping.kt +++ b/libraries/stdlib/js/src/kotlin/grouping.kt @@ -21,7 +21,7 @@ package kotlin.collections * @return a [Map] associating the key of each group with the count of element in the group. */ @SinceKotlin("1.1") -public fun Grouping.eachCount(): Map = +public actual fun Grouping.eachCount(): Map = fold(0) { acc, _ -> acc + 1 } /** diff --git a/libraries/stdlib/js/src/kotlin/io.kt b/libraries/stdlib/js/src/kotlin/io.kt index 08c45880132..512a7175935 100644 --- a/libraries/stdlib/js/src/kotlin/io.kt +++ b/libraries/stdlib/js/src/kotlin/io.kt @@ -17,4 +17,4 @@ package kotlin.io // temporary for shared code, until we have an annotation like JvmSerializable -internal interface Serializable \ No newline at end of file +internal actual interface Serializable \ No newline at end of file diff --git a/libraries/stdlib/js/src/kotlin/kotlin.kt b/libraries/stdlib/js/src/kotlin/kotlin.kt index 2df112b81f7..f3343837a87 100644 --- a/libraries/stdlib/js/src/kotlin/kotlin.kt +++ b/libraries/stdlib/js/src/kotlin/kotlin.kt @@ -53,20 +53,20 @@ public fun booleanArrayOf(vararg elements: Boolean): BooleanArray = definedExter /** * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer]. */ -public fun lazy(initializer: () -> T): Lazy = UnsafeLazyImpl(initializer) +public actual fun lazy(initializer: () -> T): Lazy = UnsafeLazyImpl(initializer) /** * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer]. * * The [mode] parameter is ignored. */ -public fun lazy(mode: LazyThreadSafetyMode, initializer: () -> T): Lazy = UnsafeLazyImpl(initializer) +public actual fun lazy(mode: LazyThreadSafetyMode, initializer: () -> T): Lazy = UnsafeLazyImpl(initializer) /** * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer]. * * The [lock] parameter is ignored. */ -public fun lazy(lock: Any?, initializer: () -> T): Lazy = UnsafeLazyImpl(initializer) +public actual fun lazy(lock: Any?, initializer: () -> T): Lazy = UnsafeLazyImpl(initializer) internal fun fillFrom(src: dynamic, dst: dynamic): dynamic { diff --git a/libraries/stdlib/js/src/kotlin/math.kt b/libraries/stdlib/js/src/kotlin/math.kt index 5a4caa6213b..d03b9f1b85d 100644 --- a/libraries/stdlib/js/src/kotlin/math.kt +++ b/libraries/stdlib/js/src/kotlin/math.kt @@ -20,14 +20,6 @@ package kotlin.math import kotlin.internal.InlineOnly import kotlin.js.Math as nativeMath -// constants, can't use them from nativeMath as they are not constants there - -/** Ratio of the circumference of a circle to its diameter, approximately 3.14159. */ -@SinceKotlin("1.2") -public const val PI: Double = 3.141592653589793 -/** Base of the natural logarithms, approximately 2.71828. */ -@SinceKotlin("1.2") -public const val E: Double = 2.718281828459045 // ================ Double Math ======================================== @@ -38,7 +30,7 @@ public const val E: Double = 2.718281828459045 */ @SinceKotlin("1.2") @InlineOnly -public inline fun sin(x: Double): Double = nativeMath.sin(x) +public actual inline fun sin(x: Double): Double = nativeMath.sin(x) /** Computes the cosine of the angle [x] given in radians. * @@ -47,7 +39,7 @@ public inline fun sin(x: Double): Double = nativeMath.sin(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun cos(x: Double): Double = nativeMath.cos(x) +public actual inline fun cos(x: Double): Double = nativeMath.cos(x) /** Computes the tangent of the angle [x] given in radians. * @@ -56,7 +48,7 @@ public inline fun cos(x: Double): Double = nativeMath.cos(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun tan(x: Double): Double = nativeMath.tan(x) +public actual inline fun tan(x: Double): Double = nativeMath.tan(x) /** * Computes the arc sine of the value [x]; @@ -67,7 +59,7 @@ public inline fun tan(x: Double): Double = nativeMath.tan(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun asin(x: Double): Double = nativeMath.asin(x) +public actual inline fun asin(x: Double): Double = nativeMath.asin(x) /** * Computes the arc cosine of the value [x]; @@ -78,7 +70,7 @@ public inline fun asin(x: Double): Double = nativeMath.asin(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun acos(x: Double): Double = nativeMath.acos(x) +public actual inline fun acos(x: Double): Double = nativeMath.acos(x) /** * Computes the arc tangent of the value [x]; @@ -89,7 +81,7 @@ public inline fun acos(x: Double): Double = nativeMath.acos(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun atan(x: Double): Double = nativeMath.atan(x) +public actual inline fun atan(x: Double): Double = nativeMath.atan(x) /** * Returns the angle `theta` of the polar coordinates `(r, theta)` that correspond @@ -109,7 +101,7 @@ public inline fun atan(x: Double): Double = nativeMath.atan(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun atan2(y: Double, x: Double): Double = nativeMath.atan2(y, x) +public actual inline fun atan2(y: Double, x: Double): Double = nativeMath.atan2(y, x) /** * Computes the hyperbolic sine of the value [x]. @@ -121,7 +113,7 @@ public inline fun atan2(y: Double, x: Double): Double = nativeMath.atan2(y, x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun sinh(x: Double): Double = nativeMath.sinh(x) +public actual inline fun sinh(x: Double): Double = nativeMath.sinh(x) /** * Computes the hyperbolic cosine of the value [x]. @@ -132,7 +124,7 @@ public inline fun sinh(x: Double): Double = nativeMath.sinh(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun cosh(x: Double): Double = nativeMath.cosh(x) +public actual inline fun cosh(x: Double): Double = nativeMath.cosh(x) /** * Computes the hyperbolic tangent of the value [x]. @@ -144,7 +136,7 @@ public inline fun cosh(x: Double): Double = nativeMath.cosh(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun tanh(x: Double): Double = nativeMath.tanh(x) +public actual inline fun tanh(x: Double): Double = nativeMath.tanh(x) /** * Computes the inverse hyperbolic sine of the value [x]. @@ -158,7 +150,7 @@ public inline fun tanh(x: Double): Double = nativeMath.tanh(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun asinh(x: Double): Double = nativeMath.asinh(x) +public actual inline fun asinh(x: Double): Double = nativeMath.asinh(x) /** * Computes the inverse hyperbolic cosine of the value [x]. @@ -172,7 +164,7 @@ public inline fun asinh(x: Double): Double = nativeMath.asinh(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun acosh(x: Double): Double = nativeMath.acosh(x) +public actual inline fun acosh(x: Double): Double = nativeMath.acosh(x) /** * Computes the inverse hyperbolic tangent of the value [x]. @@ -187,7 +179,7 @@ public inline fun acosh(x: Double): Double = nativeMath.acosh(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun atanh(x: Double): Double = nativeMath.atanh(x) +public actual inline fun atanh(x: Double): Double = nativeMath.atanh(x) /** * Computes `sqrt(x^2 + y^2)` without intermediate overflow or underflow. @@ -198,7 +190,7 @@ public inline fun atanh(x: Double): Double = nativeMath.atanh(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun hypot(x: Double, y: Double): Double = nativeMath.hypot(x, y) +public actual inline fun hypot(x: Double, y: Double): Double = nativeMath.hypot(x, y) /** * Computes the positive square root of the value [x]. @@ -208,7 +200,7 @@ public inline fun hypot(x: Double, y: Double): Double = nativeMath.hypot(x, y) */ @SinceKotlin("1.2") @InlineOnly -public inline fun sqrt(x: Double): Double = nativeMath.sqrt(x) +public actual inline fun sqrt(x: Double): Double = nativeMath.sqrt(x) /** * Computes Euler's number `e` raised to the power of the value [x]. @@ -220,7 +212,7 @@ public inline fun sqrt(x: Double): Double = nativeMath.sqrt(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun exp(x: Double): Double = nativeMath.exp(x) +public actual inline fun exp(x: Double): Double = nativeMath.exp(x) /** * Computes `exp(x) - 1`. @@ -236,7 +228,7 @@ public inline fun exp(x: Double): Double = nativeMath.exp(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun expm1(x: Double): Double = nativeMath.expm1(x) +public actual inline fun expm1(x: Double): Double = nativeMath.expm1(x) /** * Computes the logarithm of the value [x] to the given [base]. @@ -251,7 +243,7 @@ public inline fun expm1(x: Double): Double = nativeMath.expm1(x) * See also logarithm functions for common fixed bases: [ln], [log10] and [log2]. */ @SinceKotlin("1.2") -public fun log(x: Double, base: Double): Double { +public actual fun log(x: Double, base: Double): Double { if (base <= 0.0 || base == 1.0) return Double.NaN return nativeMath.log(x) / nativeMath.log(base) } @@ -267,7 +259,7 @@ public fun log(x: Double, base: Double): Double { */ @SinceKotlin("1.2") @InlineOnly -public inline fun ln(x: Double): Double = nativeMath.log(x) +public actual inline fun ln(x: Double): Double = nativeMath.log(x) /** * Computes the common logarithm (base 10) of the value [x]. @@ -276,7 +268,7 @@ public inline fun ln(x: Double): Double = nativeMath.log(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun log10(x: Double): Double = nativeMath.log10(x) +public actual inline fun log10(x: Double): Double = nativeMath.log10(x) /** * Computes the binary logarithm (base 2) of the value [x]. @@ -285,7 +277,7 @@ public inline fun log10(x: Double): Double = nativeMath.log10(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun log2(x: Double): Double = nativeMath.log2(x) +public actual inline fun log2(x: Double): Double = nativeMath.log2(x) /** * Computes `ln(x + 1)`. @@ -303,7 +295,7 @@ public inline fun log2(x: Double): Double = nativeMath.log2(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun ln1p(x: Double): Double = nativeMath.log1p(x) +public actual inline fun ln1p(x: Double): Double = nativeMath.log1p(x) /** * Rounds the given value [x] to an integer towards positive infinity. @@ -315,7 +307,7 @@ public inline fun ln1p(x: Double): Double = nativeMath.log1p(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun ceil(x: Double): Double = nativeMath.ceil(x).unsafeCast() // TODO: Remove unsafe cast after removing public js.math +public actual inline fun ceil(x: Double): Double = nativeMath.ceil(x).unsafeCast() // TODO: Remove unsafe cast after removing public js.math /** * Rounds the given value [x] to an integer towards negative infinity. @@ -327,7 +319,7 @@ public inline fun ceil(x: Double): Double = nativeMath.ceil(x).unsafeCast() +public actual inline fun floor(x: Double): Double = nativeMath.floor(x).unsafeCast() /** * Rounds the given value [x] to an integer towards zero. @@ -339,7 +331,7 @@ public inline fun floor(x: Double): Double = nativeMath.floor(x).unsafeCast() } @@ -366,7 +358,7 @@ public fun round(x: Double): Double { */ @SinceKotlin("1.2") @InlineOnly -public inline fun abs(x: Double): Double = nativeMath.abs(x) +public actual inline fun abs(x: Double): Double = nativeMath.abs(x) /** * Returns the sign of the given value [x]: @@ -379,7 +371,7 @@ public inline fun abs(x: Double): Double = nativeMath.abs(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun sign(x: Double): Double = nativeMath.sign(x) +public actual inline fun sign(x: Double): Double = nativeMath.sign(x) /** @@ -389,7 +381,7 @@ public inline fun sign(x: Double): Double = nativeMath.sign(x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun min(a: Double, b: Double): Double = nativeMath.min(a, b) +public actual inline fun min(a: Double, b: Double): Double = nativeMath.min(a, b) /** * Returns the greater of two values. * @@ -397,7 +389,7 @@ public inline fun min(a: Double, b: Double): Double = nativeMath.min(a, b) */ @SinceKotlin("1.2") @InlineOnly -public inline fun max(a: Double, b: Double): Double = nativeMath.max(a, b) +public actual inline fun max(a: Double, b: Double): Double = nativeMath.max(a, b) // extensions @@ -414,7 +406,7 @@ public inline fun max(a: Double, b: Double): Double = nativeMath.max(a, b) */ @SinceKotlin("1.2") @InlineOnly -public inline fun Double.pow(x: Double): Double = nativeMath.pow(this, x) +public actual inline fun Double.pow(x: Double): Double = nativeMath.pow(this, x) /** * Raises this value to the integer power [n]. @@ -423,7 +415,7 @@ public inline fun Double.pow(x: Double): Double = nativeMath.pow(this, x) */ @SinceKotlin("1.2") @InlineOnly -public inline fun Double.pow(n: Int): Double = nativeMath.pow(this, n.toDouble()) +public actual inline fun Double.pow(n: Int): Double = nativeMath.pow(this, n.toDouble()) /** * Returns the absolute value of this value. @@ -435,7 +427,7 @@ public inline fun Double.pow(n: Int): Double = nativeMath.pow(this, n.toDouble() */ @SinceKotlin("1.2") @InlineOnly -public inline val Double.absoluteValue: Double get() = nativeMath.abs(this) +public actual inline val Double.absoluteValue: Double get() = nativeMath.abs(this) /** * Returns the sign of this value: @@ -448,7 +440,7 @@ public inline val Double.absoluteValue: Double get() = nativeMath.abs(this) */ @SinceKotlin("1.2") @InlineOnly -public inline val Double.sign: Double get() = nativeMath.sign(this) +public actual inline val Double.sign: Double get() = nativeMath.sign(this) /** * Returns this value with the sign bit same as of the [sign] value. @@ -456,7 +448,7 @@ public inline val Double.sign: Double get() = nativeMath.sign(this) * If [sign] is `NaN` the sign of the result is undefined. */ @SinceKotlin("1.2") -public fun Double.withSign(sign: Double): Double { +public actual fun Double.withSign(sign: Double): Double { val thisSignBit = js("Kotlin").doubleSignBit(this).unsafeCast() val newSignBit = js("Kotlin").doubleSignBit(sign).unsafeCast() return if (thisSignBit == newSignBit) this else -this @@ -467,7 +459,7 @@ public fun Double.withSign(sign: Double): Double { */ @SinceKotlin("1.2") @InlineOnly -public inline fun Double.withSign(sign: Int): Double = this.withSign(sign.toDouble()) +public actual inline fun Double.withSign(sign: Int): Double = this.withSign(sign.toDouble()) /** * Returns the ulp (unit in the last place) of this value. @@ -480,7 +472,7 @@ public inline fun Double.withSign(sign: Int): Double = this.withSign(sign.toDoub * - `0.0.ulp` is `Double.MIN_VALUE` */ @SinceKotlin("1.2") -public val Double.ulp: Double get() = when { +public actual val Double.ulp: Double get() = when { this < 0 -> (-this).ulp this.isNaN() || this == Double.POSITIVE_INFINITY -> this this == Double.MAX_VALUE -> this - this.nextDown() @@ -491,7 +483,7 @@ public val Double.ulp: Double get() = when { * Returns the [Double] value nearest to this value in direction of positive infinity. */ @SinceKotlin("1.2") -public fun Double.nextUp(): Double = when { +public actual fun Double.nextUp(): Double = when { this.isNaN() || this == Double.POSITIVE_INFINITY -> this this == 0.0 -> Double.MIN_VALUE else -> Double.fromBits(this.toRawBits() + if (this > 0) 1 else -1) @@ -501,7 +493,7 @@ public fun Double.nextUp(): Double = when { * Returns the [Double] value nearest to this value in direction of negative infinity. */ @SinceKotlin("1.2") -public fun Double.nextDown(): Double = when { +public actual fun Double.nextDown(): Double = when { this.isNaN() || this == Double.NEGATIVE_INFINITY -> this this == 0.0 -> -Double.MIN_VALUE else -> Double.fromBits(this.toRawBits() + if (this > 0) -1 else 1) @@ -517,7 +509,7 @@ public fun Double.nextDown(): Double = when { * */ @SinceKotlin("1.2") -public fun Double.nextTowards(to: Double): Double = when { +public actual fun Double.nextTowards(to: Double): Double = when { this.isNaN() || to.isNaN() -> Double.NaN to == this -> to to > this -> this.nextUp() @@ -536,7 +528,7 @@ public fun Double.nextTowards(to: Double): Double = when { * @throws IllegalArgumentException when this value is `NaN` */ @SinceKotlin("1.2") -public fun Double.roundToInt(): Int = when { +public actual fun Double.roundToInt(): Int = when { isNaN() -> throw IllegalArgumentException("Cannot round NaN value.") this > Int.MAX_VALUE -> Int.MAX_VALUE this < Int.MIN_VALUE -> Int.MIN_VALUE @@ -554,7 +546,7 @@ public fun Double.roundToInt(): Int = when { * @throws IllegalArgumentException when this value is `NaN` */ @SinceKotlin("1.2") -public fun Double.roundToLong(): Long = when { +public actual fun Double.roundToLong(): Long = when { isNaN() -> throw IllegalArgumentException("Cannot round NaN value.") this > Long.MAX_VALUE -> Long.MAX_VALUE this < Long.MIN_VALUE -> Long.MIN_VALUE @@ -573,7 +565,7 @@ public fun Double.roundToLong(): Long = when { */ @SinceKotlin("1.2") @InlineOnly -public inline fun sin(x: Float): Float = nativeMath.sin(x.toDouble()).toFloat() +public actual inline fun sin(x: Float): Float = nativeMath.sin(x.toDouble()).toFloat() /** Computes the cosine of the angle [x] given in radians. * @@ -582,7 +574,7 @@ public inline fun sin(x: Float): Float = nativeMath.sin(x.toDouble()).toFloat() */ @SinceKotlin("1.2") @InlineOnly -public inline fun cos(x: Float): Float = nativeMath.cos(x.toDouble()).toFloat() +public actual inline fun cos(x: Float): Float = nativeMath.cos(x.toDouble()).toFloat() /** Computes the tangent of the angle [x] given in radians. * @@ -591,7 +583,7 @@ public inline fun cos(x: Float): Float = nativeMath.cos(x.toDouble()).toFloat() */ @SinceKotlin("1.2") @InlineOnly -public inline fun tan(x: Float): Float = nativeMath.tan(x.toDouble()).toFloat() +public actual inline fun tan(x: Float): Float = nativeMath.tan(x.toDouble()).toFloat() /** * Computes the arc sine of the value [x]; @@ -602,7 +594,7 @@ public inline fun tan(x: Float): Float = nativeMath.tan(x.toDouble()).toFloat() */ @SinceKotlin("1.2") @InlineOnly -public inline fun asin(x: Float): Float = nativeMath.asin(x.toDouble()).toFloat() +public actual inline fun asin(x: Float): Float = nativeMath.asin(x.toDouble()).toFloat() /** * Computes the arc cosine of the value [x]; @@ -613,7 +605,7 @@ public inline fun asin(x: Float): Float = nativeMath.asin(x.toDouble()).toFloat( */ @SinceKotlin("1.2") @InlineOnly -public inline fun acos(x: Float): Float = nativeMath.acos(x.toDouble()).toFloat() +public actual inline fun acos(x: Float): Float = nativeMath.acos(x.toDouble()).toFloat() /** * Computes the arc tangent of the value [x]; @@ -624,7 +616,7 @@ public inline fun acos(x: Float): Float = nativeMath.acos(x.toDouble()).toFloat( */ @SinceKotlin("1.2") @InlineOnly -public inline fun atan(x: Float): Float = nativeMath.atan(x.toDouble()).toFloat() +public actual inline fun atan(x: Float): Float = nativeMath.atan(x.toDouble()).toFloat() /** * Returns the angle `theta` of the polar coordinates `(r, theta)` that correspond @@ -644,7 +636,7 @@ public inline fun atan(x: Float): Float = nativeMath.atan(x.toDouble()).toFloat( */ @SinceKotlin("1.2") @InlineOnly -public inline fun atan2(y: Float, x: Float): Float = nativeMath.atan2(y.toDouble(), x.toDouble()).toFloat() +public actual inline fun atan2(y: Float, x: Float): Float = nativeMath.atan2(y.toDouble(), x.toDouble()).toFloat() /** * Computes the hyperbolic sine of the value [x]. @@ -656,7 +648,7 @@ public inline fun atan2(y: Float, x: Float): Float = nativeMath.atan2(y.toDouble */ @SinceKotlin("1.2") @InlineOnly -public inline fun sinh(x: Float): Float = nativeMath.sinh(x.toDouble()).toFloat() +public actual inline fun sinh(x: Float): Float = nativeMath.sinh(x.toDouble()).toFloat() /** * Computes the hyperbolic cosine of the value [x]. @@ -667,7 +659,7 @@ public inline fun sinh(x: Float): Float = nativeMath.sinh(x.toDouble()).toFloat( */ @SinceKotlin("1.2") @InlineOnly -public inline fun cosh(x: Float): Float = nativeMath.cosh(x.toDouble()).toFloat() +public actual inline fun cosh(x: Float): Float = nativeMath.cosh(x.toDouble()).toFloat() /** * Computes the hyperbolic tangent of the value [x]. @@ -679,7 +671,7 @@ public inline fun cosh(x: Float): Float = nativeMath.cosh(x.toDouble()).toFloat( */ @SinceKotlin("1.2") @InlineOnly -public inline fun tanh(x: Float): Float = nativeMath.tanh(x.toDouble()).toFloat() +public actual inline fun tanh(x: Float): Float = nativeMath.tanh(x.toDouble()).toFloat() /** * Computes the inverse hyperbolic sine of the value [x]. @@ -693,7 +685,7 @@ public inline fun tanh(x: Float): Float = nativeMath.tanh(x.toDouble()).toFloat( */ @SinceKotlin("1.2") @InlineOnly -public inline fun asinh(x: Float): Float = nativeMath.asinh(x.toDouble()).toFloat() +public actual inline fun asinh(x: Float): Float = nativeMath.asinh(x.toDouble()).toFloat() /** * Computes the inverse hyperbolic cosine of the value [x]. @@ -707,7 +699,7 @@ public inline fun asinh(x: Float): Float = nativeMath.asinh(x.toDouble()).toFloa */ @SinceKotlin("1.2") @InlineOnly -public inline fun acosh(x: Float): Float = nativeMath.acosh(x.toDouble()).toFloat() +public actual inline fun acosh(x: Float): Float = nativeMath.acosh(x.toDouble()).toFloat() /** * Computes the inverse hyperbolic tangent of the value [x]. @@ -722,7 +714,7 @@ public inline fun acosh(x: Float): Float = nativeMath.acosh(x.toDouble()).toFloa */ @SinceKotlin("1.2") @InlineOnly -public inline fun atanh(x: Float): Float = nativeMath.atanh(x.toDouble()).toFloat() +public actual inline fun atanh(x: Float): Float = nativeMath.atanh(x.toDouble()).toFloat() /** * Computes `sqrt(x^2 + y^2)` without intermediate overflow or underflow. @@ -733,7 +725,7 @@ public inline fun atanh(x: Float): Float = nativeMath.atanh(x.toDouble()).toFloa */ @SinceKotlin("1.2") @InlineOnly -public inline fun hypot(x: Float, y: Float): Float = nativeMath.hypot(x.toDouble(), y.toDouble()).toFloat() +public actual inline fun hypot(x: Float, y: Float): Float = nativeMath.hypot(x.toDouble(), y.toDouble()).toFloat() /** * Computes the positive square root of the value [x]. @@ -743,7 +735,7 @@ public inline fun hypot(x: Float, y: Float): Float = nativeMath.hypot(x.toDouble */ @SinceKotlin("1.2") @InlineOnly -public inline fun sqrt(x: Float): Float = nativeMath.sqrt(x.toDouble()).toFloat() +public actual inline fun sqrt(x: Float): Float = nativeMath.sqrt(x.toDouble()).toFloat() /** * Computes Euler's number `e` raised to the power of the value [x]. @@ -755,7 +747,7 @@ public inline fun sqrt(x: Float): Float = nativeMath.sqrt(x.toDouble()).toFloat( */ @SinceKotlin("1.2") @InlineOnly -public inline fun exp(x: Float): Float = nativeMath.exp(x.toDouble()).toFloat() +public actual inline fun exp(x: Float): Float = nativeMath.exp(x.toDouble()).toFloat() /** * Computes `exp(x) - 1`. @@ -771,7 +763,7 @@ public inline fun exp(x: Float): Float = nativeMath.exp(x.toDouble()).toFloat() */ @SinceKotlin("1.2") @InlineOnly -public inline fun expm1(x: Float): Float = nativeMath.expm1(x.toDouble()).toFloat() +public actual inline fun expm1(x: Float): Float = nativeMath.expm1(x.toDouble()).toFloat() /** * Computes the logarithm of the value [x] to the given [base]. @@ -787,7 +779,7 @@ public inline fun expm1(x: Float): Float = nativeMath.expm1(x.toDouble()).toFloa */ @SinceKotlin("1.2") @InlineOnly -public inline fun log(x: Float, base: Float): Float = log(x.toDouble(), base.toDouble()).toFloat() +public actual inline fun log(x: Float, base: Float): Float = log(x.toDouble(), base.toDouble()).toFloat() /** * Computes the natural logarithm (base `E`) of the value [x]. @@ -800,7 +792,7 @@ public inline fun log(x: Float, base: Float): Float = log(x.toDouble(), base.toD */ @SinceKotlin("1.2") @InlineOnly -public inline fun ln(x: Float): Float = nativeMath.log(x.toDouble()).toFloat() +public actual inline fun ln(x: Float): Float = nativeMath.log(x.toDouble()).toFloat() /** * Computes the common logarithm (base 10) of the value [x]. @@ -809,7 +801,7 @@ public inline fun ln(x: Float): Float = nativeMath.log(x.toDouble()).toFloat() */ @SinceKotlin("1.2") @InlineOnly -public inline fun log10(x: Float): Float = nativeMath.log10(x.toDouble()).toFloat() +public actual inline fun log10(x: Float): Float = nativeMath.log10(x.toDouble()).toFloat() /** * Computes the binary logarithm (base 2) of the value [x]. @@ -818,7 +810,7 @@ public inline fun log10(x: Float): Float = nativeMath.log10(x.toDouble()).toFloa */ @SinceKotlin("1.2") @InlineOnly -public inline fun log2(x: Float): Float = nativeMath.log2(x.toDouble()).toFloat() +public actual inline fun log2(x: Float): Float = nativeMath.log2(x.toDouble()).toFloat() /** * Computes `ln(a + 1)`. @@ -836,7 +828,7 @@ public inline fun log2(x: Float): Float = nativeMath.log2(x.toDouble()).toFloat( */ @SinceKotlin("1.2") @InlineOnly -public inline fun ln1p(x: Float): Float = nativeMath.log1p(x.toDouble()).toFloat() +public actual inline fun ln1p(x: Float): Float = nativeMath.log1p(x.toDouble()).toFloat() /** * Rounds the given value [x] to an integer towards positive infinity. @@ -848,7 +840,7 @@ public inline fun ln1p(x: Float): Float = nativeMath.log1p(x.toDouble()).toFloat */ @SinceKotlin("1.2") @InlineOnly -public inline fun ceil(x: Float): Float = nativeMath.ceil(x.toDouble()).toFloat() +public actual inline fun ceil(x: Float): Float = nativeMath.ceil(x.toDouble()).toFloat() /** * Rounds the given value [x] to an integer towards negative infinity. @@ -860,7 +852,7 @@ public inline fun ceil(x: Float): Float = nativeMath.ceil(x.toDouble()).toFloat( */ @SinceKotlin("1.2") @InlineOnly -public inline fun floor(x: Float): Float = nativeMath.floor(x.toDouble()).toFloat() +public actual inline fun floor(x: Float): Float = nativeMath.floor(x.toDouble()).toFloat() /** * Rounds the given value [x] to an integer towards zero. @@ -872,7 +864,7 @@ public inline fun floor(x: Float): Float = nativeMath.floor(x.toDouble()).toFloa */ @SinceKotlin("1.2") @InlineOnly -public inline fun truncate(x: Float): Float = truncate(x.toDouble()).toFloat() +public actual inline fun truncate(x: Float): Float = truncate(x.toDouble()).toFloat() /** * Rounds the given value [x] towards the closest integer with ties rounded towards even integer. @@ -882,7 +874,7 @@ public inline fun truncate(x: Float): Float = truncate(x.toDouble()).toFloat() */ @SinceKotlin("1.2") @InlineOnly -public inline fun round(x: Float): Float = round(x.toDouble()).toFloat() +public actual inline fun round(x: Float): Float = round(x.toDouble()).toFloat() /** @@ -895,7 +887,7 @@ public inline fun round(x: Float): Float = round(x.toDouble()).toFloat() */ @SinceKotlin("1.2") @InlineOnly -public inline fun abs(x: Float): Float = nativeMath.abs(x.toDouble()).toFloat() +public actual inline fun abs(x: Float): Float = nativeMath.abs(x.toDouble()).toFloat() /** * Returns the sign of the given value [x]: @@ -908,7 +900,7 @@ public inline fun abs(x: Float): Float = nativeMath.abs(x.toDouble()).toFloat() */ @SinceKotlin("1.2") @InlineOnly -public inline fun sign(x: Float): Float = nativeMath.sign(x.toDouble()).toFloat() +public actual inline fun sign(x: Float): Float = nativeMath.sign(x.toDouble()).toFloat() @@ -919,7 +911,7 @@ public inline fun sign(x: Float): Float = nativeMath.sign(x.toDouble()).toFloat( */ @SinceKotlin("1.2") @InlineOnly -public inline fun min(a: Float, b: Float): Float = nativeMath.min(a, b) +public actual inline fun min(a: Float, b: Float): Float = nativeMath.min(a, b) /** * Returns the greater of two values. * @@ -927,7 +919,7 @@ public inline fun min(a: Float, b: Float): Float = nativeMath.min(a, b) */ @SinceKotlin("1.2") @InlineOnly -public inline fun max(a: Float, b: Float): Float = nativeMath.max(a, b) +public actual inline fun max(a: Float, b: Float): Float = nativeMath.max(a, b) // extensions @@ -945,7 +937,7 @@ public inline fun max(a: Float, b: Float): Float = nativeMath.max(a, b) */ @SinceKotlin("1.2") @InlineOnly -public inline fun Float.pow(x: Float): Float = nativeMath.pow(this.toDouble(), x.toDouble()).toFloat() +public actual inline fun Float.pow(x: Float): Float = nativeMath.pow(this.toDouble(), x.toDouble()).toFloat() /** * Raises this value to the integer power [n]. @@ -954,7 +946,7 @@ public inline fun Float.pow(x: Float): Float = nativeMath.pow(this.toDouble(), x */ @SinceKotlin("1.2") @InlineOnly -public inline fun Float.pow(n: Int): Float = nativeMath.pow(this.toDouble(), n.toDouble()).toFloat() +public actual inline fun Float.pow(n: Int): Float = nativeMath.pow(this.toDouble(), n.toDouble()).toFloat() /** * Returns the absolute value of this value. @@ -966,7 +958,7 @@ public inline fun Float.pow(n: Int): Float = nativeMath.pow(this.toDouble(), n.t */ @SinceKotlin("1.2") @InlineOnly -public inline val Float.absoluteValue: Float get() = nativeMath.abs(this.toDouble()).toFloat() +public actual inline val Float.absoluteValue: Float get() = nativeMath.abs(this.toDouble()).toFloat() /** * Returns the sign of this value: @@ -979,7 +971,7 @@ public inline val Float.absoluteValue: Float get() = nativeMath.abs(this.toDoubl */ @SinceKotlin("1.2") @InlineOnly -public inline val Float.sign: Float get() = nativeMath.sign(this.toDouble()).toFloat() +public actual inline val Float.sign: Float get() = nativeMath.sign(this.toDouble()).toFloat() /** * Returns this value with the sign bit same as of the [sign] value. @@ -988,13 +980,13 @@ public inline val Float.sign: Float get() = nativeMath.sign(this.toDouble()).toF */ @SinceKotlin("1.2") @InlineOnly -public inline fun Float.withSign(sign: Float): Float = this.toDouble().withSign(sign.toDouble()).toFloat() +public actual inline fun Float.withSign(sign: Float): Float = this.toDouble().withSign(sign.toDouble()).toFloat() /** * Returns this value with the sign bit same as of the [sign] value. */ @SinceKotlin("1.2") @InlineOnly -public inline fun Float.withSign(sign: Int): Float = this.toDouble().withSign(sign.toDouble()).toFloat() +public actual inline fun Float.withSign(sign: Int): Float = this.toDouble().withSign(sign.toDouble()).toFloat() /** @@ -1009,7 +1001,7 @@ public inline fun Float.withSign(sign: Int): Float = this.toDouble().withSign(si */ @SinceKotlin("1.2") @InlineOnly -public inline fun Float.roundToInt(): Int = toDouble().roundToInt() +public actual inline fun Float.roundToInt(): Int = toDouble().roundToInt() /** * Rounds this [Float] value to the nearest integer and converts the result to [Long]. @@ -1023,7 +1015,7 @@ public inline fun Float.roundToInt(): Int = toDouble().roundToInt() */ @SinceKotlin("1.2") @InlineOnly -public inline fun Float.roundToLong(): Long = toDouble().roundToLong() +public actual inline fun Float.roundToLong(): Long = toDouble().roundToLong() @@ -1038,21 +1030,21 @@ public inline fun Float.roundToLong(): Long = toDouble().roundToLong() */ // TODO: remove manual 'or' when KT-19290 is fixed @SinceKotlin("1.2") -public fun abs(n: Int): Int = if (n < 0) (-n or 0) else n +public actual fun abs(n: Int): Int = if (n < 0) (-n or 0) else n /** * Returns the smaller of two values. */ @SinceKotlin("1.2") @InlineOnly -public inline fun min(a: Int, b: Int): Int = nativeMath.min(a, b) +public actual inline fun min(a: Int, b: Int): Int = nativeMath.min(a, b) /** * Returns the greater of two values. */ @SinceKotlin("1.2") @InlineOnly -public inline fun max(a: Int, b: Int): Int = nativeMath.max(a, b) +public actual inline fun max(a: Int, b: Int): Int = nativeMath.max(a, b) /** * Returns the absolute value of this value. @@ -1064,7 +1056,7 @@ public inline fun max(a: Int, b: Int): Int = nativeMath.max(a, b) */ @SinceKotlin("1.2") @InlineOnly -public inline val Int.absoluteValue: Int get() = abs(this) +public actual inline val Int.absoluteValue: Int get() = abs(this) /** * Returns the sign of this value: @@ -1073,7 +1065,7 @@ public inline val Int.absoluteValue: Int get() = abs(this) * - `1` if the value is positive */ @SinceKotlin("1.2") -public val Int.sign: Int get() = when { +public actual val Int.sign: Int get() = when { this < 0 -> -1 this > 0 -> 1 else -> 0 @@ -1090,21 +1082,21 @@ public val Int.sign: Int get() = when { * @see absoluteValue extension property for [Long] */ @SinceKotlin("1.2") -public fun abs(n: Long): Long = if (n < 0) -n else n +public actual fun abs(n: Long): Long = if (n < 0) -n else n /** * Returns the smaller of two values. */ @SinceKotlin("1.2") @Suppress("NOTHING_TO_INLINE") -public inline fun min(a: Long, b: Long): Long = if (a <= b) a else b +public actual inline fun min(a: Long, b: Long): Long = if (a <= b) a else b /** * Returns the greater of two values. */ @SinceKotlin("1.2") @Suppress("NOTHING_TO_INLINE") -public inline fun max(a: Long, b: Long): Long = if (a >= b) a else b +public actual inline fun max(a: Long, b: Long): Long = if (a >= b) a else b /** * Returns the absolute value of this value. @@ -1116,7 +1108,7 @@ public inline fun max(a: Long, b: Long): Long = if (a >= b) a else b */ @SinceKotlin("1.2") @InlineOnly -public inline val Long.absoluteValue: Long get() = abs(this) +public actual inline val Long.absoluteValue: Long get() = abs(this) /** * Returns the sign of this value: @@ -1125,7 +1117,7 @@ public inline val Long.absoluteValue: Long get() = abs(this) * - `1` if the value is positive */ @SinceKotlin("1.2") -public val Long.sign: Int get() = when { +public actual val Long.sign: Int get() = when { this < 0 -> -1 this > 0 -> 1 else -> 0 diff --git a/libraries/stdlib/js/src/kotlin/numberConversions.kt b/libraries/stdlib/js/src/kotlin/numberConversions.kt index 394061268f2..e8ceaf0688f 100644 --- a/libraries/stdlib/js/src/kotlin/numberConversions.kt +++ b/libraries/stdlib/js/src/kotlin/numberConversions.kt @@ -21,66 +21,66 @@ package kotlin.text /** * Returns `true` if the contents of this string is equal to the word "true", ignoring case, and `false` otherwise. */ -public fun String.toBoolean(): Boolean = toLowerCase() == "true" +public actual fun String.toBoolean(): Boolean = toLowerCase() == "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. */ -public 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. * @throws NumberFormatException if the string is not a valid representation of a number. * @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion. */ -public fun String.toByte(radix: Int): Byte = toByteOrNull(radix) ?: numberFormatError(this) +public actual fun String.toByte(radix: Int): Byte = toByteOrNull(radix) ?: numberFormatError(this) /** * Parses the string as a [Short] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number. */ -public fun String.toShort(): Short = toShortOrNull() ?: numberFormatError(this) +public actual fun String.toShort(): Short = toShortOrNull() ?: numberFormatError(this) /** * Parses the string as a [Short] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number. * @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion. */ -public fun String.toShort(radix: Int): Short = toShortOrNull(radix) ?: numberFormatError(this) +public actual fun String.toShort(radix: Int): Short = toShortOrNull(radix) ?: numberFormatError(this) /** * Parses the string as an [Int] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number. */ -public fun String.toInt(): Int = toIntOrNull() ?: numberFormatError(this) +public actual fun String.toInt(): Int = toIntOrNull() ?: numberFormatError(this) /** * Parses the string as an [Int] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number. * @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion. */ -public fun String.toInt(radix: Int): Int = toIntOrNull(radix) ?: numberFormatError(this) +public actual fun String.toInt(radix: Int): Int = toIntOrNull(radix) ?: numberFormatError(this) /** * Parses the string as a [Long] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number. */ -public fun String.toLong(): Long = toLongOrNull() ?: numberFormatError(this) +public actual fun String.toLong(): Long = toLongOrNull() ?: numberFormatError(this) /** * Parses the string as a [Long] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number. * @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion. */ -public fun String.toLong(radix: Int): Long = toLongOrNull(radix) ?: numberFormatError(this) +public actual fun String.toLong(radix: Int): Long = toLongOrNull(radix) ?: numberFormatError(this) /** * Parses the string as a [Double] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number. */ -public fun String.toDouble(): Double = (+(this.asDynamic())).unsafeCast().also { +public actual fun String.toDouble(): Double = (+(this.asDynamic())).unsafeCast().also { if (it.isNaN() && !this.isNaN() || it == 0.0 && this.isBlank()) numberFormatError(this) } @@ -90,13 +90,13 @@ public fun String.toDouble(): Double = (+(this.asDynamic())).unsafeCast( * @throws NumberFormatException if the string is not a valid representation of a number. */ @kotlin.internal.InlineOnly -public inline fun String.toFloat(): Float = toDouble().unsafeCast() +public actual inline fun String.toFloat(): Float = toDouble().unsafeCast() /** * Parses the string as a [Double] number and returns the result * or `null` if the string is not a valid representation of a number. */ -public fun String.toDoubleOrNull(): Double? = (+(this.asDynamic())).unsafeCast().takeIf { +public actual fun String.toDoubleOrNull(): Double? = (+(this.asDynamic())).unsafeCast().takeIf { !(it.isNaN() && !this.isNaN() || it == 0.0 && this.isBlank()) } @@ -105,7 +105,7 @@ public fun String.toDoubleOrNull(): Double? = (+(this.asDynamic())).unsafeCast() +public actual inline fun String.toFloatOrNull(): Float? = toDoubleOrNull().unsafeCast() private fun String.isNaN(): Boolean = when(this.toLowerCase()) { @@ -117,14 +117,14 @@ private fun String.isNaN(): Boolean = when(this.toLowerCase()) { * Checks whether the given [radix] is valid radix for string to number and number to string conversion. */ @PublishedApi -internal fun checkRadix(radix: Int): Int { +internal actual fun checkRadix(radix: Int): Int { if(radix !in 2..36) { throw IllegalArgumentException("radix $radix was not in valid range 2..36") } return radix } -internal fun digitOf(char: Char, radix: Int): Int = when { +internal actual fun digitOf(char: Char, radix: Int): Int = when { char >= '0' && char <= '9' -> char - '0' char >= 'A' && char <= 'Z' -> char - 'A' + 10 char >= 'a' && char <= 'z' -> char - 'a' + 10 diff --git a/libraries/stdlib/js/src/kotlin/numbers.kt b/libraries/stdlib/js/src/kotlin/numbers.kt index bd63af2abbf..6d20e439501 100644 --- a/libraries/stdlib/js/src/kotlin/numbers.kt +++ b/libraries/stdlib/js/src/kotlin/numbers.kt @@ -4,33 +4,33 @@ package kotlin * Returns `true` if the specified number is a * Not-a-Number (NaN) value, `false` otherwise. */ -public 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. */ -public fun Float.isNaN(): Boolean = this != this +public actual fun Float.isNaN(): Boolean = this != this /** * Returns `true` if this value is infinitely large in magnitude. */ -public 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. */ -public 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). */ -public 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). */ -public 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] @@ -38,7 +38,7 @@ public fun Float.isFinite(): Boolean = !isInfinite() && !isNaN() */ @SinceKotlin("1.2") @library("doubleToBits") -public fun Double.toBits(): Long = definedExternally +public actual fun Double.toBits(): Long = definedExternally /** * Returns a bit representation of the specified floating-point value as [Long] @@ -47,14 +47,14 @@ public fun Double.toBits(): Long = definedExternally */ @SinceKotlin("1.2") @library("doubleToRawBits") -public fun Double.toRawBits(): Long = definedExternally +public actual fun Double.toRawBits(): Long = definedExternally /** * Returns the [Double] value corresponding to a given bit representation. */ @SinceKotlin("1.2") @kotlin.internal.InlineOnly -public inline fun Double.Companion.fromBits(bits: Long): Double = js("Kotlin").doubleFromBits(bits).unsafeCast() +public actual inline fun Double.Companion.fromBits(bits: Long): Double = js("Kotlin").doubleFromBits(bits).unsafeCast() /** * Returns a bit representation of the specified floating-point value as [Int] @@ -65,7 +65,7 @@ public inline fun Double.Companion.fromBits(bits: Long): Double = js("Kotlin").d */ @SinceKotlin("1.2") @library("floatToBits") -public fun Float.toBits(): Int = definedExternally +public actual fun Float.toBits(): Int = definedExternally /** * Returns a bit representation of the specified floating-point value as [Int] @@ -77,11 +77,11 @@ public fun Float.toBits(): Int = definedExternally */ @SinceKotlin("1.2") @library("floatToRawBits") -public fun Float.toRawBits(): Int = definedExternally +public actual fun Float.toRawBits(): Int = definedExternally /** * Returns the [Float] value corresponding to a given bit representation. */ @SinceKotlin("1.2") @kotlin.internal.InlineOnly -public inline fun Float.Companion.fromBits(bits: Int): Float = js("Kotlin").floatFromBits(bits).unsafeCast() \ No newline at end of file +public actual inline fun Float.Companion.fromBits(bits: Int): Float = js("Kotlin").floatFromBits(bits).unsafeCast() \ No newline at end of file diff --git a/libraries/stdlib/js/src/kotlin/regex.kt b/libraries/stdlib/js/src/kotlin/regex.kt index f61adcec6cc..8c2f070242d 100644 --- a/libraries/stdlib/js/src/kotlin/regex.kt +++ b/libraries/stdlib/js/src/kotlin/regex.kt @@ -21,7 +21,7 @@ import kotlin.js.RegExp /** * Provides enumeration values to use to set regular expression options. */ -public enum class RegexOption(val value: String) { +public actual enum class RegexOption(val value: String) { /** Enables case-insensitive matching. */ IGNORE_CASE("i"), /** Enables multiline mode. @@ -37,36 +37,36 @@ public enum class RegexOption(val value: String) { * * @param value The value of captured group. */ -public data class MatchGroup(val value: String) +public actual data class MatchGroup(actual val value: String) /** A compiled representation of a regular expression. * * For pattern syntax reference see [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp] and [http://www.w3schools.com/jsref/jsref_obj_regexp.asp] */ -public class Regex(pattern: String, options: Set) { +public actual class Regex actual constructor(pattern: String, options: Set) { /** Creates a regular expression from the specified [pattern] string and the specified single [option]. */ - public constructor(pattern: String, option: RegexOption) : this(pattern, setOf(option)) + public actual constructor(pattern: String, option: RegexOption) : this(pattern, setOf(option)) /** Creates a regular expression from the specified [pattern] string and the default options. */ - public constructor(pattern: String) : this(pattern, emptySet()) + public actual constructor(pattern: String) : this(pattern, emptySet()) /** The pattern string of this regular expression. */ - public val pattern: String = pattern + public actual val pattern: String = pattern /** The set of options that were used to create this regular expression. */ - public val options: Set = options.toSet() + public actual val options: Set = options.toSet() private val nativePattern: RegExp = RegExp(pattern, options.map { it.value }.joinToString(separator = "") + "g") /** Indicates whether the regular expression matches the entire [input]. */ - public infix fun matches(input: CharSequence): Boolean { + public actual infix fun matches(input: CharSequence): Boolean { nativePattern.reset() val match = nativePattern.exec(input.toString()) return match != null && match.index == 0 && nativePattern.lastIndex == input.length } /** Indicates whether the regular expression can find at least one match in the specified [input]. */ - public fun containsMatchIn(input: CharSequence): Boolean { + public actual fun containsMatchIn(input: CharSequence): Boolean { nativePattern.reset() return nativePattern.test(input.toString()) } @@ -76,18 +76,18 @@ public class Regex(pattern: String, options: Set) { * @param startIndex An index to start search with, by default 0. Must be not less than zero and not greater than `input.length()` * @return An instance of [MatchResult] if match was found or `null` otherwise. */ - public fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = nativePattern.findNext(input.toString(), startIndex) + public actual fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = nativePattern.findNext(input.toString(), startIndex) /** Returns a sequence of all occurrences of a regular expression within the [input] string, beginning at the specified [startIndex]. */ - public fun findAll(input: CharSequence, startIndex: Int = 0): Sequence = generateSequence({ find(input, startIndex) }, { match -> match.next() }) + public actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence = generateSequence({ find(input, startIndex) }, { match -> match.next() }) /** * Attempts to match the entire [input] CharSequence against the pattern. * * @return An instance of [MatchResult] if the entire input matches or `null` otherwise. */ - public fun matchEntire(input: CharSequence): MatchResult? { + public actual fun matchEntire(input: CharSequence): MatchResult? { if (pattern.startsWith('^') && pattern.endsWith('$')) return find(input) else @@ -99,14 +99,14 @@ public class Regex(pattern: String, options: Set) { * * @param replacement A replacement expression that can include substitutions. See [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace] for details. */ - public fun replace(input: CharSequence, replacement: String): String = input.toString().nativeReplace(nativePattern, replacement) + public actual fun replace(input: CharSequence, replacement: String): String = input.toString().nativeReplace(nativePattern, replacement) /** * Replaces all occurrences of this regular expression in the specified [input] string with the result of * the given function [transform] that takes [MatchResult] and returns a string to be used as a * replacement for that match. */ - public inline fun replace(input: CharSequence, transform: (MatchResult) -> CharSequence): String { + public actual inline fun replace(input: CharSequence, transform: (MatchResult) -> CharSequence): String { var match = find(input) if (match == null) return input.toString() @@ -134,7 +134,7 @@ public class Regex(pattern: String, options: Set) { * * @param replacement A replacement expression that can include substitutions. See [Matcher.appendReplacement] for details. */ - public fun replaceFirst(input: CharSequence, replacement: String): String { + public actual fun replaceFirst(input: CharSequence, replacement: String): String { val nonGlobalOptions = options.map { it.value }.joinToString(separator = "") return input.toString().nativeReplace(RegExp(pattern, nonGlobalOptions), replacement) } @@ -144,7 +144,7 @@ public class Regex(pattern: String, options: Set) { * * @param limit The maximum number of times the split can occur. */ - public fun split(input: CharSequence, limit: Int = 0): List { + public actual fun split(input: CharSequence, limit: Int = 0): List { 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 result = mutableListOf() @@ -161,15 +161,15 @@ public class Regex(pattern: String, options: Set) { /** Returns the string representation of this regular expression. */ public override fun toString(): String = nativePattern.toString() - companion object { + actual companion object { /** Returns a literal regex for the specified [literal] string. */ - public fun fromLiteral(literal: String): Regex = Regex(escape(literal)) + public actual fun fromLiteral(literal: String): Regex = Regex(escape(literal)) /** Returns a literal pattern for the specified [literal] string. */ - public fun escape(literal: String): String = literal.nativeReplace(patternEscape, "\\$&") + public actual fun escape(literal: String): String = literal.nativeReplace(patternEscape, "\\$&") /** Returns a literal replacement exression for the specified [literal] string. */ - public fun escapeReplacement(literal: String): String = literal.nativeReplace(replacementEscape, "$$$$") + public actual fun escapeReplacement(literal: String): String = literal.nativeReplace(replacementEscape, "$$$$") private val patternEscape = RegExp("""[-\\^$*+?.()|[\]{}]""", "g") private val replacementEscape = RegExp("""\$""", "g") diff --git a/libraries/stdlib/js/src/kotlin/sequence.kt b/libraries/stdlib/js/src/kotlin/sequence.kt index c0ae870be41..718c1a8c709 100644 --- a/libraries/stdlib/js/src/kotlin/sequence.kt +++ b/libraries/stdlib/js/src/kotlin/sequence.kt @@ -16,10 +16,10 @@ package kotlin.sequences -internal class ConstrainedOnceSequence(sequence: Sequence) : Sequence { +internal actual class ConstrainedOnceSequence actual constructor(sequence: Sequence) : Sequence { private var sequenceRef: Sequence? = sequence - override fun iterator(): Iterator { + actual override fun iterator(): Iterator { val sequence = sequenceRef ?: throw IllegalStateException("This sequence can be consumed only once.") sequenceRef = null return sequence.iterator() diff --git a/libraries/stdlib/js/src/kotlin/string.kt b/libraries/stdlib/js/src/kotlin/string.kt index 1598991b52a..472189cdde1 100644 --- a/libraries/stdlib/js/src/kotlin/string.kt +++ b/libraries/stdlib/js/src/kotlin/string.kt @@ -3,16 +3,16 @@ package kotlin.text import kotlin.js.RegExp @kotlin.internal.InlineOnly -public inline fun String.toUpperCase(): String = asDynamic().toUpperCase() +public actual inline fun String.toUpperCase(): String = asDynamic().toUpperCase() @kotlin.internal.InlineOnly -public inline fun String.toLowerCase(): String = asDynamic().toLowerCase() +public actual inline fun String.toLowerCase(): String = asDynamic().toLowerCase() @kotlin.internal.InlineOnly -internal inline fun String.nativeIndexOf(str: String, fromIndex: Int): Int = asDynamic().indexOf(str, fromIndex) +internal actual inline fun String.nativeIndexOf(str: String, fromIndex: Int): Int = asDynamic().indexOf(str, fromIndex) @kotlin.internal.InlineOnly -internal inline fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int = asDynamic().lastIndexOf(str, fromIndex) +internal actual inline fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int = asDynamic().lastIndexOf(str, fromIndex) @kotlin.internal.InlineOnly internal inline fun String.nativeStartsWith(s: String, position: Int): Boolean = asDynamic().startsWith(s, position) @@ -21,10 +21,10 @@ internal inline fun String.nativeStartsWith(s: String, position: Int): Boolean = internal inline fun String.nativeEndsWith(s: String): Boolean = asDynamic().endsWith(s) @kotlin.internal.InlineOnly -public inline fun String.substring(startIndex: Int): String = asDynamic().substring(startIndex) +public actual inline fun String.substring(startIndex: Int): String = asDynamic().substring(startIndex) @kotlin.internal.InlineOnly -public inline fun String.substring(startIndex: Int, endIndex: Int): String = asDynamic().substring(startIndex, endIndex) +public actual inline fun String.substring(startIndex: Int, endIndex: Int): String = asDynamic().substring(startIndex, endIndex) @kotlin.internal.InlineOnly public inline fun String.concat(str: String): String = asDynamic().concat(str) diff --git a/libraries/stdlib/js/src/kotlin/stringsCode.kt b/libraries/stdlib/js/src/kotlin/stringsCode.kt index eb0f18589cf..d78f5e7fa1b 100644 --- a/libraries/stdlib/js/src/kotlin/stringsCode.kt +++ b/libraries/stdlib/js/src/kotlin/stringsCode.kt @@ -3,9 +3,9 @@ package kotlin.text import kotlin.js.RegExp @kotlin.internal.InlineOnly -internal inline fun String.nativeIndexOf(ch: Char, fromIndex: Int): Int = nativeIndexOf(ch.toString(), fromIndex) +internal actual inline fun String.nativeIndexOf(ch: Char, fromIndex: Int): Int = nativeIndexOf(ch.toString(), fromIndex) @kotlin.internal.InlineOnly -internal inline fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = nativeLastIndexOf(ch.toString(), fromIndex) +internal actual inline fun String.nativeLastIndexOf(ch: Char, fromIndex: Int): Int = nativeLastIndexOf(ch.toString(), fromIndex) /** * Returns `true` if this string starts with the specified prefix. @@ -44,9 +44,9 @@ public fun String.matches(regex: String): Boolean { return result != null && result.size != 0 } -public fun CharSequence.isBlank(): Boolean = length == 0 || (if (this is String) this else this.toString()).matches("^[\\s\\xA0]+$") +public actual fun CharSequence.isBlank(): Boolean = length == 0 || (if (this is String) this else this.toString()).matches("^[\\s\\xA0]+$") -public fun String?.equals(other: String?, ignoreCase: Boolean = false): Boolean = +public actual fun String?.equals(other: String?, ignoreCase: Boolean = false): Boolean = if (this == null) other == null else if (!ignoreCase) @@ -55,7 +55,7 @@ public fun String?.equals(other: String?, ignoreCase: Boolean = false): Boolean other != null && this.toLowerCase() == other.toLowerCase() -public fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean +public actual fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean = regionMatchesImpl(thisOffset, other, otherOffset, length, ignoreCase) @@ -64,7 +64,7 @@ public fun CharSequence.regionMatches(thisOffset: Int, other: CharSequence, othe * * @includeFunctionBody ../../test/StringTest.kt capitalize */ -public fun String.capitalize(): String { +public actual fun String.capitalize(): String { return if (isNotEmpty()) substring(0, 1).toUpperCase() + substring(1) else this } @@ -73,7 +73,7 @@ public fun String.capitalize(): String { * * @includeFunctionBody ../../test/StringTest.kt decapitalize */ -public fun String.decapitalize(): String { +public actual fun String.decapitalize(): String { return if (isNotEmpty()) substring(0, 1).toLowerCase() + substring(1) else this } @@ -81,7 +81,7 @@ public fun String.decapitalize(): String { * Returns a string containing this char sequence repeated [n] times. * @throws [IllegalArgumentException] when n < 0. */ -public fun CharSequence.repeat(n: Int): String { +public actual fun CharSequence.repeat(n: Int): String { require(n >= 0) { "Count 'n' must be non-negative, but was $n." } return when (n) { 0 -> "" @@ -107,14 +107,14 @@ public fun CharSequence.repeat(n: Int): String { } } -public fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String = +public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String = nativeReplace(RegExp(Regex.escape(oldValue), if (ignoreCase) "gi" else "g"), Regex.escapeReplacement(newValue)) -public fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String = +public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String = nativeReplace(RegExp(Regex.escape(oldChar.toString()), if (ignoreCase) "gi" else "g"), newChar.toString()) -public fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean = false): String = +public actual fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean = false): String = nativeReplace(RegExp(Regex.escape(oldValue), if (ignoreCase) "i" else ""), Regex.escapeReplacement(newValue)) -public fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String = +public actual fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean = false): String = nativeReplace(RegExp(Regex.escape(oldChar.toString()), if (ignoreCase) "i" else ""), newChar.toString()) diff --git a/libraries/stdlib/js/src/kotlin/text.kt b/libraries/stdlib/js/src/kotlin/text.kt index 9f2791bb9ad..78fdb7ee7ef 100644 --- a/libraries/stdlib/js/src/kotlin/text.kt +++ b/libraries/stdlib/js/src/kotlin/text.kt @@ -17,47 +17,49 @@ package kotlin.text -public interface Appendable { - fun append(csq: CharSequence?): Appendable - fun append(csq: CharSequence?, start: Int, end: Int): Appendable - fun append(c: Char): Appendable +public actual interface Appendable { + public actual fun append(csq: CharSequence?): Appendable + public actual fun append(csq: CharSequence?, start: Int, end: Int): Appendable + public actual fun append(c: Char): Appendable } -public class StringBuilder(content: String = "") : Appendable, CharSequence { - constructor(@Suppress("UNUSED_PARAMETER") capacity: Int) : this() {} +public actual class StringBuilder(content: String) : Appendable, CharSequence { + actual constructor(@Suppress("UNUSED_PARAMETER") capacity: Int) : this() {} - constructor(content: CharSequence) : this(content.toString()) {} + actual constructor(content: CharSequence) : this(content.toString()) {} + + actual constructor() : this("") private var string: String = content - override val length: Int + actual override val length: Int get() = string.asDynamic().length - override fun get(index: Int): Char = string[index] + actual override fun get(index: Int): Char = string[index] - override fun subSequence(start: Int, end: Int): CharSequence = string.substring(start, end) + actual override fun subSequence(startIndex: Int, endIndex: Int): CharSequence = string.substring(startIndex, endIndex) - override fun append(c: Char): StringBuilder { + actual override fun append(c: Char): StringBuilder { string += c return this } - override fun append(csq: CharSequence?): StringBuilder { + actual override fun append(csq: CharSequence?): StringBuilder { string += csq.toString() return this } - override fun append(csq: CharSequence?, start: Int, end: Int): StringBuilder { + actual override fun append(csq: CharSequence?, start: Int, end: Int): StringBuilder { string += csq.toString().substring(start, end) return this } - fun append(obj: Any?): StringBuilder { + actual fun append(obj: Any?): StringBuilder { string += obj.toString() return this } - fun reverse(): StringBuilder { + actual fun reverse(): StringBuilder { string = string.asDynamic().split("").reverse().join("") return this }