1

Does anyone know which JavaScript engine Kotlin is using to evaluate Javascript? I found the following class

KotlinJsr223ScriptEngineFactoryExamples.kt

looking at the class source KotlinJsr223ScriptEngineFactoryExamples.kt could see the following dependency

import javax.script.Bindings
import javax.script.ScriptContext
import javax.script.ScriptEngine

I'm wondering whether Kotlin is based on already existing Javascript Engines like Nashorn or Rhino or it's running its own implementation. I'm considering to port my lib to Korlin, the performance is extremely important for me, base on my tests Hashorn is losing to Rhino. So I want to find out, what engine Kotlin is executing behind the senses.

Thanks in advance

4
  • 1
    Kotlin and Javascript are just languages. When you compile kotlin to javascript, it is translated to a javascript file and you can use the javascript file anywhere directly. Commented Jan 29, 2019 at 8:08
  • Thanks for replying, my intention was to figure out not how Kotlin is interpreted to JS but what lib it is using when I need to eval JS static code from Kotlin. I don't believe Kotlin does with it something, I wouldn't expect to see some JS engine, like Rhino for JAVA Commented Jan 29, 2019 at 9:11
  • What do you mean by "eval JS static code from Kotlin"? The js() function supporting inline JavaScript is only available in Kotlin/JS. Kotlin/JVM and Kotlin/Native do not have any features for evaluating JS code. Commented Jan 29, 2019 at 12:41
  • according to the doc kotlinlang.org/docs/reference/… the javascript could be eval not only using js() Commented Jan 29, 2019 at 14:33

1 Answer 1

1

JavaScript engine is provided by JDK. It can be:

You can find out script engine for your JDK using:

val engine = javax.script.ScriptEngineManager().getEngineByName("JavaScript")

println(engine::class) // class jdk.nashorn.api.scripting.NashornScriptEngine
Sign up to request clarification or add additional context in comments.

1 Comment

Please advice on which script engine one can use now, after Nashorn has been deprecated in JDK 11? @kzm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.