return NJS_ERROR;
}
- njs_set_array(retval, array);
-
if (array->object.fast_array) {
for (i = 0; i < length; i++) {
array->start[i] = args[i + 1];
}
}
+ njs_set_array(retval, array);
+
return NJS_OK;
}
{
int64_t i, n, r, start, length, to_insert, to_skip, new_length;
njs_int_t ret;
- njs_value_t *this, value;
+ njs_value_t *this, a, value;
njs_array_t *array;
this = njs_argument(args, 0);
return NJS_ERROR;
}
- njs_set_array(retval, array);
+ njs_set_array(&a, array);
for (i = 0; i < start; i++) {
ret = njs_value_property_i64(vm, this, i, &value);
return NJS_ERROR;
}
- ret = njs_value_create_data_prop_i64(vm, retval, i, &value, 0);
+ ret = njs_value_create_data_prop_i64(vm, &a, i, &value, 0);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
}
for (n = 3; to_insert-- > 0; i++, n++) {
- ret = njs_value_create_data_prop_i64(vm, retval, i, &args[n], 0);
+ ret = njs_value_create_data_prop_i64(vm, &a, i, &args[n], 0);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
return NJS_ERROR;
}
- ret = njs_value_create_data_prop_i64(vm, retval, i, &value, 0);
+ ret = njs_value_create_data_prop_i64(vm, &a, i, &value, 0);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
i++;
}
+ njs_set_array(retval, array);
+
return NJS_OK;
}
int64_t length, i;
njs_int_t ret;
njs_array_t *array;
- njs_value_t *this, value;
+ njs_value_t *this, a, value;
this = njs_argument(args, 0);
return NJS_ERROR;
}
- njs_set_array(retval, array);
+ njs_set_array(&a, array);
for (i = 0; i < length; i++) {
ret = njs_value_property_i64(vm, this, length - i - 1, &value);
return NJS_ERROR;
}
- ret = njs_value_create_data_prop_i64(vm, retval, i, &value, 0);
+ ret = njs_value_create_data_prop_i64(vm, &a, i, &value, 0);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
}
+ njs_set_array(retval, array);
+
return NJS_OK;
}
int64_t i, nslots, nunds, length;
njs_int_t ret;
njs_array_t *array;
- njs_value_t *this, *comparefn;
+ njs_value_t *this, *comparefn, a;
njs_function_t *compare;
njs_array_sort_slot_t *slots;
njs_assert(length == (nslots + nunds));
- njs_set_array(retval, array);
+ njs_set_array(&a, array);
for (i = 0; i < nslots; i++) {
- ret = njs_value_property_i64_set(vm, retval, i, &slots[i].value);
- if (njs_slow_path(ret == NJS_ERROR)) {
+ ret = njs_value_create_data_prop_i64(vm, &a, i, &slots[i].value, 0);
+ if (njs_slow_path(ret != NJS_OK)) {
goto exception;
}
}
for (; i < length; i++) {
- ret = njs_value_property_i64_set(vm, retval, i,
- njs_value_arg(&njs_value_undefined));
- if (njs_slow_path(ret == NJS_ERROR)) {
+ ret = njs_value_create_data_prop_i64(vm, &a, i,
+ njs_value_arg(&njs_value_undefined), 0);
+ if (njs_slow_path(ret != NJS_OK)) {
goto exception;
}
}
ret = NJS_OK;
+ njs_set_array(retval, array);
exception:
{ njs_str("'/A/B/C/D/'.split('/').toSpliced(1,1).join('/')"),
njs_str("/B/C/D/") },
+ { njs_str("let r, arr = new Array(4);"
+ "Object.defineProperty(arr, 0, { get: () => { throw 'Oops'; } });"
+ "try { r = arr.toSpliced(0, 0); } catch (e) { }"
+ "r.toString()"),
+ njs_str("TypeError: cannot get property \"toString\" of undefined") },
+
{ njs_str("var a = []; a.reverse()"),
njs_str("") },
{ njs_str("Array.prototype[0] = 0; var x = [,1]; x.reverse(); x"),
njs_str("1,0") },
+ { njs_str("let r, arr = new Array(4);"
+ "Object.defineProperty(arr, 0, { get: () => { throw 'Oops'; } });"
+ "try { r = arr.toReversed(0, 0); } catch (e) { }"
+ "r.toString()"),
+ njs_str("TypeError: cannot get property \"toString\" of undefined") },
+
{ njs_str("var a = [,3,2,1]; njs.dump([a.toReversed(),a])"),
njs_str("[[1,2,3,undefined],[<empty>,3,2,1]]") },