From: Dmitry Volyntsev Date: Wed, 3 Jul 2019 14:16:40 +0000 (+0300) Subject: Fixed Array.prototype.slice() for primitive types. X-Git-Tag: 0.3.4~100 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=e6263dd0086779138aa3ab5fbac9b6b012639b0c;p=njs.git Fixed Array.prototype.slice() for primitive types. This closes #188 issue on Github. --- diff --git a/njs/njs_array.c b/njs/njs_array.c index b418b74f..2571dcd0 100644 --- a/njs/njs_array.c +++ b/njs/njs_array.c @@ -683,6 +683,17 @@ njs_array_prototype_slice_copy(njs_vm_t *vm, njs_value_t *this, length--; } while (length != 0); + + } else { + + /* Primitive types. */ + + value = array->start; + + do { + *value++ = njs_value_invalid; + length--; + } while (length != 0); } } diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 24ecf857..b3607d48 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -3687,6 +3687,10 @@ static njs_unit_test_t njs_test[] = { nxt_string("Array.prototype.slice.call(new String('αβZγ'))"), nxt_string("α,β,Z,γ") }, + { nxt_string("1..__proto__.length = '2';" + "Array.prototype.slice.call(1, 0, 2)"), + nxt_string(",") }, + { nxt_string("Array.prototype.pop()"), nxt_string("undefined") },