summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2023-01-23 11:36:31 +0100
committerJo-Philipp Wich <jo@mein.io>2023-01-23 11:36:31 +0100
commitf1be0d725735fd8dd489494b00e954a93223f722 (patch)
tree2a433e6506d6cd3a61bf75f4829de46f22c9a9af /lib.c
parent48a6eac1da1584ea784fd7d53f761baa87ae84d2 (diff)
types: fix array unshift operations and add test coverage
- Fix `ucv_array_unshift()` improperly rejecting operation on empty arrays - Fix `uc_unshift()` improperly reversing maintaining argument order - Add missing test coverage for `push()`, `pop()`, `unshift()` and `shift()` array operations. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index 0366a13..a0a1b9b 100644
--- a/lib.c
+++ b/lib.c
@@ -464,18 +464,18 @@ static uc_value_t *
uc_unshift(uc_vm_t *vm, size_t nargs)
{
uc_value_t *arr = uc_fn_arg(0);
- uc_value_t *item = NULL;
+ uc_value_t *item;
size_t i;
if (!assert_mutable_array(vm, arr))
return NULL;
for (i = 1; i < nargs; i++) {
- item = uc_fn_arg(i);
+ item = uc_fn_arg(nargs - i);
ucv_array_unshift(arr, ucv_get(item));
}
- return ucv_get(item);
+ return (nargs > 1) ? ucv_get(uc_fn_arg(nargs - 1)) : NULL;
}
static uc_value_t *