The grow()
method of SharedArrayBuffer
instances grows the SharedArrayBuffer
to the specified size, in bytes.
On this page
SharedArrayBuffer.prototype.grow()
Syntax
grow(newLength)
Parameters
-
newLength
-
The new length, in bytes, to resize the
SharedArrayBuffer
to.
Return value
None (undefined
).
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 growable 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
Browser compatibility
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
grow |
111 | 111 | No | 97 | 16.4 | 111 | No | 75 | 16.4 | 22.0 | No | 1.33 | 20.0.0 |
See also
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow