Skip to content

Commit

Permalink
fixup: use isDetachedBuffer only
Browse files Browse the repository at this point in the history
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
  • Loading branch information
daeyeon committed Aug 4, 2022
1 parent 50c7728 commit 6f6ba3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
3 changes: 1 addition & 2 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ const {
extractSizeAlgorithm,
lazyTransfer,
isDetachedBuffer,
isViewedArrayBufferDetached,
isBrandCheck,
resetQueue,
setPromiseHandled,
Expand Down Expand Up @@ -684,7 +683,7 @@ class ReadableStreamBYOBRequest {
'This BYOB request has been invalidated');
}

if (isViewedArrayBufferDetached(view)) {
if (isDetachedBuffer(ArrayBufferViewGetBuffer(view))) {
throw new ERR_INVALID_STATE.TypeError('Viewed ArrayBuffer is detached');
}

Expand Down
18 changes: 4 additions & 14 deletions lib/internal/webstreams/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,14 @@ function transferArrayBuffer(buffer) {
}

function isDetachedBuffer(buffer) {
if (ArrayBufferGetByteLength(buffer) === 0) {
try {
new Uint8Array(buffer);
} catch {
return true;
}
try {
new Uint8Array(buffer);
} catch {
return true;
}
return false;
}

function isViewedArrayBufferDetached(view) {
return (
ArrayBufferViewGetByteLength(view) === 0 &&
isDetachedBuffer(ArrayBufferViewGetBuffer(view))
);
}

function dequeueValue(controller) {
assert(controller[kState].queue !== undefined);
assert(controller[kState].queueTotalSize !== undefined);
Expand Down Expand Up @@ -245,7 +236,6 @@ module.exports = {
isBrandCheck,
isDetachedBuffer,
isPromisePending,
isViewedArrayBufferDetached,
peekQueueValue,
resetQueue,
setPromiseHandled,
Expand Down

0 comments on commit 6f6ba3e

Please sign in to comment.