FuzzJs: If the program successfully parsed, try running it

This should help us get a lot more coverage in LibJS.
This commit is contained in:
Luke 2021-01-03 15:01:36 +00:00 committed by Andreas Kling
parent 7bb18215cb
commit c49899b0b6
Notes: sideshowbarker 2024-07-19 00:10:04 +09:00

View file

@ -25,8 +25,10 @@
*/
#include <AK/StringView.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Lexer.h>
#include <LibJS/Parser.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <stddef.h>
#include <stdint.h>
@ -35,6 +37,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
auto js = AK::StringView(static_cast<const unsigned char*>(data), size);
auto lexer = JS::Lexer(js);
auto parser = JS::Parser(lexer);
parser.parse_program();
auto program = parser.parse_program();
if (!parser.has_errors()) {
auto vm = JS::VM::create();
auto interpreter = JS::Interpreter::create<JS::GlobalObject>(*vm);
interpreter->run(interpreter->global_object(), *program);
}
return 0;
}