diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-07-03 16:58:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-03 16:58:08 +0200 |
commit | 6137c8046d2d1bf4145a72aa634270c7aaf23341 (patch) | |
tree | 85428d5bb447b7e17323b4d6187e7b4124d17d68 /runtime/js/12_io.js | |
parent | d4de477ef903e2e47c6427e14f0fe543106b1297 (diff) |
refactor: use primordials in runtime/, part1 (#11241)
Diffstat (limited to 'runtime/js/12_io.js')
-rw-r--r-- | runtime/js/12_io.js | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/runtime/js/12_io.js b/runtime/js/12_io.js index d2b2127a6..2380e0283 100644 --- a/runtime/js/12_io.js +++ b/runtime/js/12_io.js @@ -7,6 +7,12 @@ ((window) => { const core = window.Deno.core; + const { + Uint8Array, + ArrayPrototypePush, + TypedArrayPrototypeSubarray, + TypedArrayPrototypeSet, + } = window.__bootstrap.primordials; const DEFAULT_BUFFER_SIZE = 32 * 1024; // Seek whence values. // https://golang.org/pkg/io/#pkg-constants @@ -36,7 +42,9 @@ } else { let nwritten = 0; while (nwritten < result) { - nwritten += await dst.write(b.subarray(nwritten, result)); + nwritten += await dst.write( + TypedArrayPrototypeSubarray(b, nwritten, result), + ); } n += nwritten; } @@ -56,7 +64,7 @@ break; } - yield b.subarray(0, result); + yield TypedArrayPrototypeSubarray(b, 0, result); } } @@ -72,7 +80,7 @@ break; } - yield b.subarray(0, result); + yield TypedArrayPrototypeSubarray(b, 0, result); } } @@ -119,7 +127,7 @@ const buf = new Uint8Array(READ_PER_ITER); const read = await r.read(buf); if (typeof read == "number") { - buffers.push(new Uint8Array(buf.buffer, 0, read)); + ArrayPrototypePush(buffers, new Uint8Array(buf.buffer, 0, read)); } else { break; } @@ -137,7 +145,7 @@ let n = 0; for (const buf of buffers) { - contents.set(buf, n); + TypedArrayPrototypeSet(contents, buf, n); n += buf.byteLength; } @@ -151,7 +159,7 @@ const buf = new Uint8Array(READ_PER_ITER); const read = r.readSync(buf); if (typeof read == "number") { - buffers.push(new Uint8Array(buf.buffer, 0, read)); + ArrayPrototypePush(buffers, new Uint8Array(buf.buffer, 0, read)); } else { break; } @@ -166,7 +174,7 @@ let n = 0; for (const buf of buffers) { - contents.set(buf, n); + TypedArrayPrototypeSet(contents, buf, n); n += buf.byteLength; } |