diff --git a/kernel/fs/fs.go b/kernel/fs/fs.go index 34cdf7e..3bd9a11 100644 --- a/kernel/fs/fs.go +++ b/kernel/fs/fs.go @@ -181,7 +181,7 @@ func (s *Service) read(this js.Value, args []js.Value) any { // buf := make([]byte, length) // n, err := StdinBuf.Read(buf) // if err != nil { - // cb.Invoke(jsError(err)) + // cb.Invoke(jsError(err), 0) // return // } // js.CopyBytesToJS(jsbuf, buf[:n]) @@ -196,27 +196,27 @@ func (s *Service) read(this js.Value, args []js.Value) any { f, ok := s.fds[fd] s.mu.Unlock() if !ok { - cb.Invoke(jsError(syscall.EBADF)) + cb.Invoke(jsError(syscall.EBADF), 0) return } if rs, ok := f.File.(io.ReadSeeker); ok && !pos.IsNull() { _, err := rs.Seek(int64(pos.Int()), 0) if err != nil { - cb.Invoke(jsError(err)) + cb.Invoke(jsError(err), 0) return } } buf := make([]byte, length) n, err := f.Read(buf) - if err != nil && err != io.EOF { - cb.Invoke(jsError(err)) - return - } if n > 0 { js.CopyBytesToJS(jsbuf, buf[:n]) } + if err != nil && err != io.EOF { + cb.Invoke(jsError(err), n) + return + } cb.Invoke(nil, n) }() diff --git a/kernel/web/lib/syscall.js b/kernel/web/lib/syscall.js index a699d89..061dd40 100644 --- a/kernel/web/lib/syscall.js +++ b/kernel/web/lib/syscall.js @@ -58,12 +58,8 @@ globalThis.api = { // only significant signature change read(fd, bufsize, offset, length, position) { const buf = new Uint8Array(bufsize); - return new Promise((ok, err) => globalThis.fs.read(fd, buf, offset, length, position, (e) => { - if (e !== null) { - err(e); - } else { - ok(buf); - } + return new Promise(resolve => globalThis.fs.read(fd, buf, offset, length, position, (err, n) => { + resolve({err, buf, n}); })); }, readdir(path) { @@ -125,4 +121,4 @@ function cb(ok, err) { } -//# sourceURL=syscall.js \ No newline at end of file +//# sourceURL=syscall.js diff --git a/kernel/web/lib/wasm.js b/kernel/web/lib/wasm.js index 1241f6d..7677ea7 100644 --- a/kernel/web/lib/wasm.js +++ b/kernel/web/lib/wasm.js @@ -132,10 +132,9 @@ } globalThis.sys.call("fs.read", [fd, buffer.length, offset, length, position]) .then(res => { - buffer.set(res.value); - callback(null, res.value.length); - }) - .catch(err => callback(err)); + buffer.set(res.value.buf); + callback(res.value.err, res.value.n); + }); }, readdir(path, callback) { globalThis.sys.call("fs.readdir", [path]) @@ -692,4 +691,4 @@ } } })(); -//# sourceURL=wasm.js \ No newline at end of file +//# sourceURL=wasm.js