changeset 2569:37e1253f004f

Fixed %TypedArray%.from() with buffer is detached by mapper.
author Dmitry Volyntsev <xeioex@nginx.com>
date Thu, 12 Jun 2025 15:16:41 -0700
parents 84478627a37c
children 7ade97e7d376
files src/njs_typed_array.c
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/njs_typed_array.c	Mon Jun 09 16:59:22 2025 +0300
+++ b/src/njs_typed_array.c	Thu Jun 12 15:16:41 2025 -0700
@@ -324,13 +324,14 @@
 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_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;
+    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 @@
     }
 
     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 @@
             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);