Fixed %TypedArray%.prototype.fill().

For subarrays starting from non-zero offset.
diff --git a/src/njs_typed_array.c b/src/njs_typed_array.c
index fa43900..aa8689a 100644
--- a/src/njs_typed_array.c
+++ b/src/njs_typed_array.c
@@ -491,7 +491,7 @@
     int16_t             i16;
     int32_t             i32;
     uint8_t             u8;
-    int64_t             start, end;
+    int64_t             start, end, offset;
     uint32_t            i, length;
     njs_int_t           ret;
     njs_value_t         *this, *setval, lvalue;
@@ -535,20 +535,22 @@
     njs_set_typed_array(&vm->retval, array);
 
     buffer = array->buffer;
+    offset = array->offset;
 
     switch (array->type) {
     case NJS_OBJ_TYPE_UINT8_CLAMPED_ARRAY:
-        if (num < 0) {
-            num = 0;
+        if (isnan(num) || num < 0) {
+            u8 = 0;
 
         } else if (num > 255) {
-            num = 255;
+            u8 = 255;
+
+        } else {
+            u8 = lrint(num);
         }
 
-        u8 = lrint(num);
-
-        for (i = start; i < end; i++) {
-            buffer->u.u8[i] = u8;
+        if (start < end) {
+            memset(&buffer->u.u8[start + offset], u8, end - start);
         }
 
         break;
@@ -557,8 +559,8 @@
     case NJS_OBJ_TYPE_INT8_ARRAY:
         i8 = njs_number_to_int32(num);
 
-        for (i = start; i < end; i++) {
-            buffer->u.u8[i] = i8;
+        if (start < end) {
+            memset(&buffer->u.u8[start + offset], i8, end - start);
         }
 
         break;
@@ -568,7 +570,7 @@
         i16 = njs_number_to_int32(num);
 
         for (i = start; i < end; i++) {
-            buffer->u.u16[i] = i16;
+            buffer->u.u16[i + offset] = i16;
         }
 
         break;
@@ -578,7 +580,7 @@
         i32 = njs_number_to_int32(num);
 
         for (i = start; i < end; i++) {
-            buffer->u.u32[i] = i32;
+            buffer->u.u32[i + offset] = i32;
         }
 
         break;
@@ -587,7 +589,7 @@
         f32 = num;
 
         for (i = start; i < end; i++) {
-            buffer->u.f32[i] = f32;
+            buffer->u.f32[i + offset] = f32;
         }
 
         break;
@@ -597,7 +599,7 @@
         /* NJS_OBJ_TYPE_FLOAT64_ARRAY. */
 
         for (i = start; i < end; i++) {
-            buffer->u.f64[i] = num;
+            buffer->u.f64[i + offset] = num;
         }
 	}
 
diff --git a/src/njs_typed_array.h b/src/njs_typed_array.h
index 4a99b1b..a9938a1 100644
--- a/src/njs_typed_array.h
+++ b/src/njs_typed_array.h
@@ -103,11 +103,9 @@
 
     switch (array->type) {
     case NJS_OBJ_TYPE_UINT8_CLAMPED_ARRAY:
-        if (v < 0) {
+        if (isnan(v) || v < 0) {
             v = 0;
-        }
-
-        if (v > 255) {
+        } else if (v > 255) {
             v = 255;
         }
 
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index 0da9401..cd4e3ed 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -5005,6 +5005,11 @@
               "       return (a[0] === 1 && a[1] === 12 && a[2] === 3 && a.length == 3)})"),
       njs_str("true") },
 
+    { njs_str(NJS_TYPED_ARRAY_LIST
+              ".every(v=>{var a = new v([0,0,0,0,0]).fill(8, -1, -3); "
+              "       return njs.dump(a) === `${v.name} [0,0,0,0,0]`;})"),
+      njs_str("true") },
+
     { njs_str(NJS_INT_TYPED_ARRAY_LIST
               ".every(v=>{var a = new v([1,2,3]); a.fill('qq', 1, 2); "
               "       return (a[0] === 1 && a[1] === 0 && a[2] === 3 && a.length == 3)})"),
@@ -5341,6 +5346,12 @@
       njs_str("true") },
 
     { njs_str(NJS_TYPED_ARRAY_LIST
+              ".every(v=>{var a = new v([1,2,3,4]); "
+              "           a.subarray(1,10).fill(0);"
+              "           return  njs.dump(a) === `${v.name} [1,0,0,0]`;})"),
+      njs_str("true") },
+
+    { njs_str(NJS_TYPED_ARRAY_LIST
               ".every(v=>{var a = new v([1,2,3]); "
               "           var r = a.subarray(1,3);"
               "           return  a.buffer === r.buffer;})"),