Skip to content

Commit

Permalink
stream: use ArrayBufferPrototypeGetByteLength
Browse files Browse the repository at this point in the history
PR-URL: #45528
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
anonrig authored and danielleadams committed Jan 3, 2023
1 parent 203ca49 commit 2bde576
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
16 changes: 8 additions & 8 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const {
ArrayBuffer,
ArrayBufferPrototypeGetByteLength,
ArrayBufferPrototypeSlice,
ArrayPrototypePush,
ArrayPrototypeShift,
Expand Down Expand Up @@ -93,7 +94,6 @@ const {
ArrayBufferViewGetBuffer,
ArrayBufferViewGetByteLength,
ArrayBufferViewGetByteOffset,
ArrayBufferGetByteLength,
AsyncIterator,
cloneAsUint8Array,
copyArrayBuffer,
Expand Down Expand Up @@ -667,7 +667,7 @@ class ReadableStreamBYOBRequest {

const viewByteLength = ArrayBufferViewGetByteLength(view);
const viewBuffer = ArrayBufferViewGetBuffer(view);
const viewBufferByteLength = ArrayBufferGetByteLength(viewBuffer);
const viewBufferByteLength = ArrayBufferPrototypeGetByteLength(viewBuffer);

if (isDetachedBuffer(viewBuffer)) {
throw new ERR_INVALID_STATE.TypeError('Viewed ArrayBuffer is detached');
Expand Down Expand Up @@ -906,7 +906,7 @@ class ReadableStreamBYOBReader {

const viewByteLength = ArrayBufferViewGetByteLength(view);
const viewBuffer = ArrayBufferViewGetBuffer(view);
const viewBufferByteLength = ArrayBufferGetByteLength(viewBuffer);
const viewBufferByteLength = ArrayBufferPrototypeGetByteLength(viewBuffer);

if (viewByteLength === 0 || viewBufferByteLength === 0) {
return PromiseReject(
Expand Down Expand Up @@ -1118,7 +1118,7 @@ class ReadableByteStreamController {
}
const chunkByteLength = ArrayBufferViewGetByteLength(chunk);
const chunkBuffer = ArrayBufferViewGetBuffer(chunk);
const chunkBufferByteLength = ArrayBufferGetByteLength(chunkBuffer);
const chunkBufferByteLength = ArrayBufferPrototypeGetByteLength(chunkBuffer);
if (chunkByteLength === 0 || chunkBufferByteLength === 0) {
throw new ERR_INVALID_STATE.TypeError(
'chunk ArrayBuffer is zero-length or detached');
Expand Down Expand Up @@ -2492,7 +2492,7 @@ function readableByteStreamControllerPullInto(
const buffer = ArrayBufferViewGetBuffer(view);
const byteOffset = ArrayBufferViewGetByteOffset(view);
const byteLength = ArrayBufferViewGetByteLength(view);
const bufferByteLength = ArrayBufferGetByteLength(buffer);
const bufferByteLength = ArrayBufferPrototypeGetByteLength(buffer);

let transferredBuffer;
try {
Expand Down Expand Up @@ -2795,7 +2795,7 @@ function readableByteStreamControllerFillPullIntoDescriptorFromQueue(
totalBytesToCopyRemaining,
headOfQueue.byteLength);
const destStart = byteOffset + desc.bytesFilled;
const arrayBufferByteLength = ArrayBufferGetByteLength(buffer);
const arrayBufferByteLength = ArrayBufferPrototypeGetByteLength(buffer);
if (arrayBufferByteLength - destStart < bytesToCopy) {
throw new ERR_INVALID_STATE.RangeError(
'view ArrayBuffer size is invalid');
Expand Down Expand Up @@ -2899,7 +2899,7 @@ function readableByteStreamControllerRespondInReadableState(
controller,
remainder,
0,
ArrayBufferGetByteLength(remainder));
ArrayBufferPrototypeGetByteLength(remainder));
}
desc.bytesFilled -= remainderSize;
readableByteStreamControllerCommitPullIntoDescriptor(
Expand All @@ -2921,7 +2921,7 @@ function readableByteStreamControllerRespondWithNewView(controller, view) {
const viewByteLength = ArrayBufferViewGetByteLength(view);
const viewByteOffset = ArrayBufferViewGetByteOffset(view);
const viewBuffer = ArrayBufferViewGetBuffer(view);
const viewBufferByteLength = ArrayBufferGetByteLength(viewBuffer);
const viewBufferByteLength = ArrayBufferPrototypeGetByteLength(viewBuffer);

if (stream[kState].state === 'closed') {
if (viewByteLength !== 0)
Expand Down
9 changes: 2 additions & 7 deletions lib/internal/webstreams/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const {
ArrayBufferPrototype,
ArrayBufferPrototypeGetByteLength,
ArrayBufferPrototypeSlice,
ArrayPrototypePush,
ArrayPrototypeShift,
Expand Down Expand Up @@ -109,10 +109,6 @@ function ArrayBufferViewGetByteOffset(view) {
return ReflectGet(view.constructor.prototype, 'byteOffset', view);
}

function ArrayBufferGetByteLength(view) {
return ReflectGet(ArrayBufferPrototype, 'byteLength', view);
}

function cloneAsUint8Array(view) {
const buffer = ArrayBufferViewGetBuffer(view);
const byteOffset = ArrayBufferViewGetByteOffset(view);
Expand Down Expand Up @@ -140,7 +136,7 @@ function transferArrayBuffer(buffer) {
}

function isDetachedBuffer(buffer) {
if (ArrayBufferGetByteLength(buffer) === 0) {
if (ArrayBufferPrototypeGetByteLength(buffer) === 0) {
// TODO(daeyeon): Consider using C++ builtin to improve performance.
try {
new Uint8Array(buffer);
Expand Down Expand Up @@ -244,7 +240,6 @@ module.exports = {
ArrayBufferViewGetBuffer,
ArrayBufferViewGetByteLength,
ArrayBufferViewGetByteOffset,
ArrayBufferGetByteLength,
AsyncIterator,
cloneAsUint8Array,
copyArrayBuffer,
Expand Down

0 comments on commit 2bde576

Please sign in to comment.