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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! A collection of APIs for Javy.
//!
//! APIs are enabled through the the [`Config`](crate::Config).
//!
//! Example usage:
//! ```rust
//!
//! use javy::{Config, Runtime, from_js_error};
//! use anyhow::Result;
//!
//! fn main() -> Result<()> {
//! let mut config = Config::default();
//! config.text_encoding(true);
//! let runtime = Runtime::new(config)?;
//! let context = runtime.context();
//! context.with(|cx| {
//! cx.eval_with_options::<(), _>(
//! r#"
//! console.log(new TextEncoder().encode(""))
//! "#,
//! Default::default()
//! )
//! .map_err(|e| from_js_error(cx.clone(), e))
//! })?;
//! Ok(())
//! }
//!
//! ```
//!
//! ## Features
//!
//! ### `console`
//!
//! Adds an implementation of the `console.log` and `console.error`.
//!
//! ### `TextEncoding`
//!
//! Provides partial implementations of `TextEncoder` and `TextDecoder`.
//! Disabled by default.
//!
//! ### `Random`
//!
//! Overrides the implementation of `Math.random` to one that seeds
//! the RNG on first call to `Math.random`. This is helpful to enable when using
//! using a tool like Wizer to snapshot a [`Runtime`] so that the output of
//! `Math.random` relies on the WASI context used at runtime and not the WASI
//! context used when snapshotting.
//!
//! ### `StreamIO`
//!
//! Provides an implementation of `Javy.IO.readSync` and `Javy.IO.writeSync`.
//! Disabled by default. Note that it is strongly recommended to target
//! WASI preview 1 when enabling this configuration. To use this
//! configuration with WASI preview 2 or later, you cannot use Javy's
//! plugin initialization and it will not be compatible for use with the
//! Javy CLI. See [the extending Javy docs](/docs/docs-using-extending.md) for
//! more details on using a WASI preview 1 plugin.
//!
//! ### `JSON`
//! Provides an efficient implementation of JSON functions based on [`simd-json`](https://crates.io/crates/simd-json/0.13.10)
//! and [`serde_json`](https://crates.io/crates/serde_json)
//!
//! Disabled by default.
pub
pub
pub
pub
pub