No description
Find a file
2022-10-03 00:37:26 +02:00
.github/workflows fix github action 2021-02-04 21:52:25 +01:00
examples Format + fix warning in examples 2020-05-25 17:00:08 +02:00
libquickjs-sys added date validation 2022-08-13 18:07:09 +02:00
src fix: cargo warnings 2022-10-03 00:37:26 +02:00
.gitignore Ignore .vscode 2021-02-04 21:52:25 +01:00
Cargo.toml fix more date formats, now passes all tests 2022-08-13 15:02:04 +02:00
CHANGELOG.md Update quickjs to 2021-03-27 2021-06-08 21:24:47 +00:00
justfile build: Valgrind: Show error list 2021-08-10 01:08:26 +02:00
LICENSE.txt Initial commit with working project. 2019-07-16 09:41:39 +02:00
README.md (cargo-release) version 0.4.1 2021-03-15 15:13:48 +01:00
release.toml Add cargo-release config 2020-05-27 10:06:27 +02:00
shell.nix Add shell.nix for Nix OS development 2020-07-09 01:50:41 +02:00

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.

Quickstart

[dependencies]
quick-js = "0.4.1"
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();

Optional Features

The crate supports the following features:

  • chrono: 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

  • log: allows forwarding console.log messages to the log crate. Note: must be enabled with ContextBuilder::console(quick_js::console::LogConsole);

  • patched Enabled automatically for some other features, like bigint. You should not need to enable this manually. Applies QuickJS patches that can be found in libquickjs-sys/embed/patches directory.

Installation

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

Windows Support

Windows is only supported with the MSYS2 environment and x86_64-pc-windows-gnu target architecture.

If you have MSYS2 installed and the MSYS bin directory in your path, you can compile quickjs with cargo build --target="x86_64-pc-windows-gnu".

The target can also be configured permanently via a cargo config file or the CARGO_BUILD_TARGET env var.

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

You then need to disable the bundled feature in the libquickjs-sys crate to force using the system version.