Skip to content
yuroyamiPublic

About

A JavaScript engine for Kotlin multiplatform, Android, iOS, JVM and JS. Based on Mozilla Rhino ported to pure Kotlin Multiplatform

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

210 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KiteJS

A JavaScript engine for Kotlin Multiplatform, with two engines behind one API: Mozilla Rhino's interpreter ported to common Kotlin, and QuickJS-ng compiled into each target. Either one runs the same script the same way on every target.

AI tools wrote much of the code, tests and documentation in this project, under the direction and review of its author.

Documentation · Getting started · Choosing an engine · Binding host objects · Differences from a browser · API reference

KiteJs(QuickJs) { instructionBudget = 5_000_000 }.use { js ->
    js.global.function<Double, Double, Double>("hypot") { a, b -> hypot(a, b) }
    js.global.obj("document") {
        property("title", "Untitled")
        getter("readyState") { "complete" }
    }
    println(js.evaluate("document.title + ':' + hypot(3, 4)").asString())
}
// Untitled:5

Swap QuickJs for Rhino and nothing else changes: the values, the host bindings, the promises and the errors behave the same on both.

Two engines

Rhino is common Kotlin all the way down. There is no native library to ship and no code generation at runtime, and the parser, the regular expressions, the date arithmetic and the number formatting are all computed inside the engine. It runs ES5.1 and most of ES2015 and later: let and const, arrow functions, destructuring, classes with private and static members, Symbol, Map, Set, generators, Promise, async functions, async generators and for await, iterator helpers, Proxy, Reflect, BigInt, WeakRef, typed arrays over resizable and shared buffers with Atomics, optional chaining and the full regular expression syntax. It does not run modules.

QuickJS is QuickJS-ng 0.17.0, the C engine, compiled in: a static library on Kotlin/Native, a JNI library inside the jar and the AAR, and a WebAssembly module on JavaScript and Wasm. It runs ES2023 and most of what came after, it was between 3 and 12 times faster than Rhino on the JVM in our measurements, and it can cap the memory a script takes. It adds about 1 MB of native code per platform, about 360 KB gzipped on the web.

Choosing an engine compares them in full.

Binding your own functions and objects uses lambdas and property references, not reflection, so it behaves identically on every target and on both engines.

Targets

JVM (bytecode 11), Android, iOS, macOS, JavaScript, WebAssembly, Linux (x64 and arm64) and Windows, for both engines.

Installing it

KiteJS is on Maven Central. Add the engine you want, or both:

// build.gradle.kts
commonMain.dependencies {
    implementation("io.github.yuroyami:kitejs-rhino:0.7.0")       // KiteJs(Rhino)
    implementation("io.github.yuroyami:kitejs-quickjs:0.7.0")     // KiteJs(QuickJs)
    implementation("io.github.yuroyami:kitejs-coroutines:0.7.0")  // optional
}

The last artifact puts either engine behind suspending functions: awaiting a promise, handing a Deferred to a script, host functions that suspend, and cancellation that stops a running script. The kitejs artifact from earlier releases still works and brings Rhino with it, along with the old KiteJs { }, which now opens Rhino and is deprecated in favour of KiteJs(Rhino) { }.

On JavaScript and Wasm, QuickJS has to compile its WebAssembly module before the first engine opens: call QuickJs.load() once and await it. Everywhere else it returns at once.

Correctness

Both engines run one contract suite, on every target, that pins down how the API behaves.

Rhino's dedicated :kitejs-rhino:test262Parity task compares a pinned test262 corpus with upstream Rhino, recording intentional differences separately. Agreement includes tests both engines fail; it is a compatibility check, not a claim that every case conforms to ECMAScript.

Corpus replay is separate from the ordinary test suite and must be requested with -Ptest262Replay. Missing or mismatched inputs fail that requested run. The dedicated workflow replays one versioned artifact across its platform matrix and records executed counts and known differences per target. Coverage is established by those run results; the regular platform tests alone do not establish corpus coverage. See Testing for commands and evidence.

Licence

MPL-2.0, because KiteJS is a derivative of Mozilla Rhino. QuickJS-ng, which kitejs-quickjs carries in kitejs-quickjs/native/quickjs, keeps its MIT licence. See LICENSE and NOTICE.

About

A JavaScript engine for Kotlin multiplatform, Android, iOS, JVM and JS. Based on Mozilla Rhino ported to pure Kotlin Multiplatform

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages