Welcome! Log In Create A New Profile

Advanced

[njs] Added support for ArrayBuffer in njs_vm_value_to_bytes().

Dmitry Volyntsev
July 13, 2021 11:24AM
details: https://hg.nginx.org/njs/rev/e37a80fac86f
branches:
changeset: 1677:e37a80fac86f
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue Jul 13 15:22:24 2021 +0000
description:
Added support for ArrayBuffer in njs_vm_value_to_bytes().

diffstat:

src/njs_vm.c | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)

diffs (44 lines):

diff -r 537f897451ef -r e37a80fac86f src/njs_vm.c
--- a/src/njs_vm.c Tue Jul 13 10:23:23 2021 +0900
+++ b/src/njs_vm.c Tue Jul 13 15:22:24 2021 +0000
@@ -1131,7 +1131,7 @@ njs_int_t
njs_vm_value_to_bytes(njs_vm_t *vm, njs_str_t *dst, njs_value_t *src)
{
u_char *start;
- size_t size;
+ size_t size, length, offset;
njs_int_t ret;
njs_value_t value;
njs_typed_array_t *array;
@@ -1147,15 +1147,27 @@ njs_vm_value_to_bytes(njs_vm_t *vm, njs_
switch (value.type) {
case NJS_TYPED_ARRAY:
case NJS_DATA_VIEW:
- array = njs_typed_array(&value);
- buffer = njs_typed_array_buffer(array);
+ case NJS_ARRAY_BUFFER:
+
+ if (value.type != NJS_ARRAY_BUFFER) {
+ array = njs_typed_array(&value);
+ buffer = njs_typed_array_buffer(array);
+ offset = array->offset;
+ length = array->byte_length;
+
+ } else {
+ buffer = njs_array_buffer(&value);
+ offset = 0;
+ length = buffer->size;
+ }
+
if (njs_slow_path(njs_is_detached_buffer(buffer))) {
njs_type_error(vm, "detached buffer");
return NJS_ERROR;
}

- dst->start = &buffer->u.u8[array->offset];
- dst->length = array->byte_length;
+ dst->start = &buffer->u.u8[offset];
+ dst->length = length;
break;

default:
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Added support for ArrayBuffer in njs_vm_value_to_bytes().

Dmitry Volyntsev 92 July 13, 2021 11:24AM



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

Online Users

Guests: 63
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