summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2021-03-11vm: gracefully handle property setting on non-array, non-object valuesJo-Philipp Wich
Before this fix, the VM aborted due to an assert in libjson-c when an attempt was made to set a property on a non-object value. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11compiler: fix switch case->default fallthroughJo-Philipp Wich
Simplify handling of default case in switch statements. Instead of jumping over the default block, simply record the start address of the block since the initial switch jump is patched into the first non-default case already. This also leads to slightly smaller bytecode. Previously, when a case branch fell through into a default block, it did hit the default skip jump which jumped back into the first case which then fell through into the default skip jump, leading to an endless loop. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11run_tests.sh: add various fixes and improvementsJo-Philipp Wich
- Report encountered stderr/stdout when none is expected - Fix processing testcases where the code to run is defined first - Set module search path to source tree to enable loading C extensions Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-09lib: prevent possible use-after-free in uc_pop()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08object: remove unused struct memberJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08lib: retain prototype when passing scopes to include()Jo-Philipp Wich
Change uc_include() to retain the prototype of the given scope object when processing includes. Also change the default behaviour to register the current VM scope as prototype on the passed scope object so that included code has access to functions such as length(), print() etc. by default. To actually sandbox the included code, the new `proto()` function can be used to create a scope object with an empty prototype: `include(..., proto({ ... }, {}))` Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08main: expose global prototype as `global` property on root scopeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08lib: use uc_prototype_lookup() to obain search path property valueJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08vm: use uc_prototype_lookup() to obtain require function pointerJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08object: introduce uc_prototype_lookup()Jo-Philipp Wich
The new uc_prototype_lookup() function allows looking up properties in the given prototype chain. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08fs: make error function available on directory, process and file handlesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08ubus: make error function available on the connection instanceJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08uci: fix potential invalid memory access in error()Jo-Philipp Wich
Check the numerical error code index before attempting to look it up in the error string array. Also make error function available on the cursor instance as well. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08fs: fix readlink() return valueJo-Philipp Wich
The fs.readlink() function incorrectly produced a JSON string containing trailing null bytes. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08value: ensure proper result of relational NaN comparisonJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08lib: introduce new proto() ucode functionJo-Philipp Wich
The proto() function allows getting and setting the prototype value of array or object values, which is useful to build object instances. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08object: introduce uc_protoref_new()Jo-Philipp Wich
The new uc_protoref_new() function allows creating array or object values with prototype references. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08value: support traversing the prototype chain of array valuesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08vm: fix global scope refcount imbalanceJo-Philipp Wich
The uc_vm_execute() API function decreases the refcount of the globals object when finishing but does not increase it initially which leads to a double free at main.c:155 Fix the issue by both increasing and decreasing the refcount. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08README.md: document trace() functionJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-02-26compiler: fix try/catch miscompilationJo-Philipp Wich
When skipping catch blocks with exception variables, jump beyond the instruction popping the exception variable off the stack to fix a stack position mismatch between compiler and vm. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-02-26lexer: improvementsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-02-25vm: use portable printf format for pointer differencesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-02-17Merge pull request #2 from jow-/rewriteJo-Philipp Wich
treewide: rewrite ucode interpreter
2021-02-17syntax: support ES2015 computed property namesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-02-17syntax: support ES2015 shorthand property namesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-02-17treewide: rewrite ucode interpreterJo-Philipp Wich
Replace the former AST walking interpreter implementation with a single pass bytecode compiler and a corresponding virtual machine. The rewrite lays the groundwork for a couple of improvements with will be subsequently implemented: - Ability to precompile ucode sources into binary byte code - Strippable debug information - Reduced runtime memory usage Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-12-07uci: fix -Werror=maybe-uninitialized warningJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-12-07ubus: fix uninitialized pointer return in uc_ubus_call() and uc_ubus_list()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-12-07eval: fix use-after-free in uc_invoke() error pathJo-Philipp Wich
Since we're putting the intermediate JSON return value, the associated tag info will get freed as well, resulting in use-after-free when raising a syntax error due to usage of continue or break outside of loop structures. Read the tag type and offset values before releasing the intermediate `rv` value. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-12-06treewide: prevent stale pointer access in opcode handlersJo-Philipp Wich
Instead of obtaining and caching direct opcode pointers, use relative references when dealing with opcodes since direct or indirect calls to uc_execute_op() might lead to reallocations of the opcode array, shifting memory addresses and invalidating pointers taken before the invocation. Such stale pointer accesses could be commonly triggered when one part of the processed expression was a require() or include() call loading relatively large ucode sources. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-30syntax: fix quirks when parsing octal sequencesJo-Philipp Wich
- Eliminate dead code left after regex literal parsing changes - Properly handle short octal sequences at end of string Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-30syntax: recognize single-char escapes in regex literals againJo-Philipp Wich
Ensure that the single char escapes `\a`, `\b`, `\e`, `\f`, `\n`, `\r`, `\t` and `\v` keep working. Since they're not part of the POSIX extended regular expression spec, they're not handled by the RE engine so we need to substitute them by their actual byte value while parsing the literal. Fixes: ac5cb87 ("syntax: fix string and regex literal parsing quirks") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-30syntax: fix string and regex literal parsing quirksJo-Philipp Wich
- Do not interprete escape sequences in regexp literals - Do not improperly substitute control escape sequences such as `\n` or `\a` after a backslash Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-30tests: fix testcasesJo-Philipp Wich
Fixes: 8b4d0d5 ("tests: prefer `let` over `local`") Fixes: a162cf7 ("treewide: rebrand to ucode") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-19tests: prefer `let` over `local`Jo-Philipp Wich
Promote the use of `let` to move ucode examples closer to ES syntax. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-19treewide: rebrand to ucodeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-16lib: optimize length() for objectsJo-Philipp Wich
Instead of counting the keys individually, use the existing json_object_object_length() function. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-16lib: extend length() to handle objectsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-16lib: extend ord() to allow reading byte values at arbitrary indexesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-16README.md: fix typosJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-16lib: add system() functionJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-15fs: extend process close() function to return program exit codeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-15lexer: improve scanner performanceJo-Philipp Wich
Optimize the strncmp() based token lookup with an integer comparison approach which roughly cuts the time of the source code parsing phase in half. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-12parser: reuse T_FUNC nodes when creating anonymous function valuesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-12ast: simplify declaration AST structureJo-Philipp Wich
Do not emit dummy T_ASSIGN nodes for plain variable declarations without initialization (`let foo` or `local foo`). This also allows simplifying `ut_check_for_in()` since we only need to deal with one common structure for both `for (... in ...)` and `for (local ... in ...)` cases. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-12syntax: implement key/value for-in loop iterationJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-10fs: do not close stdio streams when gc'ing scopeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-10main: fix double free when using multiple -E optionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-10lexer: accept "let" as synonym for "local"Jo-Philipp Wich
This brings the utpl script syntax closer to ES5/ES6 and allows to use existing syntax highlightings in IDEs and editors. Signed-off-by: Jo-Philipp Wich <jo@mein.io>