int64_t length, l, h;
njs_int_t ret, lret, hret;
njs_value_t value, lvalue, hvalue, *this;
- njs_array_t *array;
this = njs_argument(args, 0);
return NJS_OK;
}
- if (njs_is_fast_array(this)) {
- array = njs_array(this);
-
- for (l = 0, h = length - 1; l < h; l++, h--) {
- if (njs_fast_path(njs_is_valid(&array->start[l]))) {
- lvalue = array->start[l];
- lret = NJS_OK;
-
- } else {
- lret = njs_value_property_i64(vm, this, l, &lvalue);
- if (njs_slow_path(lret == NJS_ERROR)) {
- return NJS_ERROR;
- }
- }
-
- if (njs_fast_path(njs_is_valid(&array->start[h]))) {
- hvalue = array->start[h];
- hret = NJS_OK;
-
- } else {
- hret = njs_value_property_i64(vm, this, h, &hvalue);
- if (njs_slow_path(hret == NJS_ERROR)) {
- return NJS_ERROR;
- }
- }
-
- if (lret == NJS_OK) {
- array->start[h] = lvalue;
-
- if (hret == NJS_OK) {
- array->start[l] = hvalue;
-
- } else {
- array->start[l] = njs_value_invalid;
- }
-
- } else if (hret == NJS_OK) {
- array->start[l] = hvalue;
- array->start[h] = njs_value_invalid;
- }
- }
-
- njs_set_array(&vm->retval, array);
- return NJS_OK;
- }
-
for (l = 0, h = length - 1; l < h; l++, h--) {
lret = njs_value_property_i64(vm, this, l, &lvalue);
if (njs_slow_path(lret == NJS_ERROR)) {
{ njs_str("[,,,3,2,1].reverse()"),
njs_str("1,2,3,,,") },
+ { njs_str("var a = [,,2,1];"
+ "Object.defineProperty(a.__proto__, 0, {"
+ " get: () => {"
+ " a.length = 10**6;"
+ " return 4;"
+ " },"
+ " set: (setval) => { Object.defineProperty(a, 0, { value: setval }); },"
+ "});"
+ "a.reverse();"
+ "a.slice(0, 4)"),
+ njs_str("1,2,,4") },
+
{ njs_str("var o = {1:true, 2:'', length:-2}; Array.prototype.reverse.call(o) === o"),
njs_str("true") },