switch (type) {
case NGX_JS_BODY_ARRAY_BUFFER:
- return qjs_new_external_array_buffer(cx, ctx->body_read_data,
- ctx->body_read_len, 0);
+ return JS_NewArrayBufferCopy(cx, ctx->body_read_data,
+ ctx->body_read_len);
case NGX_JS_BODY_JSON:
if (ctx->body_read_nul) {
switch (magic) {
case NGX_JS_BODY_ARRAY_BUFFER:
- /*
- * request->body is allocated from e->pool
- * and will be freed when context is freed.
- */
- result = qjs_new_external_array_buffer(cx, request->body.data,
- request->body.len, 0);
+ result = JS_NewArrayBufferCopy(cx, request->body.data,
+ request->body.len);
if (JS_IsException(result)) {
return JS_ThrowOutOfMemory(cx);
}
ngx_qjs_ext_fetch_response_body(JSContext *cx, JSValueConst this_val,
int argc, JSValueConst *argv, int magic)
{
+ u_char *p;
+ int64_t size;
JSValue result;
njs_int_t ret;
njs_str_t string;
break;
case NGX_JS_BODY_ARRAY_BUFFER:
- ret = njs_chb_join(&response->chain, &string);
- if (ret != NJS_OK) {
+ size = njs_chb_size(&response->chain);
+ if (size < 0) {
return JS_ThrowOutOfMemory(cx);
}
+ p = js_malloc(cx, njs_max(size, 1));
+ if (p == NULL) {
+ return JS_EXCEPTION;
+ }
+
+ njs_chb_join_to(&response->chain, p);
njs_chb_destroy(&response->chain);
- /*
- * string.start is allocated from e->pool
- * and will be freed when context is freed.
- */
- result = qjs_new_external_array_buffer(cx, string.start,
- string.length, 0);
+ result = qjs_new_array_buffer(cx, p, size);
if (JS_IsException(result)) {
- return JS_ThrowOutOfMemory(cx);
+ js_free(cx, p);
}
break;