summaryrefslogtreecommitdiffhomepage
path: root/vm.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-05-18 10:45:21 +0200
committerJo-Philipp Wich <jo@mein.io>2021-05-18 13:11:33 +0200
commitff6811f29065951ab3917460f3d76ffe6ddb0c81 (patch)
tree7d3925b2640c9dfc07959faaf866699d77a30d00 /vm.c
parent5803d8605b84ef362cc7f96f9e523eff5d0d81bc (diff)
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 <jo@mein.io>
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/vm.c b/vm.c
index 5b7b5e8..8a503a0 100644
--- a/vm.c
+++ b/vm.c
@@ -1918,6 +1918,31 @@ uc_vm_insn_print(uc_vm *vm, enum insn_type insn)
ucv_put(v);
}
+static void
+uc_vm_insn_delete(uc_vm *vm, enum insn_type insn)
+{
+ uc_value_t *k = uc_vm_stack_pop(vm);
+ uc_value_t *v = uc_vm_stack_pop(vm);
+ bool rv;
+
+ switch (ucv_type(v)) {
+ case UC_OBJECT:
+ rv = uc_delval(vm, v, k);
+ uc_vm_stack_push(vm, ucv_boolean_new(rv));
+ break;
+
+ default:
+ uc_vm_raise_exception(vm, EXCEPTION_REFERENCE,
+ "left-hand side expression is %s",
+ v ? "not an object" : "null");
+
+ break;
+ }
+
+ ucv_put(k);
+ ucv_put(v);
+}
+
static uc_value_t *
uc_vm_callframe_pop(uc_vm *vm)
{
@@ -2186,6 +2211,10 @@ uc_vm_execute_chunk(uc_vm *vm)
uc_vm_insn_print(vm, insn);
break;
+ case I_DELETE:
+ uc_vm_insn_delete(vm, insn);
+ break;
+
default:
uc_vm_raise_exception(vm, EXCEPTION_RUNTIME, "unknown opcode %d", insn);
break;