Skip to content

Commit 9e2e566

Browse files
committed
fs_mem: convert file.data back to non-resizable arraybuffer after closing
1 parent 9bccc5b commit 9e2e566

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/fs_mem.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ export class OpenFile extends Fd {
6161
return wasi.ERRNO_SUCCESS;
6262
}
6363

64+
fd_close(): number {
65+
// convert file.data back to a non-resizable arraybuffer after
66+
// closing, otherwise using it in web api (e.g. creating a
67+
// Response object) could throw. see:
68+
//
69+
// https://webidl.spec.whatwg.org/#AllowResizable
70+
// https://issues.chromium.org/issues/40249433
71+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1842773
72+
if (
73+
this.file.data.buffer instanceof ArrayBuffer &&
74+
this.file.data.buffer.resizable
75+
) {
76+
this.file.data = new Uint8Array(this.file.data);
77+
}
78+
return wasi.ERRNO_SUCCESS;
79+
}
80+
6481
fd_fdstat_get(): { ret: number; fdstat: wasi.Fdstat | null } {
6582
return { ret: 0, fdstat: new wasi.Fdstat(wasi.FILETYPE_REGULAR_FILE, 0) };
6683
}

0 commit comments

Comments
 (0)