Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use javy_plugin_api::javy::{
};
use rand::RngCore;

pub const CRYPTO_JS: &str = include_str!("crypto.js");

pub fn bless_get_random_values(args: Args<'_>) -> Result<Value<'_>> {
let (cx, args) = args.release();
let (data, offset, length) = extract_args(&args, "Javy.Crypto.getRandomValues")?;
Expand Down
2 changes: 2 additions & 0 deletions src/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use javy_plugin_api::javy::{
};
use std::collections::HashMap;

pub const FETCH_JS: &str = include_str!("fetch.js");

/// A fetch-compliant HTTP client
pub fn bless_fetch_request(args: Args<'_>) -> Result<Value<'_>> {
let (cx, args) = args.release();
Expand Down
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ pub mod llm;
pub mod wasi;

#[cfg(feature = "crypto")]
use crypto::bless_get_random_values;
use crypto::{bless_get_random_values, CRYPTO_JS};

#[cfg(feature = "fetch")]
use fetch::bless_fetch_request;
use fetch::{bless_fetch_request, FETCH_JS};

#[cfg(feature = "llm")]
use llm::bless_llm_plugin;

#[cfg(feature = "wasip1")]
use wasi::PREVIEW_1_JS;

import_namespace!("bless_core_plugins");

#[export_name = "initialize_runtime"]
Expand Down Expand Up @@ -118,11 +121,11 @@ pub extern "C" fn initialize_runtime() {
)?;

#[cfg(feature = "crypto")]
ctx.eval::<(), _>(include_str!("crypto/crypto.js"))?;
ctx.eval::<(), _>(CRYPTO_JS)?;
#[cfg(feature = "fetch")]
ctx.eval::<(), _>(include_str!("fetch/fetch.js"))?;
ctx.eval::<(), _>(FETCH_JS)?;
#[cfg(feature = "wasip1")]
ctx.eval::<(), _>(include_str!("wasi/preview_1.js"))?;
ctx.eval::<(), _>(PREVIEW_1_JS)?;
Ok::<_, anyhow::Error>(())
})
.unwrap();
Expand Down
2 changes: 2 additions & 0 deletions src/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub(crate) use stat::wasi_preview1_path_filestat_get;
pub(crate) use symlink::wasi_preview1_path_symlink;
pub(crate) use unlink::wasi_preview1_path_unlink_file;

pub const PREVIEW_1_JS: &str = include_str!("preview_1.js");

#[inline]
pub fn process_error(ctx: Ctx<'_>, rs: i32) -> Result<()> {
let obj = JObject::new(ctx.clone())?;
Expand Down
Loading