summaryrefslogtreecommitdiff
path: root/runtime/js/13_buffer.js
diff options
context:
space:
mode:
authorKenta Moriuchi <moriken@kimamass.com>2023-04-03 02:41:41 +0900
committerGitHub <noreply@github.com>2023-04-02 19:41:41 +0200
commit03edd48edd004cec091541e6b71095cfbc4b4c87 (patch)
tree72aed1dae803334b73479ffebc7ca8c83d10addf /runtime/js/13_buffer.js
parentad8d0c90d1887beb8a5f2c6d30f9dc71cc63e4fe (diff)
chore: Turn back on dlintPreferPrimordials (#17715)
Closes #17709
Diffstat (limited to 'runtime/js/13_buffer.js')
-rw-r--r--runtime/js/13_buffer.js32
1 files changed, 19 insertions, 13 deletions
diff --git a/runtime/js/13_buffer.js b/runtime/js/13_buffer.js
index 4534152f3..907b07128 100644
--- a/runtime/js/13_buffer.js
+++ b/runtime/js/13_buffer.js
@@ -7,9 +7,12 @@
import { assert } from "ext:deno_web/00_infra.js";
const primordials = globalThis.__bootstrap.primordials;
const {
+ ArrayBufferPrototypeGetByteLength,
TypedArrayPrototypeSubarray,
TypedArrayPrototypeSlice,
TypedArrayPrototypeSet,
+ TypedArrayPrototypeGetBuffer,
+ TypedArrayPrototypeGetByteLength,
MathFloor,
MathMin,
PromiseResolve,
@@ -28,12 +31,12 @@ const MAX_SIZE = 2 ** 32 - 2;
// from `src`.
// Returns the number of bytes copied.
function copyBytes(src, dst, off = 0) {
- const r = dst.byteLength - off;
- if (src.byteLength > r) {
+ const r = TypedArrayPrototypeGetByteLength(dst) - off;
+ if (TypedArrayPrototypeGetByteLength(src) > r) {
src = TypedArrayPrototypeSubarray(src, 0, r);
}
TypedArrayPrototypeSet(dst, src, off);
- return src.byteLength;
+ return TypedArrayPrototypeGetByteLength(src);
}
class Buffer {
@@ -57,15 +60,17 @@ class Buffer {
}
empty() {
- return this.#buf.byteLength <= this.#off;
+ return TypedArrayPrototypeGetByteLength(this.#buf) <= this.#off;
}
get length() {
- return this.#buf.byteLength - this.#off;
+ return TypedArrayPrototypeGetByteLength(this.#buf) - this.#off;
}
get capacity() {
- return this.#buf.buffer.byteLength;
+ return ArrayBufferPrototypeGetByteLength(
+ TypedArrayPrototypeGetBuffer(this.#buf),
+ );
}
truncate(n) {
@@ -85,7 +90,7 @@ class Buffer {
}
#tryGrowByReslice(n) {
- const l = this.#buf.byteLength;
+ const l = TypedArrayPrototypeGetByteLength(this.#buf);
if (n <= this.capacity - l) {
this.#reslice(l + n);
return l;
@@ -94,15 +99,16 @@ class Buffer {
}
#reslice(len) {
- assert(len <= this.#buf.buffer.byteLength);
- this.#buf = new Uint8Array(this.#buf.buffer, 0, len);
+ const ab = TypedArrayPrototypeGetBuffer(this.#buf);
+ assert(len <= ArrayBufferPrototypeGetByteLength(ab));
+ this.#buf = new Uint8Array(ab, 0, len);
}
readSync(p) {
if (this.empty()) {
// Buffer is empty, reset to recover space.
this.reset();
- if (p.byteLength === 0) {
+ if (TypedArrayPrototypeGetByteLength(p) === 0) {
// this edge case is tested in 'bufferReadEmptyAtEOF' test
return 0;
}
@@ -122,7 +128,7 @@ class Buffer {
}
writeSync(p) {
- const m = this.#grow(p.byteLength);
+ const m = this.#grow(TypedArrayPrototypeGetByteLength(p));
return copyBytes(p, this.#buf, m);
}
@@ -180,7 +186,7 @@ class Buffer {
// otherwise read directly into the internal buffer
const buf = shouldGrow
? tmp
- : new Uint8Array(this.#buf.buffer, this.length);
+ : new Uint8Array(TypedArrayPrototypeGetBuffer(this.#buf), this.length);
const nread = await r.read(buf);
if (nread === null) {
@@ -205,7 +211,7 @@ class Buffer {
// otherwise read directly into the internal buffer
const buf = shouldGrow
? tmp
- : new Uint8Array(this.#buf.buffer, this.length);
+ : new Uint8Array(TypedArrayPrototypeGetBuffer(this.#buf), this.length);
const nread = r.readSync(buf);
if (nread === null) {