1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:18:12 +00:00

LibJS: Make ASTNode::generate_bytecode() fallible

Instead of crashing on the spot, return a descriptive error that will
eventually continue its days as a javascript "InternalError" exception.
This should make random crashes with BC less likely.
This commit is contained in:
Ali Mohammad Pur 2022-02-12 19:54:08 +03:30 committed by Linus Groh
parent 3a5f7cb524
commit 75aa900b83
10 changed files with 378 additions and 233 deletions

View file

@ -22,9 +22,9 @@
auto const& program = script->parse_node(); \
JS::Bytecode::Interpreter bytecode_interpreter(ast_interpreter->global_object(), ast_interpreter->realm());
#define EXPECT_NO_EXCEPTION(executable) \
auto executable = JS::Bytecode::Generator::generate(program); \
auto result = bytecode_interpreter.run(*executable); \
#define EXPECT_NO_EXCEPTION(executable) \
auto executable = MUST(JS::Bytecode::Generator::generate(program)); \
auto result = bytecode_interpreter.run(*executable); \
EXPECT(!result.is_error());
#define EXPECT_NO_EXCEPTION_WITH_OPTIMIZATIONS(executable) \
@ -54,7 +54,7 @@ TEST_CASE(if_statement_fail)
{
SETUP_AND_PARSE("if (true) throw new Exception('failed');");
auto executable = JS::Bytecode::Generator::generate(program);
auto executable = MUST(JS::Bytecode::Generator::generate(program));
auto result = bytecode_interpreter.run(*executable);
EXPECT(result.is_error());
}
@ -112,7 +112,7 @@ TEST_CASE(loading_multiple_files)
auto test_file_script = test_file_script_or_error.release_value();
auto const& test_file_program = test_file_script->parse_node();
auto executable = JS::Bytecode::Generator::generate(test_file_program);
auto executable = MUST(JS::Bytecode::Generator::generate(test_file_program));
auto result = bytecode_interpreter.run(*executable);
EXPECT(!result.is_error());
}