Rust bindings for the JavaScriptCore engine.

Overview

JavaScriptCore API for Rust

crates docs

This library provides a Rust API for the JavaScriptCore engine with the following goals:

  • High-level API like the JavaScriptCore API for Swift
  • Wrap the low-level C++ API instead of jsc to avoid the dependency to GTK.

Getting Started

Evaluating a JavaScript script

use rusty_jsc::JSContext;

let mut context = JSContext::default();
let value = context.evaluate_script("'hello, world'", 1);
if let Some(value) = value {
    println!("{}", value.to_string(&context));
    // Prints:
    // hello, world
}

Callbacks from JavaScript to Rust

use rusty_jsc::{JSContext, JSValue};
use rusty_jsc_macros::callback;

// The JavaScript code calls this Rust function.
#[callback]
fn foo(_context: JSContext) {
    println!("hello from Rust land!");
}

fn main() {
    let mut context = JSContext::default();
    let callback = JSValue::callback(&context, Some(foo));
    let mut global = context.get_global_object();
    global.set_property(&context, "foo".to_string(), callback);
    context.evaluate_script("foo()", 1);
    // Prints:
    // hello from Rust land!
}

FAQ

What about the other JavaScriptCore bindings for Rust?

The wrappers in rusty_jsc are built against <JavaScriptCore/JavaScript.h> header rather than the jsc variant that requires GTK.

Why JavaScriptCore when there's already rusty_v8?

Bun has shown that JavaScriptCore is a worthy contender to V8 on the server-side, so let's bring it over to the Rust ecosystem as well.

How were the C++ low-level bindings generated?

I first used bindgen to do the rough conversion of JavaScript/JavaScript.h header and then cleaned it up by hand. The plan is to maintain the low-level bindings by hand.

You might also like...
Songbird bindings for python

Songbird-Py Songbird bindings for python. The goal is to provide an easy to use alternitive to Lavalink. Its written with rust-bindings to Songbird. S

Unopinionated low level API bindings focused on soundness, safety, and stronger types over raw FFI.

🔥 firehazard 🔥 Create a fire hazard by locking down your (Microsoft) Windows so nobody can escape (your security sandbox.) Unopinionated low level A

Python bindings for decancer.

decancer_py Python bindings for decancer. Installation You can get started with decancer_py by installing from PyPI: pip install -U decancer-py Usage

Kotlin bindings for yrs.

ykt Kotlin bindings for yrs. Getting started import uniffi.ykt.Doc fun main() { val doc = Doc() val text = doc.getText("my_text") val tx = doc

PyO3 bindings and Python interface to skani, a method for fast fast genomic identity calculation using sparse chaining.

🐍 ⛓️ 🧬 Pyskani PyO3 bindings and Python interface to skani, a method for fast fast genomic identity calculation using sparse chaining. 🗺️ Overview

pyrevm Blazing-fast Python bindings to revm

pyrevm Blazing-fast Python bindings to revm Quickstart make install make test Example Usage Here we show how you can fork from Ethereum mainnet and s

RocksDB-based queue with python bindings

RocksQ An inproc RocksDB-based queue with Python bindings. It is implemented in Rust. Features: max capacity limit in number of elements; size calcula

A library to generate bindings from Cairo ABI.

Cainome: bindings generation from Cairo ABI Cainome is a library to generate bindings from Cairo ABI. Cainome architecture provides a flexible way to

Keybinder to type diacrytical characters without needing to hack the layout itself. Supports bindings to the left Alt + letter

Ďíáǩříťíǩád I just thought that it's a shame the word diakritika does not have any diacritics in it. Key points diakritika is a simple Windows daemon

Comments
  • Question

    Question

    Hi! Thank you for this impressive work! When searching for rust javascriptcore libs I found also this https://github.com/tauri-apps/javascriptcore-rs. How your library differentiate from theirs?

    opened by tpisto 2
  • Building with cargo-wasi

    Building with cargo-wasi

    Hello, I'm trying to use cargo-wasi to build a rust app that uses rusty_jsc, but I'm seeing this error when I run cargo wasi build:

    ❯ cargo wasi run 
       Compiling rusty_jsc_sys v0.0.2
       Compiling anyhow v1.0.66
       Compiling rusty_jsc_sys v0.0.3
    error: library kind `framework` is only supported on Apple targets
    
    error: could not compile `rusty_jsc_sys` due to previous error
    warning: build failed, waiting for other jobs to finish...
    error: could not compile `rusty_jsc_sys` due to previous error
    

    My Cargo.toml is simple:

    [package]
    name = "project"
    version = "0.1.0"
    edition = "2021"
    
    # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
    
    [dependencies]
    rusty_jsc = "0.0.2"
    rusty_jsc_macros = "0.0.3"
    rusty_jsc_sys = "0.0.3"
    

    And the main.rs is just one of your examples:

    use rusty_jsc::JSContext;
    
    fn main() {
        let mut context = JSContext::default();
        let value = context.evaluate_script("'hello, world'", 1);
        if let Some(value) = value {
            println!("{}", value.to_string(&context));
        }
    }
    

    Any ideas? I'm new to the world of WASI so hopefully its something I just don't understand

    opened by Ethan-Arrowood 2
Owner
Pekka Enberg
Founder at ChiselStrike. Software engineer interested in distributed systems, cloud/edge computing, and databases. Previously @ScyllaDB & Linux kernel.
Pekka Enberg
Rust bindings to libcurl

curl-rust libcurl bindings for Rust Quick Start use std::io::{stdout, Write}; use curl::easy::Easy; // Print a web page onto stdout fn main() {

Alex Crichton 885 Jan 9, 2023
Rust bindings to the RVVM's public api

rvvm [WIP] Safe Rust bindings to the RVVM's public API. Provides the Rust-idiomatic interface to the RVVM public API. Implemented Virtual machine crea

null 3 Jan 9, 2023
⚡️ Python bindings for a rust implementation of aapleby's MurMurHash.

?? murmurh ?? ⚡️ Python bindings for a rust implementation of aapleby's MurMurHash. ?? Contributing Contributions are welcome! Please feel free to ope

Paul Leydier 6 Jan 14, 2023
"Rust bindings for the Matlab C API"

matlab-sys matlab-sys provides low level bindings to Matlab's C API. This allows writing MEX functions, using the C Matrix API, interacting with the C

null 11 Feb 28, 2023
nvim-oxi provides safe and idiomatic Rust bindings to the rich API exposed by the Neovim text editor.

?? nvim-oxi nvim-oxi provides safe and idiomatic Rust bindings to the rich API exposed by the Neovim text editor. The project is mostly intended for p

Riccardo Mazzarini 655 Jul 13, 2023
API bindings, CLI client and FUSE filesystem for Wiki.js written in Rust.

wikijs-rs API bindings, CLI client and FUSE filesystem for Wiki.js written in Rust. What's inside? Library: Rust bindings to Wiki.js's entire GraphQL

Sandro-Alessio Gierens 4 Sep 19, 2023
Pollard's p - 1, in rust, with python bindings

Pollard's p - 1 algorithm for factorization Written in rust, using pyo3 to provide python bindings and primesieve for fast prime enumeration. libprime

Robin Jadoul 4 Sep 26, 2023
Bindings for jsonpath-rust library

jsonpath-rust-bindings This package contains Python bindings for jsonpath-rust library by besok. The details regarding the JsonPath itself can be foun

Igor 4 Nov 7, 2023
Rust bindings to the tg geometry library

tg-sys tg-sys provides unsafe bindings to the tg library. See the documentation at https://github.com/tidwall/tg/blob/main/docs/API.md for details. Us

Cliff Dyer 5 Nov 13, 2023
hackernews_tui is a Terminal UI to browse Hacker News with vim-like key bindings.

hackernews_tui is written in Rust with the help of Cursive TUI library. It uses HN Algolia search APIs to get Hacker News data.

Thang Pham 364 Dec 28, 2022