A configurable JavaScript runtime for WebAssembly.
Uses QuickJS through the quickjs-wasm-rs
crate to evalulate JavaScript source code or QuickJS bytecode.
```rust use anyhow::{anyhow, Result}; use javy::{quickjs::JSValue, Runtime};
fn main() -> Result<()> { let runtime = Runtime::default(); let context = runtime.context(); context.globalobject()?.setproperty( "print", context.wrapcallback(move |ctx, this, args| { let str = args .first() .okor(anyhow!("Need to pass an argument"))? .tostring(); println!("{str}"); Ok(JSValue::Undefined) })?, )?; context.evalglobal("hello.js", "print('hello!');")?; Ok(()) } ```
Create a Runtime
and use the reference returned by context()
to add functions and evaluate source code.
json
- transcoding functions for converting between JSValueRef
and JSONmessagepack
- transcoding functions for converting between JSValueRef
and MessagePackTo publish this crate to crates.io, run ./publish.sh
.
This crate can be compiled using a custom WASI SDK. When building this crate, set the QUICKJS_WASM_SYS_WASI_SDK_PATH
environment variable to the absolute path where you installed the SDK.