[njs] Fixed Array.prototype.length setter.
Dmitry Volyntsev
xeioex at nginx.com
Wed Sep 19 16:45:37 UTC 2018
details: http://hg.nginx.org/njs/rev/da303066654d
branches:
changeset: 610:da303066654d
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Wed Sep 19 19:24:05 2018 +0300
description:
Fixed Array.prototype.length setter.
diffstat:
njs/njs_array.c | 4 ++--
njs/test/njs_unit_test.c | 6 ++++++
2 files changed, 8 insertions(+), 2 deletions(-)
diffs (40 lines):
diff -r c989d199095a -r da303066654d njs/njs_array.c
--- a/njs/njs_array.c Wed Sep 19 14:43:58 2018 +0300
+++ b/njs/njs_array.c Wed Sep 19 19:24:05 2018 +0300
@@ -377,7 +377,7 @@ njs_array_prototype_length(njs_vm_t *vm,
njs_value_t *setval, njs_value_t *retval)
{
double num;
- int32_t size;
+ int64_t size;
uint32_t length;
njs_ret_t ret;
njs_value_t *val;
@@ -399,7 +399,7 @@ njs_array_prototype_length(njs_vm_t *vm,
return NJS_ERROR;
}
- size = (int32_t) (length - array->length);
+ size = (int64_t) length - array->length;
if (size > 0) {
ret = njs_array_expand(vm, array, 0, size);
diff -r c989d199095a -r da303066654d njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Wed Sep 19 14:43:58 2018 +0300
+++ b/njs/test/njs_unit_test.c Wed Sep 19 19:24:05 2018 +0300
@@ -2790,9 +2790,15 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("[].length = {}"),
nxt_string("RangeError: Invalid array length") },
+ { nxt_string("[].length = 2**32 - 1"),
+ nxt_string("MemoryError") },
+
{ nxt_string("[].length = 2**32"),
nxt_string("RangeError: Invalid array length") },
+ { nxt_string("[].length = 2**32 + 1"),
+ nxt_string("RangeError: Invalid array length") },
+
{ nxt_string("[].length = -1"),
nxt_string("RangeError: Invalid array length") },
More information about the nginx-devel
mailing list