[njs] A fix in Array.splice() function.
Igor Sysoev
igor at sysoev.ru
Mon Oct 17 14:01:38 UTC 2016
details: http://hg.nginx.org/njs/rev/c68db870b8b0
branches:
changeset: 199:c68db870b8b0
user: Igor Sysoev <igor at sysoev.ru>
date: Fri Oct 14 17:21:35 2016 +0300
description:
A fix in Array.splice() function.
diffstat:
njs/njs_array.c | 4 ++++
njs/test/njs_unit_test.c | 4 ++++
2 files changed, 8 insertions(+), 0 deletions(-)
diffs (28 lines):
diff -r 8046b999aaaf -r c68db870b8b0 njs/njs_array.c
--- a/njs/njs_array.c Wed Oct 12 19:08:57 2016 +0300
+++ b/njs/njs_array.c Fri Oct 14 17:21:35 2016 +0300
@@ -585,6 +585,10 @@ njs_array_prototype_splice(njs_vm_t *vm,
if (nargs > 1) {
start = args[1].data.u.number;
+ if (start > array->length) {
+ start = array->length;
+ }
+
if (nargs > 2) {
delete = args[2].data.u.number;
diff -r 8046b999aaaf -r c68db870b8b0 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Wed Oct 12 19:08:57 2016 +0300
+++ b/njs/test/njs_unit_test.c Fri Oct 14 17:21:35 2016 +0300
@@ -2304,6 +2304,10 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("var a = []; a.splice()"),
nxt_string("") },
+ { nxt_string("var a = [];"
+ "a.splice(9,0,1,2).join(':') + '|' + a"),
+ nxt_string("|1,2") },
+
{ nxt_string("var a = [0,1,2,3,4,5,6,7];"
"a.splice(3).join(':') + '|' + a"),
nxt_string("3:4:5:6:7|0,1,2") },
More information about the nginx-devel
mailing list