[njs] Fixed returned value for Buffer.prototype.write* functions.

Alexander Borisov alexander.borisov at nginx.com
Mon Oct 19 13:12:07 UTC 2020


details:   https://hg.nginx.org/njs/rev/4106bf95d343
branches:  
changeset: 1540:4106bf95d343
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Mon Oct 19 15:51:37 2020 +0300
description:
Fixed returned value for Buffer.prototype.write* functions.

All Buffer.prototype.write* functions must return offset plus
the number of bytes written.

The issue was introduced in 27bb9caf186c.

diffstat:

 src/njs_buffer.c         |  2 +-
 src/test/njs_unit_test.c |  6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r a82f123409b7 -r 4106bf95d343 src/njs_buffer.c
--- a/src/njs_buffer.c	Tue Oct 13 15:44:33 2020 +0300
+++ b/src/njs_buffer.c	Mon Oct 19 15:51:37 2020 +0300
@@ -1331,7 +1331,7 @@ njs_buffer_prototype_write_int(njs_vm_t 
         break;
     }
 
-    njs_set_undefined(&vm->retval);
+    njs_set_number(&vm->retval, index + size);
 
     return NJS_OK;
 }
diff -r a82f123409b7 -r 4106bf95d343 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Tue Oct 13 15:44:33 2020 +0300
+++ b/src/test/njs_unit_test.c	Mon Oct 19 15:51:37 2020 +0300
@@ -19191,7 +19191,11 @@ static njs_unit_test_t  njs_test[] =
               "        if (size > 1) { rmethod += endianness; wmethod += endianness; };"
               "        var v = 0x7abbccddeeff & (size * 8 - 1);"
               ""
-              "        buf[wgmethod](v, offset, size);"
+              "        var ret = buf[wgmethod](v, offset, size);"
+              "        if(ret !== offset + size) {"
+              "            throw Error(`${wgmethod} returned ${ret}, need ${offset + size}`);"
+              "        }"
+              ""
               "        var gv = buf[rgmethod](offset, size);"
               ""
               "        buf.fill(0);"


More information about the nginx-devel mailing list