Skip to content

Commit b1bf33f

Browse files
committed
test: add util.types tests
1 parent 7aae649 commit b1bf33f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/internal/util/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function isBigUint64Array(value) {
5858
}
5959

6060
function isArrayBufferDetached(value) {
61-
if (ArrayBufferPrototypeGetByteLength(value) === 0) {
61+
if (value instanceof ArrayBuffer && ArrayBufferPrototypeGetByteLength(value) === 0) {
6262
return _isArrayBufferDetached(value);
6363
}
6464
return false;

test/parallel/test-util-types.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ for (const [ value, _method ] of [
6767
}
6868
}
6969

70+
// Check detached array buffers.
71+
{
72+
[null, undefined].forEach((entry) => assert(types.isArrayBufferDetached(entry) === false));
73+
74+
const { buffer } = new Uint8Array([1, 2, 3]);
75+
new MessageChannel().port1.postMessage('', [buffer]);
76+
assert(types.isArrayBufferDetached(buffer));
77+
}
78+
7079
// Check boxed primitives.
7180
[
7281
new Boolean(),

0 commit comments

Comments
 (0)