From: Dmitry Volyntsev Date: Fri, 5 Jun 2020 11:42:41 +0000 (+0000) Subject: Fixed %TypedArray%.prototype.copyWithin() with nonzero byte offset. X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=eabbd1827d1de4c9b4d86c1a33978283e844277e;p=njs.git Fixed %TypedArray%.prototype.copyWithin() with nonzero byte offset. --- diff --git a/src/njs_typed_array.c b/src/njs_typed_array.c index e9ea2c65..1ab8a1be 100644 --- a/src/njs_typed_array.c +++ b/src/njs_typed_array.c @@ -803,8 +803,8 @@ njs_typed_array_prototype_copy_within(njs_vm_t *vm, njs_value_t *args, buffer = njs_typed_array_buffer(array); element_size = njs_typed_array_element_size(array->type); - to = to * element_size; - from = from * element_size; + to = (to + array->offset) * element_size; + from = (from + array->offset) * element_size; count = count * element_size; memmove(&buffer->u.u8[to], &buffer->u.u8[from], count); diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index d7ec6ee0..26335448 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -5719,6 +5719,13 @@ static njs_unit_test_t njs_test[] = " return a.toString() === '1,2,3,3'})"), njs_str("true") }, + { njs_str(NJS_TYPED_ARRAY_LIST + ".every(v=>{var orig = new v([255,255,1,2,3,4,5]);" + " var a = new v(orig.buffer, 2* v.BYTES_PER_ELEMENT);" + " a.copyWithin(0,3);" + " return a.toString() === '4,5,3,4,5'})"), + njs_str("true") }, + { njs_str(NJS_TYPED_ARRAY_LIST ".every(v=>{var a = new v([]); a.sort(); " " return a.toString() === ''})"),