Is it possible to invoke a javascript function bef...
# javascript
b
Is it possible to invoke a javascript function before Kotlin assigns any classes to it's internal wrappes? Background: matrix.org's olm implementation for javascript uses emscripten wasm and assigns it's classes after calling an init() function. Therefore the kotlin wrappers has unvalid references
t
You can add injection right in final script
c
If your project uses an HTML file for startup, you can execute any JS you want before loading the Kotlin file
b
Because it's a library injecting sounds very good, but how? Or do you mean manually add it to the script? That sound hacky...
c
Another solution: use lambdas instead of global variables, this way the references are only created on first access
Or you might want the ‘initialize globals on first access’ or whatever the option is called (it's one of the options added with IR)
b
I don't have global variables. Just classes which are used in the main or test function. In the compiled js code there is stuff like
var Account_1 = $module$_matrix_org_olm.Account;
right after the external js module is loaded.
Account_1
is used later, but points to undefined, because
init
wasn't called before
var Account_1 = ...
. A workaround is to call
js("new Olm.Account()")
everytime I would call
Account()
, but that feels really bad.
Tried
-Xir-property-lazy-initialization
and it did not work. Still
var Account_1 = $module$_matrix_org_olm.Account;
at the beginning.