[njs] Fixed njs_buffer_set() introduced in 27bb9caf186c.

Dmitry Volyntsev xeioex at nginx.com
Mon Sep 28 17:46:30 UTC 2020


details:   https://hg.nginx.org/njs/rev/366aa456dc90
branches:  
changeset: 1529:366aa456dc90
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Sep 28 16:59:35 2020 +0000
description:
Fixed njs_buffer_set() introduced in 27bb9caf186c.

Previously an instance of Uint8Array was returned, not Buffer.

diffstat:

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

diffs (42 lines):

diff -r 8498c810d853 -r 366aa456dc90 src/njs_buffer.c
--- a/src/njs_buffer.c	Thu Sep 24 19:00:38 2020 +0000
+++ b/src/njs_buffer.c	Mon Sep 28 16:59:35 2020 +0000
@@ -97,7 +97,7 @@ njs_buffer_set(njs_vm_t *vm, njs_value_t
 
     buffer = (njs_array_buffer_t *) &array[1];
 
-    proto = &vm->prototypes[NJS_OBJ_TYPE_BUFFER].object;
+    proto = &vm->prototypes[NJS_OBJ_TYPE_ARRAY_BUFFER].object;
 
     njs_lvlhsh_init(&buffer->object.hash);
     njs_lvlhsh_init(&buffer->object.shared_hash);
@@ -111,10 +111,12 @@ njs_buffer_set(njs_vm_t *vm, njs_value_t
     buffer->u.data = (void *) start;
     buffer->size = size;
 
+    proto = &vm->prototypes[NJS_OBJ_TYPE_BUFFER].object;
+
     array->type = NJS_OBJ_TYPE_UINT8_ARRAY;
     njs_lvlhsh_init(&array->object.hash);
     njs_lvlhsh_init(&array->object.shared_hash);
-    array->object.__proto__ = &vm->prototypes[array->type].object;
+    array->object.__proto__ = proto;
     array->object.slots = NULL;
     array->object.type = NJS_TYPED_ARRAY;
     array->object.shared = 0;
diff -r 8498c810d853 -r 366aa456dc90 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Thu Sep 24 19:00:38 2020 +0000
+++ b/src/test/njs_unit_test.c	Mon Sep 28 16:59:35 2020 +0000
@@ -19656,8 +19656,11 @@ static njs_unit_test_t  njs_externals_te
               "var s = (new TextDecoder()).decode(u16); [s, s.length]"),
       njs_str("ЙИЗЖЁЕДГВБА,11") },
 
-    { njs_str("$r.buffer.sort().slice(0,3)"),
+    { njs_str("new Uint8Array($r.buffer.sort().slice(0,3))"),
       njs_str("129,144,145") },
+
+    { njs_str("$r.buffer instanceof Buffer"),
+      njs_str("true") },
 };
 
 static njs_unit_test_t  njs_shared_test[] =


More information about the nginx-devel mailing list