SharedArrayBuffer.prototype.grow()
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
SharedArrayBuffer 实例的 grow() 方法将 SharedArrayBuffer 增长到指定大小(以字节为单位)。
¥The grow() method of SharedArrayBuffer instances grows the SharedArrayBuffer to the specified size, in bytes.
语法
参数
返回值
例外情况
¥Exceptions
TypeError-
如果
SharedArrayBuffer不可增长,则抛出该异常。 RangeError-
如果
newLength大于SharedArrayBuffer的maxByteLength或小于byteLength,则抛出。
描述
¥Description
grow() 方法将 SharedArrayBuffer 增长到 newLength 参数指定的大小,前提是 SharedArrayBuffer 是 growable,并且新大小小于或等于 SharedArrayBuffer 的 maxByteLength。新字节被初始化为 0。
¥The grow() method grows a SharedArrayBuffer to the size specified by the newLength parameter, provided that the SharedArrayBuffer is growable and the new size is less than or equal to the maxByteLength of the SharedArrayBuffer. New bytes are initialized to 0.
示例
使用增长()
¥Using grow()
在此示例中,我们创建一个可增长到最大长度 16 字节的 8 字节缓冲区,然后检查其 growable 属性,如果 growable 返回 true,则增长它:
¥In this example, we create a 8-byte buffer that is growable to a max length of 16 bytes, then check its growable property, growing it if growable returns true:
const buffer = new SharedArrayBuffer(8, { maxByteLength: 16 });
if (buffer.growable) {
console.log("SAB is growable!");
buffer.grow(12);
}
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-sharedarraybuffer.prototype.grow |
浏览器兼容性
BCD tables only load in the browser