Expand description
Zero-copy ArrayBuffer helpers built on QuickJS-NG primitives.
rquickjs doesn’t yet ship safe wrappers for QuickJS-NG’s
immutable ArrayBuffer
support, so we go through rquickjs::qjs::* directly. The two
capabilities exposed here are:
shared_array_buffer_view— create a freshArrayBufferthat borrows the bytes of an existing one (no memcpy), kept alive via a dup’dJSValuereference. The view is marked immutable, which is both a correctness guarantee (consumer mutations can’t leak into the source) and a hard safety rail (the only QuickJS code path that would lose our refcount handle is.transfer(), which immutability blocks at the JS layer).set_immutable— flip the immutable flag on an existingArrayBuffer(used when the source is a freshly-allocated buffer we own and want to seal before handing out).
These are used by Blob.stream() / Blob.slice() and by fetch’s
Response.body / Request.body getters to hand out aliased,
transfer-safe views into producer-owned storage.
Functions§
- set_
immutable - Mark an
ArrayBufferas immutable: subsequent writes through anyUint8Array/DataViewview silently fail (orTypeErrorin strict mode), and.transfer()throwsTypeError: ArrayBuffer is immutable. - shared_
array_ buffer_ view - Create a fresh, immutable
ArrayBufferthat shares storage withsourceat[offset..offset+len]without copying any bytes. The returned buffer holds a dup’d reference to the source’sJSValue, so the backing allocation stays alive exactly as long as any view (or transferred descendant of it) is reachable.