docs.rodeo

MDN Web Docs mirror

SharedArrayBuffer.prototype.grow()

{{JSRef}} 

The grow() method of {{jsxref("SharedArrayBuffer")}}  instances grows the SharedArrayBuffer to the specified size, in bytes.

Syntax

grow(newLength)

Parameters

Return value

None ({{jsxref("undefined")}} ).

Exceptions

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 {{jsxref("SharedArrayBuffer/maxByteLength", "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 {{jsxref("SharedArrayBuffer/growable", "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

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN