diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-05-18 10:45:21 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-05-18 13:11:33 +0200 |
commit | ff6811f29065951ab3917460f3d76ffe6ddb0c81 (patch) | |
tree | 7d3925b2640c9dfc07959faaf866699d77a30d00 /vm.c | |
parent | 5803d8605b84ef362cc7f96f9e523eff5d0d81bc (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.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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; |