From: Dmitry Volyntsev Date: Mon, 18 May 2020 13:22:34 +0000 (+0000) Subject: Fixed Array.prototype.slice() for sparse arrays. X-Git-Tag: 0.4.1~2 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=3dcf1d91b4ee14e9292e26763c436055edc2fa8e;p=njs.git Fixed Array.prototype.slice() for sparse arrays. --- diff --git a/src/njs_array.c b/src/njs_array.c index 13be922f..3bfcf4c0 100644 --- a/src/njs_array.c +++ b/src/njs_array.c @@ -686,15 +686,17 @@ njs_array_prototype_slice_copy(njs_vm_t *vm, njs_value_t *this, /* src value may be in Array.prototype object. */ - value = &array->start[n++]; - ret = njs_value_property_i64(vm, this, start++, value); + ret = njs_value_property_i64(vm, this, start++, + &array->start[n]); if (njs_slow_path(ret == NJS_ERROR)) { return NJS_ERROR; } if (ret != NJS_OK) { - njs_set_invalid(value); + njs_set_invalid(&array->start[n]); } + + n++; } length--; diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 3642c6fc..d468f0bc 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -4313,6 +4313,9 @@ static njs_unit_test_t njs_test[] = { njs_str("[0,1].slice()"), njs_str("0,1") }, + { njs_str("[1,2,3,,,4].slice()"), + njs_str("1,2,3,,,4") }, + { njs_str("[0,1].slice(undefined)"), njs_str("0,1") }, @@ -4326,7 +4329,7 @@ static njs_unit_test_t njs_test[] = njs_str("") }, { njs_str("var a = [1,2,3,4,5], b = a.slice(3);" - "b[0] +' '+ b[1] +' '+ b[2]"), + "b[0] +' '+ b[1] +' '+ b[2]"), njs_str("4 5 undefined") }, { njs_str("var a = [1,2]; a.pop() +' '+ a.length +' '+ a"), @@ -4336,7 +4339,7 @@ static njs_unit_test_t njs_test[] = njs_str("3 3 1,2") }, { njs_str("var a = [1,2], len = a.push(3,4,5);" - "len +' '+ a.pop() +' '+ a"), + "len +' '+ a.pop() +' '+ a"), njs_str("5 5 1,2,3,4") }, { njs_str("var x = {'0': 'a', '1': 'b', '2': 'c', 'length': 3};"