From: Dmitry Volyntsev Date: Sat, 23 Apr 2022 00:02:28 +0000 (-0700) Subject: Fixed Array.prototype.sort() when arr size is changed in a comparator. X-Git-Tag: 0.7.4~25 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=8b39afdad9a0761e0a5d4af1a762bd9a6daef572;p=njs.git Fixed Array.prototype.sort() when arr size is changed in a comparator. This fixed #468 issue on Github. --- diff --git a/src/njs_array.c b/src/njs_array.c index 81a7c155..0b8c7b91 100644 --- a/src/njs_array.c +++ b/src/njs_array.c @@ -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 --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 186defa1..25e066c3 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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()