Fixed TextDecoder.prototype.decode() with non-zero TypedArray offset.
diff --git a/src/njs_encoding.c b/src/njs_encoding.c
index 3cc7cb6..01d28af 100644
--- a/src/njs_encoding.c
+++ b/src/njs_encoding.c
@@ -214,7 +214,7 @@
     end = start + str.length;
 
     array = njs_typed_array(dest);
-    to = njs_typed_array_buffer(array)->u.u8;
+    to = njs_typed_array_start(array);
     to_end = to + array->byte_length;
 
     cp = 0;
@@ -564,7 +564,7 @@
         if (njs_is_typed_array(value)) {
             array = njs_typed_array(value);
 
-            start = array->buffer->u.u8;
+            start = njs_typed_array_start(array);
             end = start + array->byte_length;
 
         } else if (njs_is_array_buffer(value)) {
diff --git a/src/njs_typed_array.c b/src/njs_typed_array.c
index be73e50..e23fd59 100644
--- a/src/njs_typed_array.c
+++ b/src/njs_typed_array.c
@@ -610,8 +610,7 @@
 
     array = njs_typed_array(this);
 
-    njs_set_number(&vm->retval, array->offset
-                                * njs_typed_array_element_size(array->type));
+    njs_set_number(&vm->retval, njs_typed_array_offset(array));
 
     return NJS_OK;
 }
diff --git a/src/njs_typed_array.h b/src/njs_typed_array.h
index 7e31a7d..78db766 100644
--- a/src/njs_typed_array.h
+++ b/src/njs_typed_array.h
@@ -55,6 +55,20 @@
 }
 
 
+njs_inline uint32_t
+njs_typed_array_offset(const njs_typed_array_t *array)
+{
+    return array->offset * njs_typed_array_element_size(array->type);
+}
+
+
+njs_inline u_char *
+njs_typed_array_start(const njs_typed_array_t *array)
+{
+    return &array->buffer->u.u8[njs_typed_array_offset(array)];
+}
+
+
 njs_inline double
 njs_typed_array_prop(const njs_typed_array_t *array, uint32_t index)
 {
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index ed59118..4da0bc0 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -18226,6 +18226,11 @@
               "var res = en.encodeInto('ααααα', utf8); njs.dump(res)"),
       njs_str("{read:5,written:10}") },
 
+    { njs_str("var en = new TextEncoder();"
+              "var utf8 = new Uint8Array(10);"
+              "en.encodeInto('ααααα', utf8.subarray(2)); utf8[0]"),
+      njs_str("0") },
+
     { njs_str("var str = String.bytesFrom([0xCE]);"
               "var en = new TextEncoder();"
               "var utf8 = new Uint8Array(3);"
@@ -18333,6 +18338,12 @@
               "var en = new TextEncoder();"
               "njs.dump(en.encode(de.decode(buf)))"),
       njs_str("Uint8Array [1,0,0,0,2,0,0,0,3,0,0,0]") },
+
+    { njs_str("var de = new TextDecoder();"
+              "var buf = new Uint32Array([1,2,3]).subarray(1,2);"
+              "var en = new TextEncoder();"
+              "njs.dump(en.encode(de.decode(buf)))"),
+      njs_str("Uint8Array [2,0,0,0]") },
 };