From ff6811f29065951ab3917460f3d76ffe6ddb0c81 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 18 May 2021 10:45:21 +0200 Subject: syntax: implement `delete` as proper operator Turn `delete` into a proper operator mimicking ECMAScript semantics. Also ensure to transparently turn deprecated `delete(obj, propname)` function calls into `delete obj.propname` expressions during compilation. When strict mode is active, legacy delete() calls throw a syntax error instead. Finally drop the `delete()` function from the stdlib as it is shadowed by the delete operator syntax now. Signed-off-by: Jo-Philipp Wich --- lib.c | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index e6b7135..c3a1599 100644 --- a/lib.c +++ b/lib.c @@ -452,35 +452,6 @@ uc_chr(uc_vm *vm, size_t nargs) return rv; } -static uc_value_t * -uc_delete(uc_vm *vm, size_t nargs) -{ - uc_value_t *obj = uc_get_arg(0); - uc_value_t *key = NULL; - uc_value_t *rv = NULL; - bool freeable; - size_t i; - char *k; - - if (ucv_type(obj) != UC_OBJECT) - return NULL; - - for (i = 1; i < nargs; i++) { - ucv_put(rv); - - key = uc_get_arg(i); - k = uc_cast_string(vm, &key, &freeable); - rv = ucv_get(ucv_object_get(obj, k, NULL)); - - ucv_object_delete(obj, k); - - if (freeable) - free(k); - } - - return rv; -} - static uc_value_t * uc_die(uc_vm *vm, size_t nargs) { @@ -2553,7 +2524,6 @@ uc_wildcard(uc_vm *vm, size_t nargs) static const uc_cfunction_list functions[] = { { "chr", uc_chr }, - { "delete", uc_delete }, { "die", uc_die }, { "exists", uc_exists }, { "exit", uc_exit }, -- cgit v1.2.3