]> git.kaiwu.me - njs.git/commitdiff
Fixed njs_buffer_set() introduced in 27bb9caf186c.
authorDmitry Volyntsev <xeioex@nginx.com>
Mon, 28 Sep 2020 16:59:35 +0000 (16:59 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Mon, 28 Sep 2020 16:59:35 +0000 (16:59 +0000)
Previously an instance of Uint8Array was returned, not Buffer.

src/njs_buffer.c
src/test/njs_unit_test.c

index 27232c4d61406f23cf718bf81848146a4a725b94..554425958bac767a5fc5bf8ae5a91a45afe88445 100644 (file)
@@ -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;
index 3ba4ddc43d9b43f3238c8630e4aaf36599b023b9..c683814610244d89908c703a19d50d2796a1fad7 100644 (file)
@@ -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[] =