Reorganize stdlib-js sources specific to the current JS backend
Move kotlin-stdlib-js project and the sources specific to the current backend to 'stdlib/js-v1' directory, but leave sources that can be shared with the new IR backend in the common 'stdlib/js' location with exception for 'stdlib/js/src/generated', which is used exclusively for current backend. This simplifies sourceset configuration when building stdlib with the new backend.
This commit is contained in:
+3
-3
@@ -111,14 +111,14 @@ public fun isChar(c: Any): Boolean {
|
||||
}
|
||||
|
||||
// TODO: Distinguish Boolean/Byte and Short/Char
|
||||
public fun isBooleanArray(a: dynamic): Boolean = isJsArray(a) && a.`$type$` == "BooleanArray"
|
||||
public fun isBooleanArray(a: dynamic): Boolean = isJsArray(a) && a.`$type$` === "BooleanArray"
|
||||
public fun isByteArray(a: dynamic): Boolean = js("a instanceof Int8Array").unsafeCast<Boolean>()
|
||||
public fun isShortArray(a: dynamic): Boolean = js("a instanceof Int16Array").unsafeCast<Boolean>()
|
||||
public fun isCharArray(a: dynamic): Boolean = isJsArray(a) && a.`$type$` == "CharArray"
|
||||
public fun isCharArray(a: dynamic): Boolean = isJsArray(a) && a.`$type$` === "CharArray"
|
||||
public fun isIntArray(a: dynamic): Boolean = js("a instanceof Int32Array").unsafeCast<Boolean>()
|
||||
public fun isFloatArray(a: dynamic): Boolean = js("a instanceof Float32Array").unsafeCast<Boolean>()
|
||||
public fun isDoubleArray(a: dynamic): Boolean = js("a instanceof Float64Array").unsafeCast<Boolean>()
|
||||
public fun isLongArray(a: dynamic): Boolean = isJsArray(a) && a.`$type$` == "LongArray"
|
||||
public fun isLongArray(a: dynamic): Boolean = isJsArray(a) && a.`$type$` === "LongArray"
|
||||
|
||||
|
||||
internal fun jsIn(x: String, y: dynamic): Boolean = js("x in y")
|
||||
@@ -0,0 +1,9 @@
|
||||
## Kotlin Standard Library for JS
|
||||
|
||||
This module produces a `kotlin-stdlib-js` jar which contains all the Kotlin standard kotlin library code compiled to JavaScript.
|
||||
|
||||
The tests of this module can be run and debugged inside any browser by opening the **web/index.html** file in this directory to run the test cases using [Mocha](https://mochajs.org/).
|
||||
|
||||
You should execute `installMocha` gradle task before running these tests to fetch the required Mocha dependency and `testClasses` task to compile test code.
|
||||
|
||||
These tests are also run during CI build with [Node.js plugin](https://github.com/srs/gradle-node-plugin).
|
||||
@@ -15,6 +15,7 @@ def builtinsSrcDir = "${buildDir}/builtin-sources"
|
||||
def builtinsSrcDir2 = "${buildDir}/builtin-sources-for-builtins"
|
||||
def commonSrcDir = "${projectDir}/../src/kotlin"
|
||||
def commonSrcDir2 = "${projectDir}/../common/src"
|
||||
def jsCommonDir = "${projectDir}/../js"
|
||||
def coroutinesExpJsSrcDir = "${rootDir}/libraries/stdlib/coroutines-experimental/js/src"
|
||||
|
||||
def builtinsDir = "${rootDir}/core/builtins"
|
||||
@@ -22,8 +23,12 @@ def unsignedCommonSrcDir = "${rootDir}/libraries/stdlib/unsigned/src"
|
||||
def experimentalSrcDir = "${rootDir}/libraries/stdlib/experimental"
|
||||
def experimentalJsModuleName = 'kotlin-experimental'
|
||||
def coroutinesJsModuleName = 'kotlin-stdlib-coroutines'
|
||||
|
||||
def jsSrcDir = "src"
|
||||
def jsCommonSrcDir = "${jsCommonDir}/src"
|
||||
def jsTestSrcDir = "test"
|
||||
def jsCommonTestSrcDir = "${jsCommonDir}/test"
|
||||
|
||||
def jsSrcJsDir = "${jsSrcDir}/js"
|
||||
def jsOutputFile = "${buildDir}/classes/kotlin.js"
|
||||
def jsOutputMetaFile = "${buildDir}/classes/kotlin.meta.js"
|
||||
@@ -34,11 +39,11 @@ def kotlinTestJsOutputFile = "${project(':kotlin-test:kotlin-test-js').buildDir}
|
||||
def jsTestOutputFile = "${buildDir}/classes/kotlin/test/kotlin-stdlib-js_test.js"
|
||||
def kotlinTestJsTestOutputFile = "${project(':kotlin-test:kotlin-test-js').buildDir}/classes/kotlin/test/kotlin-test-js_test.js"
|
||||
|
||||
|
||||
sourceSets {
|
||||
builtins {
|
||||
kotlin {
|
||||
srcDir builtinsSrcDir2
|
||||
srcDir "${jsCommonDir}/runtime"
|
||||
srcDir 'runtime'
|
||||
}
|
||||
}
|
||||
@@ -46,6 +51,7 @@ sourceSets {
|
||||
main {
|
||||
kotlin {
|
||||
srcDir builtinsSrcDir
|
||||
srcDir jsCommonSrcDir
|
||||
srcDir jsSrcDir
|
||||
}
|
||||
}
|
||||
@@ -60,6 +66,7 @@ sourceSets {
|
||||
test {
|
||||
kotlin {
|
||||
srcDir jsTestSrcDir
|
||||
srcDir jsCommonTestSrcDir
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +152,7 @@ compileKotlin2Js {
|
||||
sourceMap = true
|
||||
sourceMapPrefix = "./"
|
||||
freeCompilerArgs += [
|
||||
"-source-map-base-dirs", [builtinsSrcDir, jsSrcDir, commonSrcDir, commonSrcDir2, unsignedCommonSrcDir].collect { file(it).absoluteFile }.join(File.pathSeparator),
|
||||
"-source-map-base-dirs", [builtinsSrcDir, jsSrcDir, jsCommonSrcDir, commonSrcDir, commonSrcDir2, unsignedCommonSrcDir].collect { file(it).absoluteFile }.join(File.pathSeparator),
|
||||
"-Xuse-experimental=kotlin.Experimental",
|
||||
"-Xuse-experimental=kotlin.ExperimentalMultiplatform",
|
||||
"-Xuse-experimental=kotlin.contracts.ExperimentalContracts",
|
||||
@@ -198,6 +205,7 @@ task compileJs(type: NoDebugJavaExec) {
|
||||
inputs.files(compileExperimentalKotlin2Js.outputs.files)
|
||||
inputs.files(compileCoroutinesExperimentalKotlin2Js.outputs.files)
|
||||
inputs.dir(jsSrcDir)
|
||||
inputs.dir(jsCommonSrcDir)
|
||||
outputs.file(jsOutputFile)
|
||||
outputs.file("${jsOutputFile}.map")
|
||||
|
||||
@@ -239,15 +247,15 @@ task compileJs(type: NoDebugJavaExec) {
|
||||
|
||||
def sourceMapBasePaths = [
|
||||
"./",
|
||||
"libraries/stdlib/js/src/js/",
|
||||
"libraries/stdlib/js/src/",
|
||||
"libraries/stdlib/js-v1/src/js/",
|
||||
"libraries/stdlib/js-v1/src/",
|
||||
]
|
||||
sourceMap.sources = sourceMap.sources.collect { sourcePath ->
|
||||
def prefixToRemove = sourceMapBasePaths.find { basePath -> sourcePath.startsWith(basePath) }
|
||||
if (prefixToRemove != null) sourcePath.substring(prefixToRemove.length()) else sourcePath
|
||||
}
|
||||
|
||||
def sourceMapSourcesBaseDirs = [jsSrcDir, jsSrcJsDir, builtinsSrcDir, commonSrcDir, commonSrcDir2, projectDir, experimentalSrcDir, unsignedCommonSrcDir]
|
||||
def sourceMapSourcesBaseDirs = [jsSrcDir, jsCommonSrcDir, jsSrcJsDir, builtinsSrcDir, commonSrcDir, commonSrcDir2, projectDir, experimentalSrcDir, unsignedCommonSrcDir]
|
||||
|
||||
sourceMap.sourcesContent = sourceMap.sources.collect { sourceName ->
|
||||
def text = sourceMapSourcesBaseDirs.collect { file("$it/$sourceName") }.find { it.exists() }?.text
|
||||
@@ -1,9 +1,5 @@
|
||||
## Kotlin Standard Library for JS
|
||||
This directory contains shared sources of Kotlin/JS Standard Library for current and IR backends.
|
||||
|
||||
This module produces a `kotlin-stdlib-js` jar which contains all the Kotlin standard kotlin library code compiled to JavaScript.
|
||||
Note that `stdlib/js/src/generated` is not shared but used exclusively for current `js-v1` backend.
|
||||
|
||||
The tests of this module can be run and debugged inside any browser by opening the **web/index.html** file in this directory to run the test cases using [Mocha](https://mochajs.org/).
|
||||
|
||||
You should execute `installMocha` gradle task before running these tests to fetch the required Mocha dependency and `testClasses` task to compile test code.
|
||||
|
||||
These tests are also run during CI build with [Node.js plugin](https://github.com/srs/gradle-node-plugin).
|
||||
Kotlin/JS Standard Library module is moved to `libraries/stdlib/js-v1`.
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.random
|
||||
|
||||
import kotlin.math.pow
|
||||
|
||||
// TODO: use stdlib file when math.pow is fixed
|
||||
|
||||
internal actual fun defaultPlatformRandom(): Random =
|
||||
Random(js("(Math.random() * Math.pow(2, 32)) | 0").unsafeCast<Int>())
|
||||
|
||||
|
||||
internal actual fun fastLog2(value: Int): Int {
|
||||
// TODO: not so fast, make faster
|
||||
var v = value
|
||||
var log = -1
|
||||
while (v != 0) {
|
||||
v = v.ushr(1)
|
||||
log++
|
||||
}
|
||||
return log
|
||||
}
|
||||
|
||||
internal actual fun doubleFromParts(hi26: Int, low27: Int): Double =
|
||||
hi26 * (2.0.pow(-26)) + low27 * (2.0.pow(-53))
|
||||
@@ -73,7 +73,7 @@ internal object PrimitiveClasses {
|
||||
fun functionClass(arity: Int): KClassImpl<Any> {
|
||||
return functionClasses.get(arity) ?: run {
|
||||
val result = PrimitiveKClassImpl(js("Function").unsafeCast<JsClass<Any>>(), "Function$arity",
|
||||
{ jsTypeOf(it) === "function" && it.asDynamic().length == arity })
|
||||
{ jsTypeOf(it) === "function" && it.asDynamic().length === arity })
|
||||
functionClasses.asDynamic()[arity] = result
|
||||
result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user