From cc164dc1e2441192020ca04f782763ce33893558 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 30 Sep 2022 19:01:42 -0600 Subject: [PATCH] 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. --- Meta/Lagom/Fuzzers/FuzzCSSParser.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp b/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp index 68c81bb512..e31f44a5fe 100644 --- a/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp +++ b/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp @@ -4,18 +4,21 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include -#include -#include +#include + +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; }