diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-01-16 13:16:04 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-22 01:21:18 +0000 |
commit | 631bbcd00a32773aa22ece270ba00628c1240d4c (patch) | |
tree | a12959a306d8a47ffe3f343942e69b9f4abb2a82 /Meta/Lagom/Fuzzers | |
parent | 232a8432b7f879140c50df8114b7467f45e99349 (diff) | |
download | serenity-631bbcd00a32773aa22ece270ba00628c1240d4c.zip |
LibJS: Refactor interpreter to use Script and Source Text Modules
This also refactors interpreter creation to follow
InitializeHostDefinedRealm, but I couldn't fit it in the title :^)
This allows us to follow the spec much more closely rather than being
completely ad-hoc with just the parse node instead of having all the
surrounding data such as the realm of the parse node.
The interpreter creation refactor creates the global execution context
once and doesn't take it off the stack. This allows LibWeb to take the
global execution context and manually handle it, following the HTML
spec. The HTML spec calls this the "realm execution context" of the
environment settings object.
It also allows us to specify the globalThis type, as it can be
different from the global object type. For example, on the web, Window
global objects use a WindowProxy global this value to enforce the same
origin policy on operations like [[GetOwnProperty]].
Finally, it allows us to directly call Program::execute in perform_eval
and perform_shadow_realm_eval as this moves
global_declaration_instantiation into Interpreter::run
(ScriptEvaluation) as per the spec.
Note that this doesn't evalulate Source Text Modules yet or refactor
the bytecode interpreter, that's work for future us :^)
This patch was originally build by Luke for the environment settings
object change but was also needed for modules. So I (davidot) have
modified it with the new completion changes and setup for that.
Co-authored-by: davidot <davidot@serenityos.org>
Diffstat (limited to 'Meta/Lagom/Fuzzers')
-rw-r--r-- | Meta/Lagom/Fuzzers/FuzzJs.cpp | 18 | ||||
-rw-r--r-- | Meta/Lagom/Fuzzers/FuzzilliJs.cpp | 8 |
2 files changed, 11 insertions, 15 deletions
diff --git a/Meta/Lagom/Fuzzers/FuzzJs.cpp b/Meta/Lagom/Fuzzers/FuzzJs.cpp index 19dcb8a404..b10b03a54a 100644 --- a/Meta/Lagom/Fuzzers/FuzzJs.cpp +++ b/Meta/Lagom/Fuzzers/FuzzJs.cpp @@ -1,27 +1,25 @@ /* * Copyright (c) 2020, the SerenityOS developers. + * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #include <AK/StringView.h> #include <LibJS/Interpreter.h> -#include <LibJS/Lexer.h> -#include <LibJS/Parser.h> #include <LibJS/Runtime/GlobalObject.h> +#include <LibJS/Script.h> #include <stddef.h> #include <stdint.h> extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { auto js = StringView(static_cast<const unsigned char*>(data), size); - auto lexer = JS::Lexer(js); - auto parser = JS::Parser(lexer); - auto program = parser.parse_program(); - if (!parser.has_errors()) { - auto vm = JS::VM::create(); - auto interpreter = JS::Interpreter::create<JS::GlobalObject>(*vm); - (void)interpreter->run(interpreter->global_object(), *program); - } + auto vm = JS::VM::create(); + auto interpreter = JS::Interpreter::create<JS::GlobalObject>(*vm); + auto parse_result = JS::Script::parse(js, interpreter->realm()); + if (!parse_result.is_error()) + (void)interpreter->run(parse_result.value()); + return 0; } diff --git a/Meta/Lagom/Fuzzers/FuzzilliJs.cpp b/Meta/Lagom/Fuzzers/FuzzilliJs.cpp index 530e570601..e5190b310c 100644 --- a/Meta/Lagom/Fuzzers/FuzzilliJs.cpp +++ b/Meta/Lagom/Fuzzers/FuzzilliJs.cpp @@ -207,13 +207,11 @@ int main(int, char**) auto js = StringView(static_cast<const unsigned char*>(data_buffer.data()), script_size); - auto lexer = JS::Lexer(js); - auto parser = JS::Parser(lexer); - auto program = parser.parse_program(); - if (parser.has_errors()) { + auto parse_result = JS::Script::parse(js, interpreter->realm()); + if (parse_result.is_error()) { result = 1; } else { - auto completion = interpreter->run(interpreter->global_object(), *program); + auto completion = interpreter->run(parse_result.value()); if (completion.is_error()) { result = 1; vm->clear_exception(); |