mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:57:34 +00:00
LibJS: Don't generate bytecode after we've encountered a parser error
This commit is contained in:
parent
319a60043b
commit
3a8f913eee
1 changed files with 20 additions and 20 deletions
|
@ -512,6 +512,13 @@ static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source
|
||||||
if (s_dump_ast)
|
if (s_dump_ast)
|
||||||
program->dump(0);
|
program->dump(0);
|
||||||
|
|
||||||
|
if (parser.has_errors()) {
|
||||||
|
auto error = parser.errors()[0];
|
||||||
|
auto hint = error.source_location_hint(source);
|
||||||
|
if (!hint.is_empty())
|
||||||
|
outln("{}", hint);
|
||||||
|
vm->throw_exception<JS::SyntaxError>(interpreter.global_object(), error.to_string());
|
||||||
|
} else {
|
||||||
if (s_dump_bytecode || s_run_bytecode) {
|
if (s_dump_bytecode || s_run_bytecode) {
|
||||||
auto unit = JS::Bytecode::Generator::generate(*program);
|
auto unit = JS::Bytecode::Generator::generate(*program);
|
||||||
if (s_dump_bytecode) {
|
if (s_dump_bytecode) {
|
||||||
|
@ -529,17 +536,10 @@ static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
if (parser.has_errors()) {
|
|
||||||
auto error = parser.errors()[0];
|
|
||||||
auto hint = error.source_location_hint(source);
|
|
||||||
if (!hint.is_empty())
|
|
||||||
outln("{}", hint);
|
|
||||||
vm->throw_exception<JS::SyntaxError>(interpreter.global_object(), error.to_string());
|
|
||||||
} else {
|
} else {
|
||||||
interpreter.run(interpreter.global_object(), *program);
|
interpreter.run(interpreter.global_object(), *program);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto handle_exception = [&] {
|
auto handle_exception = [&] {
|
||||||
auto* exception = vm->exception();
|
auto* exception = vm->exception();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue