SharedArrayBuffer.prototype.maxByteLength

Baseline 2024
Newly available

Since July 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

SharedArrayBuffer 实例的 maxByteLength 访问器属性返回当前 SharedArrayBuffer 可以增大到的最大长度(以字节为单位)。

描述

maxByteLength 属性是一个访问器属性,其设置访问器函数为 undefined,因此你只能读取该属性。该属性的值在构造数组时确定。通过 SharedArrayBuffer() 构造函数的 maxByteLength 选项来设置该值,并且无法更改。

如果当前 SharedArrayBuffer 构造时时没有指定 maxByteLength 的值,这个属性会返回一个等于 SharedArrayBufferbyteLength 属性值的数值。

示例

使用 maxByteLength

在这个示例中,我们创建一个 8 字节缓冲区,该缓冲区可调整到的最大长度是 16 字节,然后返回其 maxByteLength

js
const buffer = new SharedArrayBuffer(8, { maxByteLength: 16 });

buffer.maxByteLength; // 16

规范

Specification
ECMAScript® 2025 Language Specification
# sec-get-sharedarraybuffer.prototype.maxbytelength

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
maxByteLength

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

参见