From 2bde5768222a9f8665a32fcf53d8594f017078a8 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Mon, 21 Nov 2022 17:45:16 -0500 Subject: [PATCH] stream: use ArrayBufferPrototypeGetByteLength PR-URL: https://github.com/nodejs/node/pull/45528 Reviewed-By: Antoine du Hamel Reviewed-By: Minwoo Jung --- lib/internal/webstreams/readablestream.js | 16 ++++++++-------- lib/internal/webstreams/util.js | 9 ++------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/internal/webstreams/readablestream.js b/lib/internal/webstreams/readablestream.js index 252f8eaa1a8780..bbc47f49643425 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -4,6 +4,7 @@ const { ArrayBuffer, + ArrayBufferPrototypeGetByteLength, ArrayBufferPrototypeSlice, ArrayPrototypePush, ArrayPrototypeShift, @@ -93,7 +94,6 @@ const { ArrayBufferViewGetBuffer, ArrayBufferViewGetByteLength, ArrayBufferViewGetByteOffset, - ArrayBufferGetByteLength, AsyncIterator, cloneAsUint8Array, copyArrayBuffer, @@ -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'); @@ -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( @@ -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'); @@ -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 { @@ -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'); @@ -2899,7 +2899,7 @@ function readableByteStreamControllerRespondInReadableState( controller, remainder, 0, - ArrayBufferGetByteLength(remainder)); + ArrayBufferPrototypeGetByteLength(remainder)); } desc.bytesFilled -= remainderSize; readableByteStreamControllerCommitPullIntoDescriptor( @@ -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) diff --git a/lib/internal/webstreams/util.js b/lib/internal/webstreams/util.js index 0e260d074c73c2..1cf2d3a1874b10 100644 --- a/lib/internal/webstreams/util.js +++ b/lib/internal/webstreams/util.js @@ -1,7 +1,7 @@ 'use strict'; const { - ArrayBufferPrototype, + ArrayBufferPrototypeGetByteLength, ArrayBufferPrototypeSlice, ArrayPrototypePush, ArrayPrototypeShift, @@ -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); @@ -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); @@ -244,7 +240,6 @@ module.exports = { ArrayBufferViewGetBuffer, ArrayBufferViewGetByteLength, ArrayBufferViewGetByteOffset, - ArrayBufferGetByteLength, AsyncIterator, cloneAsUint8Array, copyArrayBuffer,