diff options
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/40_read_file.js | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/runtime/js/40_read_file.js b/runtime/js/40_read_file.js index 0ca8f56e9..1efd5338d 100644 --- a/runtime/js/40_read_file.js +++ b/runtime/js/40_read_file.js @@ -7,32 +7,44 @@ function readFileSync(path) { const file = openSync(path); - const contents = readAllSync(file); - file.close(); - return contents; + try { + const contents = readAllSync(file); + return contents; + } finally { + file.close(); + } } async function readFile(path) { const file = await open(path); - const contents = await readAll(file); - file.close(); - return contents; + try { + const contents = await readAll(file); + return contents; + } finally { + file.close(); + } } function readTextFileSync(path) { const file = openSync(path); - const contents = readAllSync(file); - file.close(); - const decoder = new TextDecoder(); - return decoder.decode(contents); + try { + const contents = readAllSync(file); + const decoder = new TextDecoder(); + return decoder.decode(contents); + } finally { + file.close(); + } } async function readTextFile(path) { const file = await open(path); - const contents = await readAll(file); - file.close(); - const decoder = new TextDecoder(); - return decoder.decode(contents); + try { + const contents = await readAll(file); + const decoder = new TextDecoder(); + return decoder.decode(contents); + } finally { + file.close(); + } } window.__bootstrap.readFile = { |