1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:07:46 +00:00

LibJS: Pass Realm to GlobalObject::initialize_global_object()

Global object initialization is tightly coupled to realm creation, so
simply pass it to the function instead of relying on the non-standard
'associated realm' concept, which I'd like to remove later.

This works essentially the same way as regular Object::initialize() now.

Additionally this allows us to forward the realm to GlobalObject's
add_constructor() / initialize_constructor() helpers, so they set the
correct realm on the allocated constructor function object.
This commit is contained in:
Linus Groh 2022-08-22 18:56:16 +01:00
parent b465f46e00
commit 7c468b5a77
18 changed files with 76 additions and 79 deletions

View file

@ -44,11 +44,13 @@ public:
VM::InterpreterExecutionScope scope(*interpreter);
GlobalObject* global_object { nullptr };
Realm* realm { nullptr };
interpreter->m_global_execution_context = MUST(Realm::initialize_host_defined_realm(
vm,
[&](Realm& realm) -> GlobalObject* {
global_object = interpreter->heap().allocate_without_realm<GlobalObjectType>(realm, forward<Args>(args)...);
[&](Realm& realm_) -> GlobalObject* {
global_object = interpreter->heap().allocate_without_realm<GlobalObjectType>(realm_, forward<Args>(args)...);
realm = &realm_;
return global_object;
},
nullptr));
@ -58,7 +60,7 @@ public:
interpreter->m_global_execution_context->function_name = global_execution_context_name;
interpreter->m_global_object = make_handle(global_object);
interpreter->m_realm = make_handle(global_object->associated_realm());
interpreter->m_realm = make_handle(realm);
return interpreter;
}