Welcome! Log In Create A New Profile

Advanced

[njs] Fixed %TypedArray%.prototype.set(s) when s element changes "this".

Dmitry Volyntsev
November 07, 2022 05:26PM
details: https://hg.nginx.org/njs/rev/62b475cce018
branches:
changeset: 1992:62b475cce018
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Nov 07 14:22:41 2022 -0800
description:
Fixed %TypedArray%.prototype.set(s) when s element changes "this".

This closes #590 issue on Github.

diffstat:

src/njs_typed_array.c | 26 --------------------------
src/test/njs_unit_test.c | 9 +++++++++
2 files changed, 9 insertions(+), 26 deletions(-)

diffs (69 lines):

diff -r 3a9415ae3330 -r 62b475cce018 src/njs_typed_array.c
--- a/src/njs_typed_array.c Mon Nov 07 14:22:41 2022 -0800
+++ b/src/njs_typed_array.c Mon Nov 07 14:22:41 2022 -0800
@@ -694,7 +694,6 @@ njs_typed_array_prototype_set(njs_vm_t *
int64_t i, length, src_length, offset;
njs_int_t ret;
njs_value_t *this, *src, *value, prop;
- njs_array_t *array;
njs_typed_array_t *self, *src_tarray;
njs_array_buffer_t *buffer;

@@ -749,29 +748,6 @@ njs_typed_array_prototype_set(njs_vm_t *
}

} else {
- if (njs_is_fast_array(src)) {
- array = njs_array(src);
- src_length = array->length;
-
- if (njs_slow_path((src_length > length)
- || (offset > length - src_length)))
- {
- njs_range_error(vm, "source is too large");
- return NJS_ERROR;
- }
-
- length = njs_min(array->length, length - offset);
-
- for (i = 0; i < length; i++) {
- ret = njs_value_to_number(vm, &array->start[i], &num);
- if (ret == NJS_OK) {
- njs_typed_array_prop_set(vm, self, offset + i, num);
- }
- }
-
- goto done;
- }
-
ret = njs_value_to_object(vm, src);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
@@ -815,8 +791,6 @@ njs_typed_array_prototype_set(njs_vm_t *
}
}

-done:
-
njs_set_undefined(&vm->retval);

return NJS_OK;
diff -r 3a9415ae3330 -r 62b475cce018 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Mon Nov 07 14:22:41 2022 -0800
+++ b/src/test/njs_unit_test.c Mon Nov 07 14:22:41 2022 -0800
@@ -6585,6 +6585,15 @@ static njs_unit_test_t njs_test[] =
" return a.toString() === '1,2,3,3'})"),
njs_str("true") },

+ { njs_str(NJS_TYPED_ARRAY_LIST
+ ".every(v=>{ var a = [];"
+ " var b = {toString() {a.length = 65535; return 99;}};"
+ " for (var c = 0; c < 3; c++) { a[c] = b; }"
+ " var ta = new v(6); ta.set(a);"
+ " return ta.toString() == '99,99,99,0,0,0';"
+ " })"),
+ njs_str("true") },
+
{ njs_str("(new Float32Array([255,255,NaN,3,NaN,Infinity,3,-Infinity,0,-0,2,1,-5])).slice(2).sort()"),
njs_str("-Infinity,-5,0,0,1,2,3,3,Infinity,NaN,NaN") },

_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Fixed %TypedArray%.prototype.set(s) when s element changes "this".

Dmitry Volyntsev 190 November 07, 2022 05:26PM



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

Online Users

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