Skip to content

Commit

Permalink
Wasm runtime: add Sys.rmdir
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Jan 25, 2025
1 parent a54d8b1 commit 06fc2d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions runtime/wasm/fs.wat
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
(import "bindings" "getcwd" (func $getcwd (result anyref)))
(import "bindings" "chdir" (func $chdir (param anyref)))
(import "bindings" "mkdir" (func $mkdir (param anyref) (param i32)))
(import "bindings" "rmdir" (func $rmdir (param anyref)))
(import "bindings" "unlink" (func $unlink (param anyref)))
(import "bindings" "readdir"
(func $readdir (param anyref) (result (ref extern))))
Expand Down Expand Up @@ -83,6 +84,16 @@
(call $caml_handle_sys_error (pop externref))
(return (ref.i31 (i32.const 0))))))

(func (export "caml_sys_rmdir")
(param $name (ref eq)) (result (ref eq))
(try
(do
(call $rmdir
(call $unwrap (call $caml_jsstring_of_string (local.get $name)))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))))
(ref.i31 (i32.const 0)))

(func (export "caml_sys_remove")
(param $name (ref eq)) (result (ref eq))
(try
Expand Down
1 change: 1 addition & 0 deletions runtime/wasm/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@
getcwd: () => (isNode ? process.cwd() : "/static"),
chdir: (x) => process.chdir(x),
mkdir: (p, m) => fs.mkdirSync(p, m),
rmdir: (p) => fs.rmdirSync(p),
unlink: (p) => fs.unlinkSync(p),
readdir: (p) => fs.readdirSync(p),
file_exists: (p) => +fs.existsSync(p),
Expand Down

0 comments on commit 06fc2d5

Please sign in to comment.