Crate javy

source ·
Expand description

Configurable JavaScript runtime for WebAssembly.

Example usage:

use anyhow::anyhow;
use javy::{Runtime, from_js_error};
let runtime = Runtime::default();
let context = runtime.context();

context.with(|cx| {
    let globals = this.globals();
    globals.set(
        "print_hello",
        Function::new(
            this.clone(),
            MutFn::new(move |_, _| {
                println!("Hello, world!");
            }),
        )?,
    )?;
});

context.with(|cx| {
    cx.eval_with_options(Default::default(), "print_hello();")
        .map_err(|e| from_js_error(cx.clone(), e))
        .map(|_| ())
});

§Core concepts

  • Runtime - The entrypoint for using the JavaScript runtime. Use a Config to configure behavior.

§Features

  • export_alloc_fns - exports alloc::canonical_abi_realloc and alloc::canonical_abi_free from generated WebAssembly for allocating and freeing memory
  • json - functions for converting between [quickjs::JSValueRef] and JSON byte slices
  • messagepack - functions for converting between [quickjs::JSValueRef] and MessagePack byte slices

Re-exports§

Modules§

Macros§

Structs§

  • A struct to hold the current Ctx and Values passed as arguments to Rust functions. A struct here is used to explicitly tie these values with a particular lifetime.
  • A configuration for Runtime.
  • A JavaScript Runtime.

Functions§