Looking at this issue I think OP is right, the doc...
# javascript
e
Looking at this issue I think OP is right, the documentation states > Puts the given piece of a JavaScript code right into the calling function. The compiler replaces call to
js(...)
code with the string constant provided as a parameter However it's not just a simple replacement, there is some validation going on, which blocks the use of certain JS features. https://youtrack.jetbrains.com/issue/KT-67813 I wonder if a way to disable validation is doable?
t
My recommendation - use
JsFunction
factory instead of
js
blocks. Validation only in runtime 😉
e
Oh nice workaround! You should post it in the issue too
t
It's not workaround 🙂 It's safest implementation of JS calls, which I see
e
I meant that it's a workaround to the validation
l
I've used
js("eval")
as a workaround.
t
eval
limitation - no inputs 😞
l
@turansky I needed to exponentiate two bigints in JS, which the Kotlin compiler doesn't like. I assigned the two values as strings to
a
and
b
in the Kotlin code, and then did this:
js("(function(a0,b0){return eval(\"a0**b0\");})(BigInt(a),BigInt(b))")
t
We already have
BigInt
support in wrappers. Looks like missed PR or issue 🙂
How you write same operation for
Int
?
l
@turansky You can do it with any
dynamic
value:
js("(function(a0,b0,c0,d0){eval(\"do something with a0, b0, etc\")})(a,b,c,d)
Assuming that your values are in the Kotlin variables a,b,c,d.
t
FYI - you create new function on every call 😞
BigInt.pow
added. Will be available in new release
l
@turansky Yeah, it's a workaround. Thanks for the update about adding it.
Basically, it's part of a multiplatform bigint/rational arithmetic library I implemented for my programming language (which itself is implemented in Kotlin). Here's the code if anyone is interested: https://codeberg.org/loke/array/src/branch/master/mpbignum
👍 1