[njs] Fixed Array.prototype.sort() when arr size is changed in a comparator.
Dmitry Volyntsev
xeioex at nginx.com
Sat Apr 23 00:04:42 UTC 2022
details: https://hg.nginx.org/njs/rev/9424f42b7266
branches:
changeset: 1839:9424f42b7266
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri Apr 22 17:02:28 2022 -0700
description:
Fixed Array.prototype.sort() when arr size is changed in a comparator.
This fixed #468 issue on Github.
diffstat:
src/njs_array.c | 2 +-
src/test/njs_unit_test.c | 3 +++
2 files changed, 4 insertions(+), 1 deletions(-)
diffs (25 lines):
diff -r 6b226ed1b25d -r 9424f42b7266 src/njs_array.c
--- a/src/njs_array.c Thu Apr 14 16:07:34 2022 -0700
+++ b/src/njs_array.c Fri Apr 22 17:02:28 2022 -0700
@@ -2696,7 +2696,7 @@ slow_path:
goto exception;
}
- if (njs_fast_path(fast_path)) {
+ if (njs_fast_path(fast_path && njs_is_fast_array(this))) {
array = njs_array(this);
start = array->start;
diff -r 6b226ed1b25d -r 9424f42b7266 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu Apr 14 16:07:34 2022 -0700
+++ b/src/test/njs_unit_test.c Fri Apr 22 17:02:28 2022 -0700
@@ -6989,6 +6989,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("[1,2].sort(1)"),
njs_str("TypeError: comparefn must be callable or undefined") },
+ { njs_str("var a = [1,2]; a.sort(() => {a.length = 65535}); a.length"),
+ njs_str("65535") },
+
/*
Array.prototype.keys()
Array.prototype.values()
More information about the nginx-devel
mailing list