Skip to content

Commit

Permalink
test: add util.types tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Nov 21, 2022
1 parent 7aae649 commit b1bf33f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/util/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function isBigUint64Array(value) {
}

function isArrayBufferDetached(value) {
if (ArrayBufferPrototypeGetByteLength(value) === 0) {
if (value instanceof ArrayBuffer && ArrayBufferPrototypeGetByteLength(value) === 0) {
return _isArrayBufferDetached(value);
}
return false;
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-util-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ for (const [ value, _method ] of [
}
}

// Check detached array buffers.
{
[null, undefined].forEach((entry) => assert(types.isArrayBufferDetached(entry) === false));

const { buffer } = new Uint8Array([1, 2, 3]);
new MessageChannel().port1.postMessage('', [buffer]);
assert(types.isArrayBufferDetached(buffer));
}

// Check boxed primitives.
[
new Boolean(),
Expand Down

0 comments on commit b1bf33f

Please sign in to comment.