diff options
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/13_buffer.js | 32 | ||||
-rw-r--r-- | runtime/js/99_main.js | 76 |
2 files changed, 57 insertions, 51 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) { diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 956f35d0a..fa16cc1f4 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -411,25 +411,25 @@ function bootstrapMainRuntime(runtimeOptions) { throw new Error("Worker runtime already bootstrapped"); } - const [ - args, - cpuCount, - debugFlag, - denoVersion, - locale, - location_, - noColor, - isTty, - tsVersion, - unstableFlag, - pid, - ppid, - target, - v8Version, - userAgent, - inspectFlag, - _, - ] = runtimeOptions; + const { + 0: args, + 1: cpuCount, + 2: debugFlag, + 3: denoVersion, + 4: locale, + 5: location_, + 6: noColor, + 7: isTty, + 8: tsVersion, + 9: unstableFlag, + 10: pid, + 11: ppid, + 12: target, + 13: v8Version, + 14: userAgent, + 15: inspectFlag, + // 16: enableTestingFeaturesFlag + } = runtimeOptions; performance.setTimeOrigin(DateNow()); globalThis_ = globalThis; @@ -519,25 +519,25 @@ function bootstrapWorkerRuntime( throw new Error("Worker runtime already bootstrapped"); } - const [ - args, - cpuCount, - debugFlag, - denoVersion, - locale, - location_, - noColor, - isTty, - tsVersion, - unstableFlag, - pid, - _ppid, - target, - v8Version, - _userAgent, - _inspectFlag, - enableTestingFeaturesFlag, - ] = runtimeOptions; + const { + 0: args, + 1: cpuCount, + 2: debugFlag, + 3: denoVersion, + 4: locale, + 5: location_, + 6: noColor, + 7: isTty, + 8: tsVersion, + 9: unstableFlag, + 10: pid, + // 11: ppid, + 12: target, + 13: v8Version, + // 14: userAgent, + // 15: inspectFlag, + 16: enableTestingFeaturesFlag, + } = runtimeOptions; performance.setTimeOrigin(DateNow()); globalThis_ = globalThis; |