1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:47:36 +00:00

LibJS: Throw SyntaxError in eval() when parser has error(s)

This commit is contained in:
Linus Groh 2021-03-15 22:08:28 +01:00 committed by Andreas Kling
parent 01a49dda85
commit d6239b691f
2 changed files with 15 additions and 0 deletions

View file

@ -322,6 +322,12 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::eval)
JS::Parser parser { JS::Lexer { code } };
auto program = parser.parse_program();
if (parser.has_errors()) {
auto& error = parser.errors()[0];
vm.throw_exception<SyntaxError>(global_object, error.to_string());
return {};
}
auto& caller_frame = vm.call_stack().at(vm.call_stack().size() - 2);
TemporaryChange scope_change(vm.call_frame().scope, caller_frame->scope);