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

Fuzzers: Convert FuzzCSSParser to use the MainThreadVM

Instead of trying to create a Window and a Document, and use those to
create a ParsingContext, just use the JS::Realm only constructor to make
sure that bindings are stashed on the main thread VM's realm.
This commit is contained in:
Andrew Kaster 2022-09-30 19:01:42 -06:00 committed by Linus Groh
parent 45838579c3
commit cc164dc1e2

View file

@ -4,18 +4,21 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/EventLoop.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Platform/EventLoopPluginSerenity.h>
namespace {
struct Globals {
Globals();
} globals;
Globals::Globals() { Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity); }
}
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
Core::EventLoop loop;
auto vm = JS::VM::create();
auto realm = JS::Realm::create(*vm);
auto window = Web::HTML::Window::create(*realm);
auto document = Web::DOM::Document::create(*window);
(void)Web::parse_css_stylesheet(Web::CSS::Parser::ParsingContext(document), { data, size });
// FIXME: There's got to be a better way to do this "correctly"
auto& vm = Web::Bindings::main_thread_vm();
(void)Web::parse_css_stylesheet(Web::CSS::Parser::ParsingContext(*vm.current_realm()), { data, size });
return 0;
}