quickjs-ng / quickjs

QuickJS, the Next Generation: a mighty JavaScript engine
https://quickjs-ng.github.io/quickjs/
MIT License
967 stars 79 forks source link

Improve parsing error messages #405

Closed chqrlie closed 4 months ago

chqrlie commented 4 months ago

The previous code was bogus:

    return js_parse_error(s, "expecting '%c'", tok);

this was causing a bug on eval("do;") where tok is TOK_WHILE (-70, 0xBA) creating an invalid UTF-8 encoding (lone trailing byte). This would ultimately have caused a failure in JS_ThrowError2 if JS_NewString failed when converting an error to a string if the conversion detects invalid UTF-8 encoding and throws an error (it currently does not, but should).