7 releases

✓ Uses Rust 2018 edition

0.3.0 Nov 2, 2019
0.2.3 Aug 30, 2019
0.2.0 Jul 30, 2019
0.1.0 Jul 22, 2019

#1 in #quickjs

Download history 120/week @ 2019-08-24 40/week @ 2019-08-31 32/week @ 2019-09-07 68/week @ 2019-09-14 42/week @ 2019-09-21 18/week @ 2019-09-28 14/week @ 2019-10-05 2/week @ 2019-10-12 21/week @ 2019-10-19 56/week @ 2019-10-26 38/week @ 2019-11-02 4/week @ 2019-11-09 23/week @ 2019-11-16 13/week @ 2019-11-23 29/week @ 2019-11-30

173 downloads per month

MIT license

2.5MB
68K SLoC

C 62K SLoC // 0.0% comments Rust 6K SLoC // 0.1% comments

quickjs-rs

Crates.io docs.rs [Build Status

A Rust wrapper for QuickJS.

QuickJS is a new, small Javascript engine by Fabrice Bellard and Charlie Gordon. It is fast and supports the full ES2020 specification.

This crate allows you to easily run and integrate with Javascript code from Rust.

Limitations

  • Windows is not supported yet

Quickstart

[dependencies]
quick-js = "0.3.0"
use quick_js::{Context, JsValue};

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

// Eval.

let value = context.eval("1 + 2").unwrap();
assert_eq!(value, JsValue::Int(3));

let value = context.eval_as::<String>(" var x = 100 + 250; x.toString() ").unwrap();
assert_eq!(&value, "350");

// 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();

Installation

By default, quickjs is bundled with the libquickjs-sys crate and automatically compiled, assuming you have the appropriate dependencies.

If you would like to use a system version instead, see below.

QuickJS will always be statically linked to your binary.

Features

The crate supports the following features:

  • chrono: adds chrono integration
    • adds a JsValue::Date variant that can be (de)serialized to/from a JS Date
  • bigint: arbitrary precision integer support via num-bigint
  • patched: applies QuickJS patches that can be found in libquickjs-sys/embed/patches directory.
  • log: allows forwarding console.log messages to the log crate. Note: must be enabled with ContextBuilder::console(quick_js::console::LogConsole);

System installation

To use the system installation, without the bundled feature, first install the required dependencies, and then compile and install quickjs.

# Debian/Ubuntu: apt-get install -y curl xz-utils build-essential gcc-multilib libclang-dev clang
mkdir quickjs 
curl -L https://bellard.org/quickjs/quickjs-2019-07-09.tar.xz | tar xJv -C quickjs --strip-components 1
cd quickjs
sudo make install

Dependencies