Realm.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/Realm.h>
  7. namespace JS {
  8. // 9.3.3 SetRealmGlobalObject ( realmRec, globalObj, thisValue ), https://tc39.es/ecma262/#sec-setrealmglobalobject
  9. void Realm::set_global_object(GlobalObject& global_object, Object* this_value)
  10. {
  11. // NOTE: Step 1 is not supported, the global object must be allocated elsewhere.
  12. // 2. Assert: Type(globalObj) is Object.
  13. // Non-standard
  14. global_object.set_associated_realm({}, *this);
  15. // 3. If thisValue is undefined, set thisValue to globalObj.
  16. if (!this_value)
  17. this_value = &global_object;
  18. // 4. Set realmRec.[[GlobalObject]] to globalObj.
  19. m_global_object = &global_object;
  20. // 5. Let newGlobalEnv be NewGlobalEnvironment(globalObj, thisValue).
  21. // 6. Set realmRec.[[GlobalEnv]] to newGlobalEnv.
  22. m_global_environment = global_object.heap().allocate<GlobalEnvironment>(global_object, global_object, *this_value);
  23. // 7. Return realmRec.
  24. }
  25. void Realm::visit_edges(Visitor& visitor)
  26. {
  27. visitor.visit(m_global_object);
  28. visitor.visit(m_global_environment);
  29. }
  30. }