[njs] Fixed %TypedArray%.from() with buffer is detached by mapper.

2025-06-13 Thread noreply
details:   
https://github.com/nginx/njs/commit/d10a85b24981ad2ba602da7b29c870cc596fda70
branches:  master
commit:d10a85b24981ad2ba602da7b29c870cc596fda70
user:  Dmitry Volyntsev 
date:  Thu, 12 Jun 2025 15:16:41 -0700
description:
Fixed %TypedArray%.from() with buffer is detached by mapper.


---
 src/njs_typed_array.c | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/njs_typed_array.c b/src/njs_typed_array.c
index 19399e3b..83e3b9f1 100644
--- a/src/njs_typed_array.c
+++ b/src/njs_typed_array.c
@@ -324,13 +324,14 @@ static njs_int_t
 njs_typed_array_from(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 njs_index_t unused, njs_value_t *retval)
 {
-double num;
-int64_tlength, i;
-njs_int_t  ret;
-njs_value_t*this, *source, *mapfn;
-njs_value_targuments[3], value;
-njs_function_t *function;
-njs_typed_array_t  *array;
+double  num;
+int64_t length, i;
+njs_int_t   ret;
+njs_value_t *this, *source, *mapfn;
+njs_value_t arguments[3], value;
+njs_function_t  *function;
+njs_typed_array_t   *array;
+njs_array_buffer_t  *buffer;
 
 this = njs_argument(args, 0);
 
@@ -371,6 +372,7 @@ njs_typed_array_from(njs_vm_t *vm, njs_value_t *args, 
njs_uint_t nargs,
 }
 
 array = njs_typed_array(retval);
+buffer = njs_typed_array_buffer(array);
 arguments[0] = *njs_arg(args, nargs, 3);
 
 for (i = 0; i < length; i++) {
@@ -393,7 +395,9 @@ njs_typed_array_from(njs_vm_t *vm, njs_value_t *args, 
njs_uint_t nargs,
 return NJS_ERROR;
 }
 
-njs_typed_array_prop_set(vm, array, i, num);
+if (!njs_is_detached_buffer(buffer)) {
+njs_typed_array_prop_set(vm, array, i, num);
+}
 }
 
 njs_set_typed_array(retval, array);
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed handling of detached buffer for typed arrays.

2025-06-13 Thread noreply
details:   
https://github.com/nginx/njs/commit/d5bcd36d321fb578ffd1c804ec2d206c3b3e945e
branches:  master
commit:d5bcd36d321fb578ffd1c804ec2d206c3b3e945e
user:  Dmitry Volyntsev 
date:  Thu, 12 Jun 2025 17:20:07 -0700
description:
Fixed handling of detached buffer for typed arrays.


---
 src/njs_typed_array.c | 5 +
 src/njs_value.c   | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/njs_typed_array.c b/src/njs_typed_array.c
index f886dca6..d7ca2e83 100644
--- a/src/njs_typed_array.c
+++ b/src/njs_typed_array.c
@@ -655,6 +655,11 @@ njs_typed_array_set_value(njs_vm_t *vm, njs_typed_array_t 
*array,
 return ret;
 }
 
+buffer = njs_typed_array_buffer(array);
+if (njs_slow_path(njs_is_detached_buffer(buffer))) {
+return NJS_OK;
+}
+
 buffer = njs_typed_array_writable(vm, array);
 if (njs_slow_path(buffer == NULL)) {
 return NJS_ERROR;
diff --git a/src/njs_value.c b/src/njs_value.c
index 86fb6444..0c616a37 100644
--- a/src/njs_value.c
+++ b/src/njs_value.c
@@ -1019,8 +1019,7 @@ njs_value_property(njs_vm_t *vm, njs_value_t *value, 
uint32_t atom_id,
 tarray = njs_typed_array(value);
 
 if (njs_slow_path(njs_is_detached_buffer(tarray->buffer))) {
-njs_type_error(vm, "detached buffer");
-return NJS_ERROR;
+goto not_found;
 }
 
 if (njs_slow_path(index >= njs_typed_array_length(tarray))) {
@@ -1109,6 +1108,7 @@ slow_path:
 break;
 
 case NJS_DECLINED:
+not_found:
 njs_set_undefined(retval);
 
 return NJS_DECLINED;
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Tests: tuned periodic test for delays.

2025-06-13 Thread noreply
details:   
https://github.com/nginx/njs/commit/3a22f42628e57f711bfc328e10388b2345f58647
branches:  master
commit:3a22f42628e57f711bfc328e10388b2345f58647
user:  Dmitry Volyntsev 
date:  Thu, 12 Jun 2025 17:54:43 -0700
description:
Tests: tuned periodic test for delays.


---
 nginx/t/js_periodic.t   | 2 +-
 nginx/t/js_periodic_fetch.t | 9 -
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/nginx/t/js_periodic.t b/nginx/t/js_periodic.t
index d6868935..7e134588 100644
--- a/nginx/t/js_periodic.t
+++ b/nginx/t/js_periodic.t
@@ -56,7 +56,7 @@ http {
 server_name  localhost;
 
 location @periodic {
-js_periodic test.tick interval=30ms jitter=1ms;
+js_periodic test.tick interval=20ms jitter=1ms;
 js_periodic test.timer interval=1s worker_affinity=all;
 js_periodic test.overrun interval=30ms;
 js_periodic test.affinity interval=50ms worker_affinity=0101;
diff --git a/nginx/t/js_periodic_fetch.t b/nginx/t/js_periodic_fetch.t
index a323afb8..39385132 100644
--- a/nginx/t/js_periodic_fetch.t
+++ b/nginx/t/js_periodic_fetch.t
@@ -99,12 +99,11 @@ $t->write_file('test.js', stop();
 
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed %TypedArray%.prototype.slice() with overlapping buffers.

2025-06-13 Thread noreply
details:   
https://github.com/nginx/njs/commit/efb0454a59f49dc8874d772c8c245460f49e6671
branches:  master
commit:efb0454a59f49dc8874d772c8c245460f49e6671
user:  Dmitry Volyntsev 
date:  Thu, 12 Jun 2025 15:34:39 -0700
description:
Fixed %TypedArray%.prototype.slice() with overlapping buffers.


---
 src/njs_typed_array.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/njs_typed_array.c b/src/njs_typed_array.c
index 83e3b9f1..f886dca6 100644
--- a/src/njs_typed_array.c
+++ b/src/njs_typed_array.c
@@ -912,6 +912,20 @@ njs_typed_array_prototype_fill(njs_vm_t *vm, njs_value_t 
*args,
 }
 
 
+static void
+njs_slice_memcpy(uint8_t *dst, const uint8_t *src, size_t len)
+{
+if (dst + len <= src || dst >= src + len) {
+/* no overlap: can use memcpy */
+memcpy(dst, src, len);
+
+} else {
+while (len-- != 0)
+*dst++ = *src++;
+}
+}
+
+
 njs_int_t
 njs_typed_array_prototype_slice(njs_vm_t *vm, njs_value_t *args,
 njs_uint_t nargs, njs_index_t copy, njs_value_t *retval)
@@ -990,7 +1004,7 @@ njs_typed_array_prototype_slice(njs_vm_t *vm, njs_value_t 
*args,
 start = start * element_size;
 count = count * element_size;
 
-memcpy(&new_buffer->u.u8[0], &buffer->u.u8[start], count);
+njs_slice_memcpy(&new_buffer->u.u8[0], &buffer->u.u8[start], 
count);
 
 } else {
 for (i = 0; i < count; i++) {
___
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel