2020-05-09 09:23:26 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-09 09:23:26 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-04-08 05:40:02 -03:00
|
|
|
#include <AK/StringView.h>
|
2021-01-03 12:01:36 -03:00
|
|
|
#include <LibJS/Interpreter.h>
|
2020-04-08 05:40:02 -03:00
|
|
|
#include <LibJS/Lexer.h>
|
|
|
|
|
#include <LibJS/Parser.h>
|
2021-01-03 12:01:36 -03:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2020-04-08 05:40:02 -03:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
|
|
|
|
{
|
2021-02-25 17:10:47 -03:00
|
|
|
auto js = StringView(static_cast<const unsigned char*>(data), size);
|
2020-04-08 05:40:02 -03:00
|
|
|
auto lexer = JS::Lexer(js);
|
|
|
|
|
auto parser = JS::Parser(lexer);
|
2021-01-03 12:01:36 -03:00
|
|
|
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);
|
|
|
|
|
}
|
2020-04-08 05:40:02 -03:00
|
|
|
return 0;
|
|
|
|
|
}
|