#javascript #quickjs #js #run-time #interpreter #big-integer

quickjs-rusty

A rusty QuickJS (QuickJS-NG) Javascript engine wrapper, and more

5 releases

new 0.7.0 Jan 9, 2025
0.6.3 Jul 7, 2024
0.6.2 Jul 2, 2024
0.6.1 Jun 30, 2024
0.6.0 Jun 19, 2024

#1188 in Web programming

Download history 28/week @ 2024-09-22 17/week @ 2024-09-29 9/week @ 2024-10-06 4/week @ 2024-10-13 1/week @ 2024-10-20 3/week @ 2024-11-17 1/week @ 2024-11-24 7/week @ 2024-12-01 22/week @ 2024-12-08 9/week @ 2024-12-15 4/week @ 2024-12-29 117/week @ 2025-01-05

130 downloads per month
Used in 5 crates (via hai_runtime)

MIT license

3MB
92K SLoC

C 81K SLoC // 0.0% comments JavaScript 6K SLoC // 0.0% comments Rust 4K SLoC // 0.1% comments Bitbake 454 SLoC // 0.1% comments Just 40 SLoC // 0.1% comments Shell 12 SLoC

quickjs-rusty

Crates.io docs.rs

QuickJS is a small and embeddable Javascript engine by Fabrice Bellard and Charlie Gordon. It supports the ES2023 specification including modules, asynchronous generators, proxies and BigInt.
Quickjs-NG is one of the most active forks of QuickJS, and it is maintained by the community focused on reigniting the project.

This crate allows you to easily access and use all the features of QuickJS from Rust. It also provides robust Rust-JS type conversion and interoperability capabilities.

Quickstart

cargo add quickjs-rusty
use quickjs_rusty::{Context, JsValue};

let context = Context::new().unwrap();

// Eval.

let value: String = c.eval_as("var x = 44; x.toString()").unwrap();
assert_eq!(&value, "44");

let value = context.eval_as::<u32>("1 + 2").unwrap();
assert_eq!(&value, 3);

// Callbacks.

context.add_callback("myCallback", |a: i32, b: i32| a + b).unwrap();

context.eval(r#"
    // x will equal 30
    var x = myCallback(10, 20);
"#).unwrap();

Note: This project is derived from quickjs-rs, but it has undergone significant restructuring. It features a completely different code structure and functional design compared to the original project.

Optional Features

The crate supports the following features:

  • serde: (default enabled). enable serde method from_js and to_js to transform between Rust types and js value in quickjs context. It should compatible with serde_json but not tested yet. See more on the example.
  • chrono: (default enabled). chrono integration
    • adds a JsValue::Date variant that can be (de)serialized to/from a JS Date
  • bigint: (default enabled). arbitrary precision integer support via num-bigint

Installation

We have a builtin quickjs-ng submodule, so you don't need to install quickjs-ng manually. We'll be at best effort to keep the submodule up-to-date with the latest quickjs-ng version.

Make sure you have Clang installed on your system.

Windows Support

quickjspp-rs can be used under target x86_64-pc-windows-msvc with Clang installed.

Dependencies

~1.4–5MB
~90K SLoC