From 320ce8b27b1ffa5218af8041d1ffe12b9aede192 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Mon, 21 Nov 2022 08:59:01 -0500 Subject: [PATCH] fixup! util: add isArrayBufferDetached method --- doc/api/util.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/api/util.md b/doc/api/util.md index 6d3ed728e2888a8..1af3fff2059a50f 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -2034,15 +2034,18 @@ added: REPLACEME * Returns: {boolean} Returns `true` if the value is a built-in [`ArrayBuffer`][] and -is detached. Detached arrays have a byte length of 0, which prevents -JavaScript from ever accessing underlying backing store. - -For example, we can end up with a detached buffer when using a BYOB -(bring your own buffer) on a ReadableStream. +is detached. For example, we can end up with a detached buffer +when using a BYOB (bring your own buffer) on a ReadableStream. +Detached arrays have a `byteLength` of 0, and their contents can +not be accessed in JavaScript. ```js util.types.isArrayBufferDetached(null); // Returns false util.types.isArrayBufferDetached(new ArrayBuffer()); // Returns false + +const { buffer } = new Uint8Array([1, 2, 3]); +new MessageChannel().port1.postMessage('', [buffer]); +util.types.isArrayBufferDetached(buffer); // Returns true ``` ### `util.types.isArrayBufferView(value)`