diff options
author | Linus Groh <mail@linusgroh.de> | 2021-09-12 12:33:54 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-12 15:18:25 +0200 |
commit | 7b92889e6bbafba2fcc74b9048fa5f05f07ce528 (patch) | |
tree | 8fee5960dc9bb4eff6d617b41a864ad015da5919 /Userland | |
parent | 106f29591688bc7f430f58360a2f6171e37b01ba (diff) | |
download | serenity-7b92889e6bbafba2fcc74b9048fa5f05f07ce528.zip |
LibJS: Change Interpreter::create_with_existing_{global_object => realm}
We need both a GlobalObject and Realm now, but can get the former from
the latter (once initialized).
This also fixes JS execution in LibWeb, as we failed to set the Realm of
the newly created Interpreter in this function.
Diffstat (limited to 'Userland')
5 files changed, 7 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Interpreter.cpp b/Userland/Libraries/LibJS/Interpreter.cpp index 06cdadabc3..bbf5282323 100644 --- a/Userland/Libraries/LibJS/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Interpreter.cpp @@ -18,11 +18,13 @@ namespace JS { -NonnullOwnPtr<Interpreter> Interpreter::create_with_existing_global_object(GlobalObject& global_object) +NonnullOwnPtr<Interpreter> Interpreter::create_with_existing_realm(Realm& realm) { + auto& global_object = realm.global_object(); DeferGC defer_gc(global_object.heap()); auto interpreter = adopt_own(*new Interpreter(global_object.vm())); interpreter->m_global_object = make_handle(&global_object); + interpreter->m_realm = make_handle(&realm); return interpreter; } diff --git a/Userland/Libraries/LibJS/Interpreter.h b/Userland/Libraries/LibJS/Interpreter.h index cb75ab14ce..aaea4fc382 100644 --- a/Userland/Libraries/LibJS/Interpreter.h +++ b/Userland/Libraries/LibJS/Interpreter.h @@ -48,7 +48,7 @@ public: return interpreter; } - static NonnullOwnPtr<Interpreter> create_with_existing_global_object(GlobalObject&); + static NonnullOwnPtr<Interpreter> create_with_existing_realm(Realm&); ~Interpreter(); diff --git a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp index 39fe9e2637..b916a2e13c 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -90,7 +90,7 @@ Value FunctionConstructor::construct(FunctionObject& new_target) Interpreter* interpreter = vm().interpreter_if_exists(); if (!interpreter) { - local_interpreter = Interpreter::create_with_existing_global_object(global_object()); + local_interpreter = Interpreter::create_with_existing_realm(*realm()); interpreter = local_interpreter.ptr(); } diff --git a/Userland/Libraries/LibJS/Runtime/OrdinaryFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/OrdinaryFunctionObject.cpp index ad6ca49c72..b558040532 100644 --- a/Userland/Libraries/LibJS/Runtime/OrdinaryFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/OrdinaryFunctionObject.cpp @@ -203,7 +203,7 @@ Value OrdinaryFunctionObject::execute_function_body() ast_interpreter = vm.interpreter_if_exists(); if (!ast_interpreter) { - local_interpreter = Interpreter::create_with_existing_global_object(global_object()); + local_interpreter = Interpreter::create_with_existing_realm(*realm()); ast_interpreter = local_interpreter.ptr(); } diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp index 8f30022367..dcfe0b870b 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp @@ -53,7 +53,7 @@ JS::Value ClassicScript::run(RethrowErrors rethrow_errors) { (void)rethrow_errors; - auto interpreter = JS::Interpreter::create_with_existing_global_object(m_script_record->realm().global_object()); + auto interpreter = JS::Interpreter::create_with_existing_realm(m_script_record->realm()); interpreter->run(interpreter->global_object(), m_script_record->parse_node()); auto& vm = interpreter->vm(); if (vm.exception()) |