1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
//! Configurable JavaScript runtime for WebAssembly.
//!
//! Example usage:
//! ```
//! # use anyhow::anyhow;
//! # use javy::{quickjs::JSValue, Runtime};
//! let runtime = Runtime::default();
//! let context = runtime.context();
//! context
//! .global_object()
//! .unwrap()
//! .set_property(
//! "print",
//! context
//! .wrap_callback(move |_ctx, _this, args| {
//! let str = args
//! .first()
//! .ok_or(anyhow!("Need to pass an argument"))?
//! .to_string();
//! println!("{str}");
//! Ok(JSValue::Undefined)
//! })
//! .unwrap(),
//! )
//! .unwrap();
//! context.eval_global("hello.js", "print('hello!');").unwrap();
//! ```
//!
//! ## 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
pub use config::Config;
pub use quickjs_wasm_rs as quickjs;
pub use runtime::Runtime;
pub mod alloc;
mod config;
mod runtime;
#[cfg(feature = "messagepack")]
pub mod messagepack;
#[cfg(feature = "json")]
pub mod json;