summaryrefslogtreecommitdiffhomepage
path: root/tests
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-09lib: prevent possible use-after-free in uc_pop()Jo-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-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-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-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-09syntax: properly handle list expressions in function callsJo-Philipp Wich
Ensure that a call like `fn((1, 2), 3)` invokes the function with arguments `2, 3` and not `1, 2, 3`. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-05eval: rework handling of list expressionsJo-Philipp Wich
Tune the grammar and rework the VM to properly yield the last result of list expressions in various contexts. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-05syntax: implement ES6-like arrow function syntaxJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-04tests: add illegal syntax tests for rest argumentsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-03syntax: implement ES6-like spread operatorJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-03syntax: implement ES6-like rest parameters for variadic functionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-02syntax: support `elif` clauses for alternative `if` syntaxJo-Philipp Wich
In the alternative `if` syntax mode, support a specific `elif` keyword instead of requiring an `else` branch followed by a disjunct `if` statement. The advantage is that templates do not require error-prone redundant `endif` keywords in else-if ladders. After this change, the following example: {% if (...): %} One condition {% else if (...): %} Another condition {% else if (...): %} A third condition {% else %} Final condition {% endif; endif; endif %} ... can be simplified into: {% if (...): %} One condition {% elif (...): %} Another condition {% elif (...): %} A third condition {% else %} Final condition {% endif %} Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-19eval: record correct source contexts in call stackJo-Philipp Wich
Also handle calls to C functions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-18ast, eval: add recursion limitJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-18eval: fix segmentation faults with self-invoking functionsJo-Philipp Wich
Store the invocation scope and function context in the call stack frame and not in the function object to properly deal with recursive invocations. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-15syntax: allow consecutive case valuesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-14treewide: unify error handlingJo-Philipp Wich
Get rid of the distinction between lexer/parser errors and runtime exceptions, use exceptions everywhere instead. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-14treewide: rework source file and callstack handlingJo-Philipp Wich
- Keep an open FILE* reference to processed source files in order to be able to rewind and extract error context later - Build a proper call stack when invoking utpl functions - Report call stack in exceptions Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-14lexer: rewriteJo-Philipp Wich
Rewrite the lexer into a restartable state machine to support parsing from file streams without the need to read the entire source text into memory first. As a side effect, the length of labels and strings is unlimited now. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-06eval: properly break out of switch/case on return/continue/exceptionJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-06eval: restore context pointer of first evaluated dot/bracket expressionJo-Philipp Wich
When an expression such as `foo.bar(a.b, c.d)` is evaluated, the state context pointer will point to `c` while we need `foo` when invoking functions. Since the context pointer is only relevant for function calls and since for function call opcodes, the lhs expression is always the first operand, there is no need to store the context of subsequent ops. Adjust the ut_get_operands() procedure to restore state->ctx to the result of the first evaluated operand. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-04treewide: rework function scopingJo-Philipp Wich
- Implement proper closure scoping for function - Avoid circular references when managing scopes pointers - Eliminate ut_putval() in favor to json_object_put() - Fix function return value handling - Change internal function structure Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-22syntax: allow empty switch statementsJo-Philipp Wich
Also add testcases for switch/case blocks. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-21tests: add try/catch testcaseJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-21tests: fix `this` context testcaseJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-15tests: add test for "this" contextJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-15eval: only set "this" scope for functions being object membersJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-14tests: add initial runtime testsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-13tests: extend for-loop tests to cover local variantsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10treewide: implement default lstrip_blocks and trim_blocks behaviourJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-08tests: add further arithmetic and syntax test casesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-07tests: add object/array literal and arithmetic test casesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-07tests: introduce testcasesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>