Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions elk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@ static jsval_t js_stmt(struct js *js) {
default: res = resolveprop(js, js_expr(js)); break;
}
//printf("STMT [%.*s] -> %s, tok %d, flags %d\n", (int) (js->pos - pos), &js->code[pos], js_str(js, res), next(js), js->flags);
if (is_err(res)) return res; // Preserve the original runtime error; do not clobber it with a "; expected" parse error below.
if (next(js) != TOK_SEMICOLON && next(js) != TOK_EOF && next(js) != TOK_RBRACE) return js_mkerr(js, "; expected");
js->consumed = 1;
// clang-format on
Expand Down
6 changes: 6 additions & 0 deletions test/unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@ static void test_c_funcs(void) {
assert(ev(js, "gt(0.78,-12.5)", "true"));
// assert(ev(js, "gt(2,2)", "true"));

// A runtime error returned from a C function should be preserved even when
// it appears as part of a larger expression (the trailing operator/operand
// must not be misreported as "; expected").
assert(ev(js, "gt() * 2", "ERROR: doh"));
assert(ev(js, "1 + gt(null, 1)", "ERROR: doh"));

js_set(js, js_glob(js), "set_timer", js_mkfun(js_set_timer));
js_eval(js, "let v = 0, f = function(x) { v+=x; };", ~0UL);
js_eval(js, "set_timer('f');", ~0UL);
Expand Down