Welcome! Log In Create A New Profile

Advanced

[njs] Fixed Array.prototype.pop() and shift() for sparse objects.

Alexander Borisov
October 09, 2019 11:58AM
details: https://hg.nginx.org/njs/rev/fa75ca7ed851
branches:
changeset: 1178:fa75ca7ed851
user: Alexander Borisov <alexander.borisov@nginx.com>
date: Wed Oct 09 18:54:57 2019 +0300
description:
Fixed Array.prototype.pop() and shift() for sparse objects.

This closes #233 issue on GitHub.

diffstat:

src/njs_array.c | 4 ++--
src/test/njs_unit_test.c | 12 ++++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)

diffs (50 lines):

diff -r 6ed84cda7426 -r fa75ca7ed851 src/njs_array.c
--- a/src/njs_array.c Wed Oct 09 18:54:54 2019 +0300
+++ b/src/njs_array.c Wed Oct 09 18:54:57 2019 +0300
@@ -694,7 +694,7 @@ njs_array_prototype_pop(njs_vm_t *vm, nj
njs_uint32_to_string(&index, --length);

ret = njs_value_property_delete(vm, value, &index, &vm->retval);
- if (njs_slow_path(ret != NJS_OK)) {
+ if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}
}
@@ -900,7 +900,7 @@ njs_array_prototype_shift(njs_vm_t *vm,
njs_uint32_to_string(&index, 0);

ret = njs_value_property_delete(vm, value, &index, &vm->retval);
- if (njs_slow_path(ret != NJS_OK)) {
+ if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}

diff -r 6ed84cda7426 -r fa75ca7ed851 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Wed Oct 09 18:54:54 2019 +0300
+++ b/src/test/njs_unit_test.c Wed Oct 09 18:54:57 2019 +0300
@@ -4093,6 +4093,12 @@ static njs_unit_test_t njs_test[] =
"catch (e) {i += '; ' + e} i"),
njs_str("1; TypeError: Cannot set property \"length\" of object which has only a getter") },

+ { njs_str("Array.prototype.pop.call({ length: 3 })"),
+ njs_str("undefined") },
+
+ { njs_str("var o = { length: 3 }; Array.prototype.pop.call(o); o.length"),
+ njs_str("2") },
+
{ njs_str("Array.prototype.shift()"),
njs_str("undefined") },

@@ -4200,6 +4206,12 @@ static njs_unit_test_t njs_test[] =
{ njs_str("var a=[0], n = 64; while(--n) {a.push(n); a.shift()}; a"),
njs_str("1") },

+ { njs_str("Array.prototype.shift.call({ length: 3 })"),
+ njs_str("undefined") },
+
+ { njs_str("var o = { length: 3 }; Array.prototype.shift.call(o); o.length"),
+ njs_str("2") },
+
{ njs_str("var a = []; a.splice()"),
njs_str("") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed Array.prototype.pop() and shift() for sparse objects.

Alexander Borisov 409 October 09, 2019 11:58AM



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

Online Users

Guests: 264
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