Expand description
Configurable JavaScript runtime for WebAssembly.
Example usage:
use anyhow::Result;
use javy::quickjs::{
function::{MutFn, Rest},
Ctx, Function, Value
};
use javy::{from_js_error, Runtime};
fn main() -> Result<()> {
let runtime = Runtime::default();
let context = runtime.context();
context.with(|cx| {
let globals = cx.globals();
globals.set(
"print_hello",
Function::new(
cx.clone(),
MutFn::new(|_: Ctx<'_>, _: Rest<Value<'_>>| {
println!("Hello, world!");
}),
)?,
)
})?;
context.with(|cx| {
cx.eval_with_options("print_hello();", Default::default())
.map_err(|e| from_js_error(cx.clone(), e))
.map(|_: ()| ())
})?;
Ok(())
}
§Core concepts
§Features
json
- functions for converting between [quickjs::JSValueRef
] and JSON byte slicesmessagepack
- functions for converting between [quickjs::JSValueRef
] and MessagePack byte slices
Re-exports§
pub use rquickjs as quickjs;
Macros§
- hold
- Alias for
Args::hold
- hold_
and_ release - Alias for [
Args::hold(cx, args).release()
]
Structs§
- Args
- A struct to hold the current
Ctx
andValue
s passed as arguments to Rust functions. A struct here is used to explicitly tie these values with a particular lifetime. - Config
- A configuration for
Runtime
. - Runtime
- A JavaScript Runtime.
Functions§
- from_
js_ error - Handles a JavaScript error or exception and converts to anyhow::Error.
- to_
js_ error - Converts an
anyhow::Error
to aJSError
. - to_
string_ lossy - Converts the JavaScript value to a string, replacing any invalid UTF-8 sequences with the Unicode replacement character (U+FFFD).
- val_
to_ string - Retrieves the string representation of a JavaScript value.