Skip to content

Commit 1323093

Browse files
committed
Fs_fake: fix offset computation
1 parent 2fee5f0 commit 1323093

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

compiler/tests-io/dune

+14
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,17 @@
8484
(compilation_mode whole_program)
8585
(flags
8686
(:standard --file "accentué"))))
87+
88+
(rule
89+
(with-stdout-to
90+
"file.txt"
91+
(echo test)))
92+
93+
(tests
94+
(names gh1856)
95+
(deps file.txt)
96+
(modes js)
97+
(js_of_ocaml
98+
(compilation_mode whole_program)
99+
(flags
100+
(:standard --file file.txt))))

compiler/tests-io/gh1856.ml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let () =
2+
let ch = open_in "/static/file.txt" in
3+
let b = Bytes.create 1024 in
4+
while input ch b 0 1024 > 0 do
5+
()
6+
done;
7+
close_in ch

runtime/js/fs_fake.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -472,17 +472,19 @@ class MlFakeFd {
472472
write(buf, pos, len, raise_unix) {
473473
if (this.file && (this.flags.wronly || this.flags.rdwr)) {
474474
var offset = this.offset;
475+
len = this.file.write(offset, buf, pos, len);
475476
this.offset += len;
476-
return this.file.write(offset, buf, pos, len);
477+
return len;
477478
}
478479
this.err_closed("write", raise_unix);
479480
}
480481

481482
read(buf, pos, len, raise_unix) {
482483
if (this.file && !this.flags.wronly) {
483484
var offset = this.offset;
485+
len = this.file.read(offset, buf, pos, len);
484486
this.offset += len;
485-
return this.file.read(offset, buf, pos, len);
487+
return len;
486488
}
487489
this.err_closed("read", raise_unix);
488490
}

0 commit comments

Comments
 (0)