Welcome! Log In Create A New Profile

Advanced

[njs] Fixed Array.prototype.sort() when arr size is changed in a comparator.

Dmitry Volyntsev
April 22, 2022 08:08PM
details: https://hg.nginx.org/njs/rev/9424f42b7266
branches:
changeset: 1839:9424f42b7266
user: Dmitry Volyntsev <xeioex@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()
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Fixed Array.prototype.sort() when arr size is changed in a comparator.

Dmitry Volyntsev 492 April 22, 2022 08:08PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 168
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready