diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-05-04 14:15:20 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-05-04 15:31:15 +0200 |
commit | a36e0dfd8432a0c345ab3a710280f6d4f663bddc (patch) | |
tree | 73e08e12a669b2c3afbbaca58f123b59b589b96c /vm.c | |
parent | 776dc9e3166dfc3735bd72be3acd26ebc6a591f5 (diff) |
syntax: implement support for 'use strict' pragma
Support per-file and per-function `"use strict";` statement to opt into
strict variable handling from ucode source code.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -197,6 +197,12 @@ uc_vm_current_chunk(uc_vm *vm) return uc_vm_frame_chunk(uc_vm_current_frame(vm)); } +static bool +uc_vm_is_strict(uc_vm *vm) +{ + return uc_vm_current_frame(vm)->strict; +} + static enum insn_type uc_vm_decode_insn(uc_vm *vm, uc_callframe *frame, uc_chunk *chunk) { @@ -542,6 +548,7 @@ uc_vm_call_function(uc_vm *vm, uc_value_t *ctx, uc_value_t *fno, bool mcall, siz frame->ctx = ctx; frame->ip = function->chunk.entries; frame->mcall = mcall; + frame->strict = function->strict; if (vm->trace) uc_vm_frame_dump(vm, frame); @@ -958,7 +965,7 @@ uc_vm_insn_load_var(uc_vm *vm, enum insn_type insn) next = ucv_prototype_get(scope); if (!next) { - if (vm->config->strict_declarations) { + if (uc_vm_is_strict(vm)) { uc_vm_raise_exception(vm, EXCEPTION_REFERENCE, "access to undeclared variable %s", ucv_string_get(name)); @@ -1131,7 +1138,7 @@ uc_vm_insn_store_var(uc_vm *vm, enum insn_type insn) next = ucv_prototype_get(scope); if (!next) { - if (vm->config->strict_declarations) { + if (uc_vm_is_strict(vm)) { uc_vm_raise_exception(vm, EXCEPTION_REFERENCE, "access to undeclared variable %s", ucv_string_get(name)); @@ -1374,7 +1381,7 @@ uc_vm_insn_update_var(uc_vm *vm, enum insn_type insn) next = ucv_prototype_get(scope); if (!next) { - if (vm->config->strict_declarations) { + if (uc_vm_is_strict(vm)) { uc_vm_raise_exception(vm, EXCEPTION_REFERENCE, "access to undeclared variable %s", ucv_string_get(name)); @@ -2289,6 +2296,7 @@ uc_vm_execute(uc_vm *vm, uc_function_t *fn, uc_value_t *globals, uc_value_t *mod frame->closure = closure; frame->stackframe = 0; frame->ip = uc_vm_frame_chunk(frame)->entries; + frame->strict = fn->strict; if (vm->trace) { buf = xprintbuf_new(); |