Welcome! Log In Create A New Profile

Advanced

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

Dmitry Volyntsev
September 28, 2020 01:48PM
details: https://hg.nginx.org/njs/rev/366aa456dc90
branches:
changeset: 1529:366aa456dc90
user: Dmitry Volyntsev <xeioex@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[] =
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

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

Dmitry Volyntsev 81 September 28, 2020 01:48PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 68
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready