QuickJS: copy body bytes into ArrayBuffer
Previously, r.readRequestArrayBuffer() and the arrayBuffer() methods
of fetch Request and Response objects returned an ArrayBuffer over
memory owned by a pool: the request pool or the engine pool. The
buffer was created without a free function, which caused the
following problems:
- with js_context_reuse, a buffer retained in the module scope
outlived the pool and pointed to freed memory in the next
request;
- ArrayBuffer.prototype.transfer() called the NULL free function;
- writes through the buffer modified the request body seen by
subsequent r.requestText and r.readRequestText() calls, for a
single buffer body directly in the nginx request buffers.
Now, the bytes are copied into memory owned by the ArrayBuffer. For
Response.arrayBuffer() the body chain is joined directly into the
runtime memory, so the number of copies is unchanged.
The issue was introduced in
b7f76b71 (0.9.1) and
7684d702 (0.9.9).
Based on a patch by Vadim Zhestikov.