[njs] Fixed %TypedArray%.prototype.copyWithin() with nonzero byte offset.

Dmitry Volyntsev xeioex at nginx.com
Fri Jun 5 11:59:58 UTC 2020


details:   https://hg.nginx.org/njs/rev/790bde011274
branches:  
changeset: 1425:790bde011274
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Jun 05 11:42:41 2020 +0000
description:
Fixed %TypedArray%.prototype.copyWithin() with nonzero byte offset.

diffstat:

 src/njs_typed_array.c    |  4 ++--
 src/test/njs_unit_test.c |  7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diffs (31 lines):

diff -r 23df5a31bafd -r 790bde011274 src/njs_typed_array.c
--- a/src/njs_typed_array.c	Fri Jun 05 11:42:40 2020 +0000
+++ b/src/njs_typed_array.c	Fri Jun 05 11:42:41 2020 +0000
@@ -803,8 +803,8 @@ njs_typed_array_prototype_copy_within(nj
     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 -r 23df5a31bafd -r 790bde011274 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Fri Jun 05 11:42:40 2020 +0000
+++ b/src/test/njs_unit_test.c	Fri Jun 05 11:42:41 2020 +0000
@@ -5720,6 +5720,13 @@ static njs_unit_test_t  njs_test[] =
       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() === ''})"),
       njs_str("true") },


More information about the nginx-devel mailing list