[njs] Fixed Array.prototype.fill().
Dmitry Volyntsev
xeioex at nginx.com
Mon Feb 25 12:38:48 UTC 2019
details: https://hg.nginx.org/njs/rev/1718603aae6a
branches:
changeset: 797:1718603aae6a
user: Artem S. Povalyukhin <artem.povaluhin at gmail.com>
date: Sat Feb 23 04:21:44 2019 +0300
description:
Fixed Array.prototype.fill().
This closes #71 issue on Github.
diffstat:
njs/njs_array.c | 11 +++++++----
njs/test/njs_unit_test.c | 4 ++++
2 files changed, 11 insertions(+), 4 deletions(-)
diffs (46 lines):
diff -r 25b394b0e953 -r 1718603aae6a njs/njs_array.c
--- a/njs/njs_array.c Sat Feb 23 04:20:23 2019 +0300
+++ b/njs/njs_array.c Sat Feb 23 04:21:44 2019 +0300
@@ -1372,12 +1372,13 @@ static njs_ret_t
njs_array_prototype_fill(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
{
- nxt_int_t i, start, end, length;
- njs_array_t *array;
+ nxt_int_t i, start, end, length;
+ njs_array_t *array;
+ const njs_value_t *value;
vm->retval = args[0];
- if (nargs < 2 || !njs_is_array(&args[0])) {
+ if (!njs_is_array(&args[0])) {
return NXT_OK;
}
@@ -1423,8 +1424,10 @@ njs_array_prototype_fill(njs_vm_t *vm, n
}
}
+ value = njs_arg(args, nargs, 1);
+
for (i = start; i < end; i++) {
- array->start[i] = args[1];
+ array->start[i] = *value;
}
return NXT_OK;
diff -r 25b394b0e953 -r 1718603aae6a njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Sat Feb 23 04:20:23 2019 +0300
+++ b/njs/test/njs_unit_test.c Sat Feb 23 04:21:44 2019 +0300
@@ -3668,6 +3668,10 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("[1,2,3].fill({a:\"b\"}, 1, 2);"),
nxt_string("1,[object Object],3") },
+ { nxt_string("Array(3).fill().reduce(function(a, x)"
+ "{ return a + (x === undefined); }, 0)"),
+ nxt_string("3") },
+
{ nxt_string("var a = [];"
"a.filter(function(v, i, a) { return v > 1 })"),
nxt_string("") },
More information about the nginx-devel
mailing list