Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: improve the checker
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com
  • Loading branch information
daeyeon committed Aug 6, 2022
commit 6fd3ea1945472e708e017d2a3b6e22cd5637f105
15 changes: 14 additions & 1 deletion lib/internal/webstreams/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const {
} = internalBinding('buffer');

const {
isArrayBuffer,
isArrayBufferView,
isPromise,
} = require('internal/util/types');

Expand Down Expand Up @@ -130,17 +132,28 @@ function transferArrayBuffer(buffer) {
}

function isDetachedBuffer(buffer) {
if (!isArrayBuffer(buffer))
throw new ERR_INVALID_ARG_TYPE('buffer', 'ArrayBuffer', buffer);
if (ArrayBufferGetByteLength(buffer) === 0) {
Comment thread
LiviaMedeiros marked this conversation as resolved.
// TODO(daeyeon): Consider using C++ builtin to improve performance.
try {
new Uint8Array(buffer);
} catch {
} catch (error) {
assert(error.name === 'TypeError');
return true;
}
}
return false;
}

function isViewedArrayBufferDetached(view) {
if (!isArrayBufferView(view)) {
throw new ERR_INVALID_ARG_TYPE(
'view',
['Buffer', 'TypedArray', 'DataView'],
view,
);
}
return (
ArrayBufferViewGetByteLength(view) === 0 &&
isDetachedBuffer(ArrayBufferViewGetBuffer(view))
Expand Down