Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d7b93e1
wasi open api implements
Joinhack May 19, 2025
1b497fd
wasi open api implements
Joinhack May 19, 2025
a8ec53d
support error message.
Joinhack May 20, 2025
de3476a
error message.
Joinhack May 20, 2025
8b5916a
implement the mkdir rmdir unlink.
Joinhack May 20, 2025
f398563
close support
Joinhack May 20, 2025
202f277
mkdir support
Joinhack May 20, 2025
f9b7165
open support
Joinhack May 20, 2025
a467c3f
rmdir support
Joinhack May 20, 2025
dce19e6
unlink support
Joinhack May 20, 2025
37226e0
refactor: use the single file for each api
Joinhack May 20, 2025
a5519ca
refactor:close mkdir open rmdir unlink
Joinhack May 21, 2025
b8a61a2
rename support
Joinhack May 22, 2025
90ece1e
stat support
Joinhack May 22, 2025
0d1b1f6
js wrapper rename stat
Joinhack May 22, 2025
7be31f1
fix the repr for stat
Joinhack May 23, 2025
bf2ac48
refactor: use global for last error
Joinhack May 24, 2025
0bdf98c
descriptor for file
Joinhack May 24, 2025
8708e62
support file descriptor close method.
Joinhack May 24, 2025
7a3268b
support seek and advise
Joinhack May 25, 2025
aa573f0
refactor: use macro for extract i64 from jsvalue
Joinhack May 25, 2025
a31d148
support sync and fdatasync for descriptor
Joinhack May 25, 2025
67c9af8
support stat for descriptor
Joinhack May 26, 2025
7d83d2f
support ftruncate for descriptor
Joinhack May 26, 2025
6b31b6a
support allocate for descriptor
Joinhack May 26, 2025
0cfc76c
rename fd
Joinhack May 26, 2025
82c6a05
comment for function
Joinhack May 26, 2025
f973213
refactor descriptor struct
Joinhack May 26, 2025
0ecdc7a
support tell for descriptor
Joinhack May 26, 2025
6c0bcf6
support touch for descriptor
Joinhack May 26, 2025
a28ff7b
support setflags for descriptor
Joinhack May 27, 2025
5066495
support readstring readall for descriptor
Joinhack May 28, 2025
f2bf362
support fatime fmtime for descriptor
Joinhack May 28, 2025
68bb4b7
support fatime fmtime for descriptor
Joinhack May 28, 2025
5ff79ac
fmt
Joinhack May 28, 2025
c75adbe
fix the issue
Joinhack May 29, 2025
97c544d
rename parameter name path_len to the prestat_ptr
Joinhack May 29, 2025
bf1180a
replace wasi with wasip1
Joinhack May 30, 2025
e51f134
Apply suggestions from code review
Joinhack Jun 6, 2025
7ee24c9
Apply suggestions from code review
Joinhack Jun 6, 2025
78bd0cb
Apply suggestions from code review
Joinhack Jun 6, 2025
e3ae7f3
Apply suggestions from code review
Joinhack Jun 6, 2025
0cc0319
Apply suggestions from code review
Joinhack Jun 6, 2025
5cb2f8f
fmt
Joinhack Jun 6, 2025
2c408c4
fix the compile issue
Joinhack Jun 6, 2025
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
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ javy-plugin-api = { version = "3.0.0", features = ["json"] }
rand = "0.8.5"
serde_json = "1.0.120"
serde = { version = "1.0.215", features = ["derive"] }
thiserror = "2.0.12"

[profile.release]
lto = true
Expand All @@ -29,4 +30,5 @@ opt-level = 3
crypto = []
fetch = []
llm = []
default = ["crypto", "fetch"]
wasip1 = []
default = ["crypto", "fetch", "wasip1"]
35 changes: 35 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ pub mod crypto;
pub mod fetch;
#[cfg(feature = "llm")]
pub mod llm;
#[cfg(feature = "wasip1")]
pub mod wasi;

#[cfg(feature = "crypto")]
use crypto::bless_get_random_values;
#[cfg(feature = "fetch")]
use fetch::bless_fetch_request;

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

Expand Down Expand Up @@ -61,6 +64,36 @@ pub extern "C" fn initialize_runtime() {
)?,
)?;

#[cfg(feature = "wasip1")]
{
macro_rules! bind {
(function, $l: ident) => {
let name = concat!("__javy_", stringify!($l));
ctx.globals().set(
name,
Function::new(
ctx.clone(),
MutFn::new(move |cx, args| {
let (cx, args) = hold_and_release!(cx, args);
wasi::$l(hold!(cx.clone(), args))
.map_err(|e| to_js_error(cx, e))
}),
)?,
)?;
};
}
bind!(function, wasi_preview1_open);
bind!(function, wasi_preview1_fd_prestat_dir_name);
bind!(function, wasi_preview1_path_create_directory);
bind!(function, wasi_preview1_path_remove_directory);
bind!(function, wasi_preview1_path_unlink_file);
bind!(function, wasi_preview1_close);
bind!(function, wasi_preview1_path_symlink);
bind!(function, wasi_preview1_path_link);
bind!(function, wasi_preview1_path_rename);
bind!(function, wasi_preview1_path_filestat_get);
}

#[cfg(feature = "llm")]
ctx.globals().set(
"BlessLLM",
Expand All @@ -87,6 +120,8 @@ pub extern "C" fn initialize_runtime() {
ctx.eval::<(), _>(include_str!("crypto/crypto.js"))?;
#[cfg(feature = "fetch")]
ctx.eval::<(), _>(include_str!("fetch/fetch.js"))?;
#[cfg(feature = "wasip1")]
ctx.eval::<(), _>(include_str!("wasi/preview_1.js"))?;
Ok::<_, anyhow::Error>(())
})
.unwrap();
Expand Down
21 changes: 21 additions & 0 deletions src/wasi/close.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use anyhow::{anyhow, bail, Result};
use javy_plugin_api::javy::{quickjs::Value, Args};

use super::{preview_1, process_error};

/// This function is used to close a file descriptor.
/// `fd`: The file descriptor to close.
pub fn wasi_preview1_close<'a>(args: Args<'a>) -> Result<Value<'a>> {
let (cx, args) = args.release();
let args_pat: &[Value<'_>] = &args.0;
let [fd, ..] = args_pat else {
bail!(
"close expects 1 parameter: the fd, Got: {} parameters.",
args.len()
);
};
let fd = fd.as_int().ok_or_else(|| anyhow!("fd must be a number"))?;
let rs = unsafe { preview_1::fd_close(fd) };
process_error(cx.clone(), rs)?;
Ok(Value::new_int(cx.clone(), rs))
}
Loading