Function mozjs::jsapi::JS::CopyArrayBuffer

source ·
pub unsafe extern "C" fn CopyArrayBuffer(
    cx: *mut JSContext,
    maybeArrayBuffer: Handle<*mut JSObject>
) -> *mut JSObject
Expand description

Create a new ArrayBuffer, whose bytes are set to the values of the bytes in the provided ArrayBuffer.

|maybeArrayBuffer| is asserted to be non-null. An error is thrown if |maybeArrayBuffer| would fail the |IsArrayBufferObject| test given further below or if |maybeArrayBuffer| is detached.

|maybeArrayBuffer| may store its contents in any fashion (i.e. it doesn’t matter whether |maybeArrayBuffer| was allocated using |JS::NewArrayBuffer|, |JS::NewExternalArrayBuffer|, or any other ArrayBuffer-allocating function).

The newly-created ArrayBuffer is effectively creatd as if by |JS::NewArrayBufferWithContents| passing in |maybeArrayBuffer|’s internal data pointer and length, in a manner safe against |maybeArrayBuffer|’s data being moved around by the GC. In particular, the new ArrayBuffer will not behave like one created for WASM or asm.js, so it can be detached.