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

LibJS: Allocate a Realm next to GlobalObject in Interpreter::create()

Also pass a Realm reference to the Bytecode::Interpreter constructor,
just like we pass the GlobalObject.
This commit is contained in:
Linus Groh 2021-09-11 19:36:25 +01:00
parent d9c3bafcd9
commit 2b8d5696ab
8 changed files with 54 additions and 10 deletions

View file

@ -8,6 +8,26 @@
namespace JS {
// 9.3.3 SetRealmGlobalObject ( realmRec, globalObj, thisValue ), https://tc39.es/ecma262/#sec-setrealmglobalobject
void Realm::set_global_object(GlobalObject& global_object, Object* this_value)
{
// NOTE: Step 1 is not supported, the global object must be allocated elsewhere.
// 2. Assert: Type(globalObj) is Object.
// 3. If thisValue is undefined, set thisValue to globalObj.
if (!this_value)
this_value = &global_object;
// 4. Set realmRec.[[GlobalObject]] to globalObj.
m_global_object = &global_object;
// 5. Let newGlobalEnv be NewGlobalEnvironment(globalObj, thisValue).
// 6. Set realmRec.[[GlobalEnv]] to newGlobalEnv.
m_global_environment = global_object.heap().allocate<GlobalEnvironment>(global_object, global_object, *this_value);
// 7. Return realmRec.
}
void Realm::visit_edges(Visitor& visitor)
{
visitor.visit(m_global_object);

View file

@ -23,6 +23,8 @@ public:
return vm.heap().allocate_without_global_object<Realm>();
}
void set_global_object(GlobalObject&, Object* this_value = nullptr);
[[nodiscard]] GlobalObject& global_object() const { return *m_global_object; }
[[nodiscard]] GlobalEnvironment& global_environment() const { return *m_global_environment; }