From a33a3867b8456652572e0917f6dc129ace7a89ef Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 26 Dec 2017 06:56:07 +0300 Subject: [PATCH] JS: Move declaration to match their packages in JVM and Common stdlib Mostly internal, but also two public annotations --- js/js.libraries/src/core/annotationsJVM.kt | 11 ++++++++++- js/js.libraries/src/core/collections.kt | 16 ++++++++++++++++ js/js.libraries/src/core/concurrent.kt | 21 ++++----------------- js/js.libraries/src/core/io.kt | 20 ++++++++++++++++++++ js/js.libraries/src/core/kotlin.kt | 19 ------------------- 5 files changed, 50 insertions(+), 37 deletions(-) create mode 100644 js/js.libraries/src/core/io.kt diff --git a/js/js.libraries/src/core/annotationsJVM.kt b/js/js.libraries/src/core/annotationsJVM.kt index 60a613347b9..0ca155ad7f5 100644 --- a/js/js.libraries/src/core/annotationsJVM.kt +++ b/js/js.libraries/src/core/annotationsJVM.kt @@ -35,4 +35,13 @@ internal annotation class JvmMultifileClass @Target(AnnotationTarget.FIELD) @Retention(AnnotationRetention.SOURCE) @MustBeDocumented -internal annotation class JvmField \ No newline at end of file +internal annotation class JvmField + + +@Target(AnnotationTarget.FIELD) +@Retention(AnnotationRetention.SOURCE) +public annotation class Volatile + +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +@Retention(AnnotationRetention.SOURCE) +public annotation class Synchronized diff --git a/js/js.libraries/src/core/collections.kt b/js/js.libraries/src/core/collections.kt index d7b25d8c587..e1b141b92e8 100644 --- a/js/js.libraries/src/core/collections.kt +++ b/js/js.libraries/src/core/collections.kt @@ -139,3 +139,19 @@ private fun collectionsSort(list: MutableList, comparator: Comparator 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 + +internal inline fun Map.toSingletonMap(): Map = this.toMutableMap() + +internal inline fun Array.copyToArrayOfAny(isVarargs: Boolean): Array = + if (isVarargs) + // no need to copy vararg array in JS + this + else + this.copyOf() diff --git a/js/js.libraries/src/core/concurrent.kt b/js/js.libraries/src/core/concurrent.kt index 39c5f5cca71..e20b93d9c3e 100644 --- a/js/js.libraries/src/core/concurrent.kt +++ b/js/js.libraries/src/core/concurrent.kt @@ -17,23 +17,10 @@ package kotlin -// Note: -// Right now we don't want to have neither 'volatile' nor 'synchronized' at runtime, -// so they annotated as `external` to avoid warnings/errors from some minifiers. -// They was reserved word in ECMAScript 2, but is not since ECMAScript 5. - -// Additional note: -// Although it's reasonable to mark these annotations as `@native` (`external` since 1.1), -// we prohibit marking annotations this way. -// TODO: Another workaround is required to remove these annotations from kotlin.js - -@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD) -@Retention(AnnotationRetention.SOURCE) -public annotation class Volatile - -@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) -@Retention(AnnotationRetention.SOURCE) -public annotation class Synchronized +@Deprecated("Use Synchronized annotation from kotlin.jvm package", ReplaceWith("kotlin.jvm.Synchronized"), level = DeprecationLevel.WARNING) +public typealias Synchronized = kotlin.jvm.Synchronized +@Deprecated("Use Volatile annotation from kotlin.jvm package", ReplaceWith("kotlin.jvm.Volatile"), level = DeprecationLevel.WARNING) +public typealias Volatile = kotlin.jvm.Volatile @kotlin.internal.InlineOnly public inline fun synchronized(@Suppress("UNUSED_PARAMETER") lock: Any, block: () -> R): R = block() diff --git a/js/js.libraries/src/core/io.kt b/js/js.libraries/src/core/io.kt new file mode 100644 index 00000000000..08c45880132 --- /dev/null +++ b/js/js.libraries/src/core/io.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.io + +// temporary for shared code, until we have an annotation like JvmSerializable +internal interface Serializable \ No newline at end of file diff --git a/js/js.libraries/src/core/kotlin.kt b/js/js.libraries/src/core/kotlin.kt index 0527fda0519..2df112b81f7 100644 --- a/js/js.libraries/src/core/kotlin.kt +++ b/js/js.libraries/src/core/kotlin.kt @@ -69,10 +69,6 @@ public fun lazy(mode: LazyThreadSafetyMode, initializer: () -> T): Lazy = public fun lazy(lock: Any?, initializer: () -> T): Lazy = UnsafeLazyImpl(initializer) -internal fun arrayOfNulls(reference: Array, size: Int): Array { - return arrayOfNulls(size).unsafeCast>() -} - internal fun fillFrom(src: dynamic, dst: dynamic): dynamic { val srcLen: Int = src.length val dstLen: Int = dst.length @@ -113,18 +109,3 @@ internal inline fun copyArrayType(from: dynamic, to: dynamic) { to.`$type$` = from.`$type$` } } - -// no singleton map implementation in js, return map as is -internal inline fun Map.toSingletonMapOrSelf(): Map = this - -internal inline fun Map.toSingletonMap(): Map = this.toMutableMap() - -internal inline fun Array.copyToArrayOfAny(isVarargs: Boolean): Array = - if (isVarargs) - // no need to copy vararg array in JS - this - else - this.copyOf() - -// temporary for shared code, until we have an annotation like JvmSerializable -internal interface Serializable \ No newline at end of file