summaryrefslogtreecommitdiff
path: root/runtime/js
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/js')
-rw-r--r--runtime/js/12_io.js15
-rw-r--r--runtime/js/40_write_file.js21
2 files changed, 16 insertions, 20 deletions
diff --git a/runtime/js/12_io.js b/runtime/js/12_io.js
index 1dd162965..213e0a1ee 100644
--- a/runtime/js/12_io.js
+++ b/runtime/js/12_io.js
@@ -7,7 +7,6 @@
((window) => {
const core = window.Deno.core;
- const { DOMException } = window.__bootstrap.domException;
const {
Uint8Array,
ArrayPrototypePush,
@@ -123,7 +122,8 @@
async function readAllInner(r, options) {
const buffers = [];
const signal = options?.signal ?? null;
- while (!signal?.aborted) {
+ while (true) {
+ signal?.throwIfAborted();
const buf = new Uint8Array(READ_PER_ITER);
const read = await r.read(buf);
if (typeof read == "number") {
@@ -132,9 +132,7 @@
break;
}
}
- if (signal?.aborted) {
- throw new DOMException("The read operation was aborted.", "AbortError");
- }
+ signal?.throwIfAborted();
return concatBuffers(buffers);
}
@@ -200,7 +198,8 @@
const buf = new Uint8Array(size + 1); // 1B to detect extended files
let cursor = 0;
const signal = options?.signal ?? null;
- while (!signal?.aborted && cursor < size) {
+ while (cursor < size) {
+ signal?.throwIfAborted();
const sliceEnd = MathMin(size + 1, cursor + READ_PER_ITER);
const slice = buf.subarray(cursor, sliceEnd);
const read = await r.read(slice);
@@ -210,9 +209,7 @@
break;
}
}
- if (signal?.aborted) {
- throw new DOMException("The read operation was aborted.", "AbortError");
- }
+ signal?.throwIfAborted();
// Handle truncated or extended files during read
if (cursor > size) {
diff --git a/runtime/js/40_write_file.js b/runtime/js/40_write_file.js
index 6ced4e066..bb3f91789 100644
--- a/runtime/js/40_write_file.js
+++ b/runtime/js/40_write_file.js
@@ -13,9 +13,7 @@
data,
options = {},
) {
- if (options?.signal?.aborted) {
- throw new DOMException("The write operation was aborted.", "AbortError");
- }
+ options.signal?.throwIfAborted();
if (options.create !== undefined) {
const create = !!options.create;
if (!create) {
@@ -73,14 +71,15 @@
const signal = options?.signal ?? null;
let nwritten = 0;
- while (!signal?.aborted && nwritten < data.length) {
- nwritten += await file.write(TypedArrayPrototypeSubarray(data, nwritten));
- }
-
- file.close();
-
- if (signal?.aborted) {
- throw new DOMException("The write operation was aborted.", "AbortError");
+ try {
+ while (nwritten < data.length) {
+ signal?.throwIfAborted();
+ nwritten += await file.write(
+ TypedArrayPrototypeSubarray(data, nwritten),
+ );
+ }
+ } finally {
+ file.close();
}
}