From: Dmitry Volyntsev Date: Mon, 28 Sep 2020 16:59:35 +0000 (+0000) Subject: Fixed njs_buffer_set() introduced in 27bb9caf186c. X-Git-Tag: 0.4.4~2 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=5f7dc4fd733f1b1d4258378b3ca1641585cd358d;p=njs.git Fixed njs_buffer_set() introduced in 27bb9caf186c. Previously an instance of Uint8Array was returned, not Buffer. --- diff --git a/src/njs_buffer.c b/src/njs_buffer.c index 27232c4d..55442595 100644 --- a/src/njs_buffer.c +++ b/src/njs_buffer.c @@ -97,7 +97,7 @@ njs_buffer_set(njs_vm_t *vm, njs_value_t *value, const u_char *start, 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 *value, const u_char *start, 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 --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 3ba4ddc4..c6838146 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -19656,8 +19656,11 @@ static njs_unit_test_t njs_externals_test[] = "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[] =