Coverage Report

Created: 2025-03-04 07:22

/src/serenity/Meta/Lagom/Fuzzers/FuzzJs.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2020, the SerenityOS developers.
3
 * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
4
 *
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#include <AK/StringView.h>
9
#include <LibJS/Bytecode/Interpreter.h>
10
#include <LibJS/Runtime/GlobalObject.h>
11
#include <LibJS/Script.h>
12
#include <stddef.h>
13
#include <stdint.h>
14
15
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
16
68
{
17
68
    AK::set_debug_enabled(false);
18
68
    auto js = StringView(static_cast<unsigned char const*>(data), size);
19
    // FIXME: https://github.com/SerenityOS/serenity/issues/17899
20
68
    if (!Utf8View(js).validate())
21
6
        return 0;
22
62
    auto vm = MUST(JS::VM::create());
23
0
    auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
24
62
    auto& realm = *root_execution_context->realm;
25
62
    auto parse_result = JS::Script::parse(js, realm);
26
62
    if (!parse_result.is_error())
27
16
        (void)vm->bytecode_interpreter().run(parse_result.value());
28
29
62
    return 0;
30
62
}