diff --git a/runtime/wasm/fs.wat b/runtime/wasm/fs.wat index cb0c50bd..f81edab2 100644 --- a/runtime/wasm/fs.wat +++ b/runtime/wasm/fs.wat @@ -25,6 +25,8 @@ (func $readdir (param anyref) (result (ref extern)))) (import "bindings" "file_exists" (func $file_exists (param anyref) (result (ref eq)))) + (import "bindings" "is_directory" + (func $is_directory (param anyref) (result (ref eq)))) (import "bindings" "rename" (func $rename (param anyref) (param anyref))) (import "jslib" "wrap" (func $wrap (param anyref) (result (ref eq)))) (import "jslib" "unwrap" (func $unwrap (param (ref eq)) (result anyref))) @@ -141,10 +143,15 @@ (data $caml_sys_is_directory "caml_sys_is_directory") - (func (export "caml_sys_is_directory") (param (ref eq)) (result (ref eq)) - ;; ZZZ - (call $log_str - (array.new_data $string $caml_sys_is_directory - (i32.const 0) (i32.const 21))) - (ref.i31 (i32.const 0))) + (func (export "caml_sys_is_directory") + (param $name (ref eq)) (result (ref eq)) + (try + (do + (return + (call $is_directory + (call $unwrap + (call $caml_jsstring_of_string (local.get $name)))))) + (catch $javascript_exception + (call $caml_handle_sys_error (pop externref)) + (return (ref.i31 (i32.const 0)))))) ) diff --git a/runtime/wasm/runtime.js b/runtime/wasm/runtime.js index c40c649b..059f5b9c 100644 --- a/runtime/wasm/runtime.js +++ b/runtime/wasm/runtime.js @@ -437,6 +437,7 @@ unlink: (p) => fs.unlinkSync(p), readdir: (p) => fs.readdirSync(p), file_exists: (p) => +fs.existsSync(p), + is_directory: (p) => +fs.lstatSync(p).isDirectory(), rename: (o, n) => fs.renameSync(o, n), throw: (e) => { throw e;