mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 14:28:49 +00:00
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>
This commit is contained in:
parent
232a8432b7
commit
631bbcd00a
Notes:
sideshowbarker
2024-07-17 20:29:14 +09:00
Author: https://github.com/Lubrsi
Commit: 631bbcd00a
Pull-request: https://github.com/SerenityOS/serenity/pull/11957
Reviewed-by: https://github.com/davidot
Reviewed-by: https://github.com/emanuele6
Reviewed-by: https://github.com/linusg
20 changed files with 293 additions and 129 deletions
|
@ -69,9 +69,15 @@ JS::Value ClassicScript::run(RethrowErrors rethrow_errors)
|
|||
(void)rethrow_errors;
|
||||
|
||||
auto timer = Core::ElapsedTimer::start_new();
|
||||
|
||||
// 6. Otherwise, set evaluationStatus to ScriptEvaluation(script's record).
|
||||
// FIXME: Interpreter::run doesn't currently return a JS::Completion.
|
||||
auto interpreter = JS::Interpreter::create_with_existing_realm(m_script_record->realm());
|
||||
|
||||
auto result = interpreter->run(interpreter->global_object(), m_script_record->parse_node());
|
||||
auto result = interpreter->run(*m_script_record);
|
||||
|
||||
// FIXME: If ScriptEvaluation does not complete because the user agent has aborted the running script, leave evaluationStatus as null.
|
||||
|
||||
dbgln("ClassicScript: Finished running script {}, Duration: {}ms", filename(), timer.elapsed());
|
||||
if (result.is_error()) {
|
||||
// FIXME: Propagate error according to the spec.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue