njs_buffer_concat(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- u_char *p;
+ u_char *p, *src;
size_t n;
int64_t i, len, list_len;
njs_int_t ret;
for (i = 0; len != 0 && i < list_len; i++) {
arr = njs_typed_array(&array->start[i]);
n = njs_min((size_t) len, arr->byte_length);
+ src = &njs_typed_array_buffer(arr)->u.u8[arr->offset];
- p = njs_cpymem(p, njs_typed_array_buffer(arr)->u.u8, n);
+ p = njs_cpymem(p, src, n);
len -= n;
}
arr = njs_typed_array(&retval);
n = njs_min((size_t) len, arr->byte_length);
+ src = &njs_typed_array_buffer(arr)->u.u8[arr->offset];
- p = njs_cpymem(p, njs_typed_array_buffer(arr)->u.u8, n);
+ p = njs_cpymem(p, src, n);
len -= n;
}
{ njs_str("Buffer.concat([new Uint8Array(2), new Uint8Array(1)], 6).fill('abc')"),
njs_str("abcabc") },
+ { njs_str("Buffer.concat([Buffer.from('ABCD').slice(2,4), Buffer.from('ABCD').slice(0,2)])"),
+ njs_str("CDAB") },
+
+ { njs_str(njs_declare_sparse_array("list", 2)
+ "list[0] = Buffer.from('ABCD').slice(2,4);"
+ "list[1] = Buffer.from('ABCD').slice(0,2);"
+ "Buffer.concat(list);"),
+ njs_str("CDAB") },
+
{ njs_str(njs_declare_sparse_array("list", 2)
"list[0] = new Uint8Array(2); list[1] = new Uint8Array(3);"
"Buffer.concat(list).fill('ab');"),