hallvard
01/20/2019, 9:25 PMtoString()
on that class should return JSON.stringify(theMap)
. But that won't work since js maps have this prototype thing in them (at least I think that's why), and so there are circular references in js runtime. Has anyone got a good idea about how I could convert the map into something that JSON.stringify()
would like?hallvard
01/21/2019, 1:12 PMvararg
function parameters? In a function of mine, there is only one parameter, and it is defined as vararg tags: String
. Inside the function, I collect the vararg into a list: tags.asList()
. In the produced js, the parameter is of course named tags
, and I find this in the function body: asList(tags)
. But wait... This takes the first string passed in and turns it into a character list.galex
01/21/2019, 4:59 PMspierce7
01/21/2019, 5:21 PMankushg
01/23/2019, 12:00 AMJson
interface? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-json/index.html
Is this something that kotlinx.serialization
supports?
I'm trying to create a wrapper around my Kotlin library so that I can pass in JS objects (i.e., {foo: "bar"}
and then convert the resulting Json
object into an instance of data class MyDataClass(val foo: String)
, and vice versa when returning an instance of MyDataClass
from Kotlin to JShallvard
01/25/2019, 3:32 PMtime=1548429717649
. But I am generating JSON, and am converting my map to an object before doing JSON.stringify()
in order to avoid cyclic references from the map, and I see the long values represented as objects, and in the final JSON, they are represented thus: "time":{"low_":-2053476207,"high_":360}
. I guess this has to do with dealing with 64bit numbers in javascript, but my question is: How do I detect this and how do I convert them? Using typeof
as I pull them out of my map, I only get object
...Alexander
01/27/2019, 11:32 AMargs
of main
function in kotlin/js always empty when running on nodejs?
fun main(args: Array<String>) = println(args.size)
// always prints 0
To access command line arguments I should do something like:
@JsModule("process")
external object process {
val argv: Array<String>
}
fun main() = println(process.argv.sliceArray(2 until process.argv.size))
Not a super convenient way. And it is defferent from the other platforms.natpryce
01/29/2019, 8:51 AMhallvard
01/29/2019, 11:49 AMMessage
, and the correct way to go about it in js is new Message.constructor()
, right? But I cannot make it use my overloaded constructors, they never seem to get called. Must I name them with annotations in order to use them? (Like @JsName("MessageFromString")
and @JsName("MessageFromMap")
or something?)spierce7
01/30/2019, 3:59 PMsdeleuze
02/07/2019, 10:11 AMsdeleuze
02/07/2019, 10:27 AM((MessageEvent) -> dynamic)?
signature, why not just MessageEvent -> Unit
?sdeleuze
02/07/2019, 10:40 AMthana
02/08/2019, 6:09 PMmichael.barker
02/09/2019, 6:20 PMhallvard
02/11/2019, 11:19 AMSackCastellon
02/11/2019, 12:41 PMwebpack-bundle
task I get the following error:
> Task :webpack-bundle
Hash: df342eca11f1ca4960d1
Version: webpack 4.29.3
Time: 1438ms
Built at: 02/11/2019 1:36:14 PM
Asset Size Chunks Chunk Names
main.bundle.js 4.06 MiB main [emitted] main
Entrypoint main = main.bundle.js
[../../../../node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 472 bytes {main} [built]
[../../../../node_modules_imported/kotlin-extensions/kotlin-extensions.js] D:/Juanjo/Code/UJI/mpp/build/node_modules_imported/kotlin-extensions/kotlin-extensions.js 4.09 KiB {main} [built]
[../../../../node_modules_imported/kotlin-react-dom/kotlin-react-dom.js] D:/Juanjo/Code/UJI/mpp/build/node_modules_imported/kotlin-react-dom/kotlin-react-dom.js 112 KiB {main} [built]
[../../../../node_modules_imported/kotlin-react/kotlin-react.js] D:/Juanjo/Code/UJI/mpp/build/node_modules_imported/kotlin-react/kotlin-react.js 18.4 KiB {main} [built]
[../../../../node_modules_imported/kotlin/kotlin.js] D:/Juanjo/Code/UJI/mpp/build/node_modules_imported/kotlin/kotlin.js 1.7 MiB {main} [built]
[../../../../node_modules_imported/kotlinx-coroutines-core/kotlinx-coroutines-core.js] D:/Juanjo/Code/UJI/mpp/build/node_modules_imported/kotlinx-coroutines-core/kotlinx-coroutines-core.js 708 KiB {main} [built]
[../../../../node_modules_imported/kotlinx-html-js/kotlinx-html-js.js] D:/Juanjo/Code/UJI/mpp/build/node_modules_imported/kotlinx-html-js/kotlinx-html-js.js 587 KiB {main} [built]
[./mpp.js] 5.06 KiB {main} [built]
+ 12 hidden modules
ERROR in D:/Juanjo/Code/UJI/mpp/build/node_modules_imported/kotlin-extensions/kotlin-extensions.js
Module not found: Error: Can't resolve 'core-js/library/fn/object/assign' in 'D:\Juanjo\Code\UJI\mpp\build\node_modules_imported\kotlin-extensions'
@ D:/Juanjo/Code/UJI/mpp/build/node_modules_imported/kotlin-extensions/kotlin-extensions.js 116:37-80
@ D:/Juanjo/Code/UJI/mpp/build/node_modules_imported/kotlin-react/kotlin-react.js
@ ./mpp.js
> Task :webpack-bundle FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':webpack-bundle'.
> node webpack.js failed (exit code = 2)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at <https://help.gradle.org>
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See <https://docs.gradle.org/4.10.3/userguide/command_line_interface.html#sec:command_line_warnings>
BUILD FAILED in 4s
8 actionable tasks: 3 executed, 5 up-to-date
Cause: node webpack.js failed (exit code = 2)
13:36:14: Task execution finished 'webpack-bundle'.
The project is just a copy of https://github.com/Kotlin/kotlin-frontend-plugin/tree/master/examples/new-mpp, with the timer example from https://reactjs.org/#a-stateful-component to test how KotlinJS works with react.thana
02/11/2019, 6:00 PMthana
02/11/2019, 6:13 PMlateinit
obviously lateinit and jsname doesnt work togetheryousuf.haque
02/11/2019, 6:35 PM- root
- module1
- build.gradle
- module2
- build.gradle
- sharedmodule
- src
- SomeDataClass.kt
- build.gradle
- build.gradle
In the above example, I'd like to use SomeDataClass
in module 1 and module 2 without having to set up a kotlin multiplatform project
cc @Zachary SmithGarouDan
02/11/2019, 10:09 PMthana
02/12/2019, 1:28 PMLong
property. when i use json.stringify()
on javascript it creates an object with two properties lwo_
and high_
what, otoho, kotlin isnt able to decoe again... is there any way out of this situation?jw
02/12/2019, 4:51 PMSOFe
02/19/2019, 4:12 AMspand
02/20/2019, 8:10 AMgalex
02/20/2019, 5:54 PMgalex
02/21/2019, 5:25 AMlouiscad
02/21/2019, 10:17 PMjs
target and a dependency to the js stdlib, but when I run the build
gradle task, I get the following error:
org.gradle.execution.MultipleBuildFailures: Build completed with 1 failures.
...
...
Caused by: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':modules:bitflags:compileKotlinJs'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
...
...
... 6 more
Caused by: java.lang.NoSuchMethodError: org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments.setCommonSources([Ljava/lang/String;)V
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runJsCompilerAsync(GradleKotlinCompilerRunner.kt:297)
at org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile.callCompilerAsync$kotlin_gradle_plugin(Tasks.kt:566)
at org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile.callCompilerAsync$kotlin_gradle_plugin(Tasks.kt:476)
Here's the link to the gradle.kts file of the module I'm trying to build: https://github.com/LouisCAD/Splitties/blob/baaf3548141ac5f8e631b5f858cc9ce25bfa2cbe/modules/bitflags/build.gradle.kts#L28
and here's the buildSrc
it depends on:
https://github.com/LouisCAD/Splitties/tree/baaf3548141ac5f8e631b5f858cc9ce25bfa2cbe/buildSrc
I'm using Kotlin 1.3.21 with Gradle 4.10.1, and AGP 3.3.1 for the Android part.Azaryan
02/22/2019, 9:06 PMgalex
02/23/2019, 2:57 PMgalex
02/23/2019, 2:57 PMDico
02/23/2019, 3:45 PMSvyatoslav Kuzmich [JB]
02/23/2019, 3:55 PMDico
02/23/2019, 4:00 PMgalex
02/23/2019, 5:24 PM@Suppress("CAST_NEVER_SUCCEEDS")
fun ArrayBuffer?.asByteArray(): ByteArray? = this?.run { Int8Array(this) as ByteArray }
Svyatoslav Kuzmich [JB]
02/23/2019, 5:41 PMgalex
02/23/2019, 5:47 PMSvyatoslav Kuzmich [JB]
02/23/2019, 5:55 PMByteArray
and Int8Array
are the same things on runtime we can use:
fun ArrayBuffer?.asByteArray(): ByteArray? =
this?.run { Int8Array(this).unsafeCast<ByteArray>() }
This will eliminate unnecesary type check and we don't have to use @Suppress
Generated code for unsafeCast
would be:
return $receiver != null ? new Int8Array($receiver) : null;
compared to as
version:
var tmp$;
if ($receiver != null) {
var tmp$_0;
tmp$ = Kotlin.isByteArray(tmp$_0 = new Int8Array($receiver)) ? tmp$_0 : throwCCE();
}
else
tmp$ = null;
return tmp$;
I’d like that function to be part of kotlin/js by defaultCould you file a feature request at kotl.in/issue?
galex
02/23/2019, 6:13 PMSvyatoslav Kuzmich [JB]
02/23/2019, 6:22 PMunsafeCast
has downsides, if cast fails your program will fail the JavaScript way: usually farther down the execution with ambiguous error message 😁galex
02/23/2019, 6:23 PM