SharedArrayBuffer.prototype.grow()
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The grow()
method of SharedArrayBuffer
instances grows the SharedArrayBuffer
to the specified size, in bytes.
Syntax
grow(newLength)
Parameters
newLength
-
The new length, in bytes, to resize the
SharedArrayBuffer
to.
Return value
Exceptions
TypeError
-
Thrown if the
SharedArrayBuffer
is not growable. RangeError
-
Thrown if
newLength
is larger than themaxByteLength
of theSharedArrayBuffer
or smaller than thebyteLength
.
Description
The grow()
method grows a SharedArrayBuffer
to the size specified by the newLength
parameter, provided that the SharedArrayBuffer
is resizable and the new size is less than or equal to the maxByteLength
of the SharedArrayBuffer
. New bytes are initialized to 0.
Examples
Using grow()
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);
}
Specifications
Specification |
---|
Resizable ArrayBuffer and growable SharedArrayBuffer # sec-sharedarraybuffer.prototype.grow |
Browser compatibility
BCD tables only load in the browser