Bladeren bron

LibJS+LibWeb: Replace GlobalObject with Realm in object constructors

No functional changes - we can still very easily get to the global
object via `Realm::global_object()`. This is in preparation of moving
the intrinsics to the realm and no longer having to pass a global
object when allocating any object.
In a few (now, and many more in subsequent commits) places we get a
realm using `GlobalObject::associated_realm()`, this is intended to be
temporary. For example, create() functions will later receive the same
treatment and are passed a realm instead of a global object.
Linus Groh 3 jaren geleden
bovenliggende
commit
ecd163bdf1
100 gewijzigde bestanden met toevoegingen van 212 en 199 verwijderingen
  1. 24 22
      Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp
  2. 2 2
      Userland/Applications/Spreadsheet/JSIntegration.cpp
  3. 1 1
      Userland/Applications/Spreadsheet/JSIntegration.h
  4. 1 1
      Userland/Applications/Spreadsheet/Workbook.cpp
  5. 5 4
      Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp
  6. 1 1
      Userland/Libraries/LibJS/Contrib/Test262/$262Object.h
  7. 2 2
      Userland/Libraries/LibJS/Contrib/Test262/AgentObject.cpp
  8. 1 1
      Userland/Libraries/LibJS/Contrib/Test262/AgentObject.h
  9. 2 1
      Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp
  10. 2 2
      Userland/Libraries/LibJS/Contrib/Test262/IsHTMLDDA.cpp
  11. 1 1
      Userland/Libraries/LibJS/Contrib/Test262/IsHTMLDDA.h
  12. 1 1
      Userland/Libraries/LibJS/Module.cpp
  13. 2 1
      Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
  14. 2 2
      Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp
  15. 1 1
      Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.h
  16. 2 2
      Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.cpp
  17. 1 1
      Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.h
  18. 2 2
      Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp
  19. 1 1
      Userland/Libraries/LibJS/Runtime/ArgumentsObject.h
  20. 2 2
      Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp
  21. 1 1
      Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.h
  22. 2 2
      Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp
  23. 1 1
      Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.h
  24. 2 2
      Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
  25. 1 1
      Userland/Libraries/LibJS/Runtime/ArrayConstructor.h
  26. 2 2
      Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp
  27. 1 1
      Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.h
  28. 2 2
      Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
  29. 1 1
      Userland/Libraries/LibJS/Runtime/ArrayPrototype.h
  30. 4 3
      Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp
  31. 1 1
      Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.h
  32. 2 2
      Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
  33. 1 1
      Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.h
  34. 2 2
      Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp
  35. 1 1
      Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.h
  36. 6 5
      Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp
  37. 1 1
      Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h
  38. 2 2
      Userland/Libraries/LibJS/Runtime/AsyncFunctionPrototype.cpp
  39. 1 1
      Userland/Libraries/LibJS/Runtime/AsyncFunctionPrototype.h
  40. 2 2
      Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp
  41. 1 1
      Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.h
  42. 2 2
      Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionPrototype.cpp
  43. 1 1
      Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionPrototype.h
  44. 2 2
      Userland/Libraries/LibJS/Runtime/AsyncGeneratorPrototype.cpp
  45. 1 1
      Userland/Libraries/LibJS/Runtime/AsyncGeneratorPrototype.h
  46. 2 2
      Userland/Libraries/LibJS/Runtime/AsyncIteratorPrototype.cpp
  47. 1 1
      Userland/Libraries/LibJS/Runtime/AsyncIteratorPrototype.h
  48. 2 2
      Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp
  49. 1 1
      Userland/Libraries/LibJS/Runtime/AtomicsObject.h
  50. 2 2
      Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp
  51. 1 1
      Userland/Libraries/LibJS/Runtime/BigIntConstructor.h
  52. 2 2
      Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp
  53. 1 1
      Userland/Libraries/LibJS/Runtime/BigIntPrototype.h
  54. 2 2
      Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp
  55. 1 1
      Userland/Libraries/LibJS/Runtime/BooleanConstructor.h
  56. 2 2
      Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp
  57. 1 1
      Userland/Libraries/LibJS/Runtime/BooleanPrototype.h
  58. 5 3
      Userland/Libraries/LibJS/Runtime/BoundFunction.cpp
  59. 1 1
      Userland/Libraries/LibJS/Runtime/BoundFunction.h
  60. 2 2
      Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp
  61. 1 1
      Userland/Libraries/LibJS/Runtime/ConsoleObject.h
  62. 2 2
      Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp
  63. 1 1
      Userland/Libraries/LibJS/Runtime/DataViewConstructor.h
  64. 2 2
      Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp
  65. 1 1
      Userland/Libraries/LibJS/Runtime/DataViewPrototype.h
  66. 2 2
      Userland/Libraries/LibJS/Runtime/DateConstructor.cpp
  67. 1 1
      Userland/Libraries/LibJS/Runtime/DateConstructor.h
  68. 2 2
      Userland/Libraries/LibJS/Runtime/DatePrototype.cpp
  69. 1 1
      Userland/Libraries/LibJS/Runtime/DatePrototype.h
  70. 4 4
      Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp
  71. 2 2
      Userland/Libraries/LibJS/Runtime/ErrorConstructor.h
  72. 4 4
      Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp
  73. 2 2
      Userland/Libraries/LibJS/Runtime/ErrorPrototype.h
  74. 2 2
      Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.cpp
  75. 1 1
      Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.h
  76. 2 2
      Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp
  77. 1 1
      Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.h
  78. 2 2
      Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp
  79. 1 1
      Userland/Libraries/LibJS/Runtime/FunctionConstructor.h
  80. 2 2
      Userland/Libraries/LibJS/Runtime/FunctionObject.cpp
  81. 1 1
      Userland/Libraries/LibJS/Runtime/FunctionObject.h
  82. 2 2
      Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp
  83. 1 1
      Userland/Libraries/LibJS/Runtime/FunctionPrototype.h
  84. 2 2
      Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp
  85. 1 1
      Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.h
  86. 2 2
      Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp
  87. 1 1
      Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.h
  88. 4 2
      Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp
  89. 1 1
      Userland/Libraries/LibJS/Runtime/GeneratorObject.h
  90. 2 2
      Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp
  91. 1 1
      Userland/Libraries/LibJS/Runtime/GeneratorPrototype.h
  92. 18 18
      Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
  93. 2 1
      Userland/Libraries/LibJS/Runtime/GlobalObject.h
  94. 4 3
      Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp
  95. 1 1
      Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h
  96. 2 2
      Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp
  97. 1 1
      Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.h
  98. 2 2
      Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp
  99. 1 1
      Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.h
  100. 2 2
      Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp

+ 24 - 22
Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp

@@ -1837,7 +1837,7 @@ class @wrapper_class@ : public @wrapper_base_class@ {
 public:
 public:
     static @wrapper_class@* create(JS::GlobalObject&, @fully_qualified_name@&);
     static @wrapper_class@* create(JS::GlobalObject&, @fully_qualified_name@&);
 
 
-    @wrapper_class@(JS::GlobalObject&, @fully_qualified_name@&);
+    @wrapper_class@(JS::Realm&, @fully_qualified_name@&);
     virtual void initialize(JS::GlobalObject&) override;
     virtual void initialize(JS::GlobalObject&) override;
     virtual ~@wrapper_class@() override;
     virtual ~@wrapper_class@() override;
 )~~~");
 )~~~");
@@ -2004,25 +2004,26 @@ namespace Web::Bindings {
 
 
 @wrapper_class@* @wrapper_class@::create(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
 @wrapper_class@* @wrapper_class@::create(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
 {
 {
-    return global_object.heap().allocate<@wrapper_class@>(global_object, global_object, impl);
+    auto& realm = *global_object.associated_realm();
+    return global_object.heap().allocate<@wrapper_class@>(global_object, realm, impl);
 }
 }
 
 
 )~~~");
 )~~~");
 
 
     if (interface.wrapper_base_class == "Wrapper") {
     if (interface.wrapper_base_class == "Wrapper") {
         generator.append(R"~~~(
         generator.append(R"~~~(
-@wrapper_class@::@wrapper_class@(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
-    : Wrapper(static_cast<WindowObject&>(global_object).ensure_web_prototype<@prototype_class@>("@name@"))
+@wrapper_class@::@wrapper_class@(JS::Realm& realm, @fully_qualified_name@& impl)
+    : Wrapper(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@"))
     , m_impl(impl)
     , m_impl(impl)
 {
 {
 }
 }
 )~~~");
 )~~~");
     } else {
     } else {
         generator.append(R"~~~(
         generator.append(R"~~~(
-@wrapper_class@::@wrapper_class@(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
-    : @wrapper_base_class@(global_object, impl)
+@wrapper_class@::@wrapper_class@(JS::Realm& realm, @fully_qualified_name@& impl)
+    : @wrapper_base_class@(realm, impl)
 {
 {
-    set_prototype(&static_cast<WindowObject&>(global_object).ensure_web_prototype<@prototype_class@>("@name@"));
+    set_prototype(&static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@"));
 }
 }
 )~~~");
 )~~~");
     }
     }
@@ -2798,7 +2799,7 @@ namespace Web::Bindings {
 class @constructor_class@ : public JS::NativeFunction {
 class @constructor_class@ : public JS::NativeFunction {
     JS_OBJECT(@constructor_class@, JS::NativeFunction);
     JS_OBJECT(@constructor_class@, JS::NativeFunction);
 public:
 public:
-    explicit @constructor_class@(JS::GlobalObject&);
+    explicit @constructor_class@(JS::Realm&);
     virtual void initialize(JS::GlobalObject&) override;
     virtual void initialize(JS::GlobalObject&) override;
     virtual ~@constructor_class@() override;
     virtual ~@constructor_class@() override;
 
 
@@ -2927,8 +2928,8 @@ using namespace Web::WebGL;
 
 
 namespace Web::Bindings {
 namespace Web::Bindings {
 
 
-@constructor_class@::@constructor_class@(JS::GlobalObject& global_object)
-    : NativeFunction(*global_object.function_prototype())
+@constructor_class@::@constructor_class@(JS::Realm& realm)
+    : NativeFunction(*realm.global_object().function_prototype())
 {
 {
 }
 }
 
 
@@ -3065,7 +3066,7 @@ namespace Web::Bindings {
 class @prototype_class@ : public JS::Object {
 class @prototype_class@ : public JS::Object {
     JS_OBJECT(@prototype_class@, JS::Object);
     JS_OBJECT(@prototype_class@, JS::Object);
 public:
 public:
-    explicit @prototype_class@(JS::GlobalObject&);
+    explicit @prototype_class@(JS::Realm&);
     virtual void initialize(JS::GlobalObject&) override;
     virtual void initialize(JS::GlobalObject&) override;
     virtual ~@prototype_class@() override;
     virtual ~@prototype_class@() override;
 private:
 private:
@@ -3210,20 +3211,20 @@ using namespace Web::WebGL;
 
 
 namespace Web::Bindings {
 namespace Web::Bindings {
 
 
-@prototype_class@::@prototype_class@([[maybe_unused]] JS::GlobalObject& global_object))~~~");
+@prototype_class@::@prototype_class@([[maybe_unused]] JS::Realm& realm))~~~");
     if (interface.name == "DOMException") {
     if (interface.name == "DOMException") {
         // https://webidl.spec.whatwg.org/#es-DOMException-specialness
         // https://webidl.spec.whatwg.org/#es-DOMException-specialness
         // Object.getPrototypeOf(DOMException.prototype) === Error.prototype
         // Object.getPrototypeOf(DOMException.prototype) === Error.prototype
         generator.append(R"~~~(
         generator.append(R"~~~(
-    : Object(*global_object.error_prototype())
+    : Object(*realm.global_object().error_prototype())
 )~~~");
 )~~~");
     } else if (!interface.parent_name.is_empty()) {
     } else if (!interface.parent_name.is_empty()) {
         generator.append(R"~~~(
         generator.append(R"~~~(
-    : Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<@prototype_base_class@>("@parent_name@"))
+    : Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_base_class@>("@parent_name@"))
 )~~~");
 )~~~");
     } else {
     } else {
         generator.append(R"~~~(
         generator.append(R"~~~(
-    : Object(*global_object.object_prototype())
+    : Object(*realm.global_object().object_prototype())
 )~~~");
 )~~~");
     }
     }
 
 
@@ -3587,7 +3588,7 @@ class @wrapper_class@ : public Wrapper {
 public:
 public:
     static @wrapper_class@* create(JS::GlobalObject&, @fully_qualified_name@&);
     static @wrapper_class@* create(JS::GlobalObject&, @fully_qualified_name@&);
 
 
-    @wrapper_class@(JS::GlobalObject&, @fully_qualified_name@&);
+    @wrapper_class@(JS::Realm&, @fully_qualified_name@&);
     virtual void initialize(JS::GlobalObject&) override;
     virtual void initialize(JS::GlobalObject&) override;
     virtual ~@wrapper_class@() override;
     virtual ~@wrapper_class@() override;
 
 
@@ -3659,11 +3660,12 @@ namespace Web::Bindings {
 
 
 @wrapper_class@* @wrapper_class@::create(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
 @wrapper_class@* @wrapper_class@::create(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
 {
 {
-    return global_object.heap().allocate<@wrapper_class@>(global_object, global_object, impl);
+    auto& realm = *global_object.associated_realm();
+    return global_object.heap().allocate<@wrapper_class@>(global_object, realm, impl);
 }
 }
 
 
-@wrapper_class@::@wrapper_class@(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
-    : Wrapper(static_cast<WindowObject&>(global_object).ensure_web_prototype<@prototype_class@>("@name@"))
+@wrapper_class@::@wrapper_class@(JS::Realm& realm, @fully_qualified_name@& impl)
+    : Wrapper(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<@prototype_class@>("@name@"))
     , m_impl(impl)
     , m_impl(impl)
 {
 {
 }
 }
@@ -3712,7 +3714,7 @@ namespace Web::Bindings {
 class @prototype_class@ : public JS::Object {
 class @prototype_class@ : public JS::Object {
     JS_OBJECT(@prototype_class@, JS::Object);
     JS_OBJECT(@prototype_class@, JS::Object);
 public:
 public:
-    explicit @prototype_class@(JS::GlobalObject&);
+    explicit @prototype_class@(JS::Realm&);
     virtual void initialize(JS::GlobalObject&) override;
     virtual void initialize(JS::GlobalObject&) override;
     virtual ~@prototype_class@() override;
     virtual ~@prototype_class@() override;
 
 
@@ -3776,8 +3778,8 @@ using namespace Web::WebGL;
 
 
 namespace Web::Bindings {
 namespace Web::Bindings {
 
 
-@prototype_class@::@prototype_class@(JS::GlobalObject& global_object)
-    : Object(*global_object.iterator_prototype())
+@prototype_class@::@prototype_class@(JS::Realm& realm)
+    : Object(*realm.global_object().iterator_prototype())
 {
 {
 }
 }
 
 

+ 2 - 2
Userland/Applications/Spreadsheet/JSIntegration.cpp

@@ -365,8 +365,8 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_column_bound)
     return JS::Value(bounds.row);
     return JS::Value(bounds.row);
 }
 }
 
 
-WorkbookObject::WorkbookObject(Workbook& workbook, JS::GlobalObject& global_object)
-    : JS::Object(*JS::Object::create(global_object, global_object.object_prototype()))
+WorkbookObject::WorkbookObject(JS::Realm& realm, Workbook& workbook)
+    : JS::Object(*realm.global_object().object_prototype())
     , m_workbook(workbook)
     , m_workbook(workbook)
 {
 {
 }
 }

+ 1 - 1
Userland/Applications/Spreadsheet/JSIntegration.h

@@ -50,7 +50,7 @@ class WorkbookObject final : public JS::Object {
     JS_OBJECT(WorkbookObject, JS::Object);
     JS_OBJECT(WorkbookObject, JS::Object);
 
 
 public:
 public:
-    WorkbookObject(Workbook&, JS::GlobalObject&);
+    WorkbookObject(JS::Realm&, Workbook&);
 
 
     virtual ~WorkbookObject() override = default;
     virtual ~WorkbookObject() override = default;
 
 

+ 1 - 1
Userland/Applications/Spreadsheet/Workbook.cpp

@@ -29,7 +29,7 @@ Workbook::Workbook(NonnullRefPtrVector<Sheet>&& sheets, GUI::Window& parent_wind
     , m_main_execution_context(m_vm->heap())
     , m_main_execution_context(m_vm->heap())
     , m_parent_window(parent_window)
     , m_parent_window(parent_window)
 {
 {
-    m_workbook_object = m_vm->heap().allocate<WorkbookObject>(m_interpreter->global_object(), *this, m_interpreter->global_object());
+    m_workbook_object = m_vm->heap().allocate<WorkbookObject>(m_interpreter->global_object(), m_interpreter->realm(), *this);
     m_interpreter->global_object().define_direct_property("workbook", workbook_object(), JS::default_attributes);
     m_interpreter->global_object().define_direct_property("workbook", workbook_object(), JS::default_attributes);
 
 
     m_main_execution_context.current_node = nullptr;
     m_main_execution_context.current_node = nullptr;

+ 5 - 4
Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp

@@ -18,8 +18,8 @@
 
 
 namespace JS::Test262 {
 namespace JS::Test262 {
 
 
-$262Object::$262Object(JS::GlobalObject& global_object)
-    : Object(Object::ConstructWithoutPrototypeTag::Tag, global_object)
+$262Object::$262Object(Realm& realm)
+    : Object(Object::ConstructWithoutPrototypeTag::Tag, realm)
 {
 {
 }
 }
 
 
@@ -27,8 +27,9 @@ void $262Object::initialize(JS::GlobalObject& global_object)
 {
 {
     Base::initialize(global_object);
     Base::initialize(global_object);
 
 
-    m_agent = vm().heap().allocate<AgentObject>(global_object, global_object);
-    m_is_htmldda = vm().heap().allocate<IsHTMLDDA>(global_object, global_object);
+    auto& realm = *global_object.associated_realm();
+    m_agent = vm().heap().allocate<AgentObject>(global_object, realm);
+    m_is_htmldda = vm().heap().allocate<IsHTMLDDA>(global_object, realm);
 
 
     u8 attr = Attribute::Writable | Attribute::Configurable;
     u8 attr = Attribute::Writable | Attribute::Configurable;
     define_native_function("clearKeptObjects", clear_kept_objects, 0, attr);
     define_native_function("clearKeptObjects", clear_kept_objects, 0, attr);

+ 1 - 1
Userland/Libraries/LibJS/Contrib/Test262/$262Object.h

@@ -17,7 +17,7 @@ class $262Object final : public Object {
     JS_OBJECT($262Object, Object);
     JS_OBJECT($262Object, Object);
 
 
 public:
 public:
-    $262Object(JS::GlobalObject&);
+    explicit $262Object(Realm&);
     virtual void initialize(JS::GlobalObject&) override;
     virtual void initialize(JS::GlobalObject&) override;
     virtual ~$262Object() override = default;
     virtual ~$262Object() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Contrib/Test262/AgentObject.cpp

@@ -12,8 +12,8 @@
 
 
 namespace JS::Test262 {
 namespace JS::Test262 {
 
 
-AgentObject::AgentObject(JS::GlobalObject& global_object)
-    : Object(Object::ConstructWithoutPrototypeTag::Tag, global_object)
+AgentObject::AgentObject(Realm& realm)
+    : Object(Object::ConstructWithoutPrototypeTag::Tag, realm)
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Contrib/Test262/AgentObject.h

@@ -15,7 +15,7 @@ class AgentObject final : public Object {
     JS_OBJECT(AgentObject, Object);
     JS_OBJECT(AgentObject, Object);
 
 
 public:
 public:
-    AgentObject(JS::GlobalObject&);
+    explicit AgentObject(Realm&);
     virtual void initialize(JS::GlobalObject&) override;
     virtual void initialize(JS::GlobalObject&) override;
     virtual ~AgentObject() override = default;
     virtual ~AgentObject() override = default;
 
 

+ 2 - 1
Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp

@@ -18,7 +18,8 @@ void GlobalObject::initialize_global_object()
 {
 {
     Base::initialize_global_object();
     Base::initialize_global_object();
 
 
-    m_$262 = vm().heap().allocate<$262Object>(*this, *this);
+    auto& realm = *associated_realm();
+    m_$262 = vm().heap().allocate<$262Object>(*this, realm);
 
 
     // https://github.com/tc39/test262/blob/master/INTERPRETING.md#host-defined-functions
     // https://github.com/tc39/test262/blob/master/INTERPRETING.md#host-defined-functions
     u8 attr = Attribute::Writable | Attribute::Configurable;
     u8 attr = Attribute::Writable | Attribute::Configurable;

+ 2 - 2
Userland/Libraries/LibJS/Contrib/Test262/IsHTMLDDA.cpp

@@ -9,9 +9,9 @@
 
 
 namespace JS::Test262 {
 namespace JS::Test262 {
 
 
-IsHTMLDDA::IsHTMLDDA(JS::GlobalObject& global_object)
+IsHTMLDDA::IsHTMLDDA(Realm& realm)
     // NativeFunction without prototype is currently not possible (only due to the lack of a ctor that supports it)
     // NativeFunction without prototype is currently not possible (only due to the lack of a ctor that supports it)
-    : NativeFunction("IsHTMLDDA", *global_object.function_prototype())
+    : NativeFunction("IsHTMLDDA", *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Contrib/Test262/IsHTMLDDA.h

@@ -14,7 +14,7 @@ class IsHTMLDDA final : public NativeFunction {
     JS_OBJECT(IsHTMLDDA, NativeFunction);
     JS_OBJECT(IsHTMLDDA, NativeFunction);
 
 
 public:
 public:
-    explicit IsHTMLDDA(JS::GlobalObject&);
+    explicit IsHTMLDDA(Realm&);
     virtual ~IsHTMLDDA() override = default;
     virtual ~IsHTMLDDA() override = default;
 
 
     virtual ThrowCompletionOr<Value> call() override;
     virtual ThrowCompletionOr<Value> call() override;

+ 1 - 1
Userland/Libraries/LibJS/Module.cpp

@@ -97,7 +97,7 @@ Object* Module::module_namespace_create(VM& vm, Vector<FlyString> unambiguous_na
     // 6. Let sortedExports be a List whose elements are the elements of exports ordered as if an Array of the same values had been sorted using %Array.prototype.sort% using undefined as comparefn.
     // 6. Let sortedExports be a List whose elements are the elements of exports ordered as if an Array of the same values had been sorted using %Array.prototype.sort% using undefined as comparefn.
     // 7. Set M.[[Exports]] to sortedExports.
     // 7. Set M.[[Exports]] to sortedExports.
     // 8. Create own properties of M corresponding to the definitions in 28.3.
     // 8. Create own properties of M corresponding to the definitions in 28.3.
-    Object* module_namespace = vm.heap().allocate<ModuleNamespaceObject>(realm().global_object(), realm().global_object(), this, move(unambiguous_names));
+    Object* module_namespace = vm.heap().allocate<ModuleNamespaceObject>(realm().global_object(), realm(), this, move(unambiguous_names));
 
 
     // 9. Set module.[[Namespace]] to M.
     // 9. Set module.[[Namespace]] to M.
     m_namespace = make_handle(module_namespace);
     m_namespace = make_handle(module_namespace);

+ 2 - 1
Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp

@@ -1076,6 +1076,7 @@ Object* create_unmapped_arguments_object(GlobalObject& global_object, Span<Value
 Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObject& function, Vector<FunctionNode::Parameter> const& formals, Span<Value> arguments, Environment& environment)
 Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObject& function, Vector<FunctionNode::Parameter> const& formals, Span<Value> arguments, Environment& environment)
 {
 {
     auto& vm = global_object.vm();
     auto& vm = global_object.vm();
+    auto& realm = *global_object.associated_realm();
 
 
     // 1. Assert: formals does not contain a rest parameter, any binding patterns, or any initializers. It may contain duplicate identifiers.
     // 1. Assert: formals does not contain a rest parameter, any binding patterns, or any initializers. It may contain duplicate identifiers.
 
 
@@ -1090,7 +1091,7 @@ Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObje
     // 7. Set obj.[[Set]] as specified in 10.4.4.4.
     // 7. Set obj.[[Set]] as specified in 10.4.4.4.
     // 8. Set obj.[[Delete]] as specified in 10.4.4.5.
     // 8. Set obj.[[Delete]] as specified in 10.4.4.5.
     // 9. Set obj.[[Prototype]] to %Object.prototype%.
     // 9. Set obj.[[Prototype]] to %Object.prototype%.
-    auto* object = vm.heap().allocate<ArgumentsObject>(global_object, global_object, environment);
+    auto* object = vm.heap().allocate<ArgumentsObject>(global_object, realm, environment);
 
 
     // 14. Let index be 0.
     // 14. Let index be 0.
     // 15. Repeat, while index < len,
     // 15. Repeat, while index < len,

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp

@@ -14,8 +14,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-AggregateErrorConstructor::AggregateErrorConstructor(GlobalObject& global_object)
-    : NativeFunction(*static_cast<Object*>(global_object.error_constructor()))
+AggregateErrorConstructor::AggregateErrorConstructor(Realm& realm)
+    : NativeFunction(static_cast<Object&>(*realm.global_object().error_constructor()))
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.h

@@ -14,7 +14,7 @@ class AggregateErrorConstructor final : public NativeFunction {
     JS_OBJECT(AggregateErrorConstructor, NativeFunction);
     JS_OBJECT(AggregateErrorConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit AggregateErrorConstructor(GlobalObject&);
+    explicit AggregateErrorConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AggregateErrorConstructor() override = default;
     virtual ~AggregateErrorConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.cpp

@@ -10,8 +10,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-AggregateErrorPrototype::AggregateErrorPrototype(GlobalObject& global_object)
-    : Object(*global_object.error_prototype())
+AggregateErrorPrototype::AggregateErrorPrototype(Realm& realm)
+    : Object(*realm.global_object().error_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.h

@@ -14,7 +14,7 @@ class AggregateErrorPrototype final : public Object {
     JS_OBJECT(AggregateErrorPrototype, Object);
     JS_OBJECT(AggregateErrorPrototype, Object);
 
 
 public:
 public:
-    explicit AggregateErrorPrototype(GlobalObject&);
+    explicit AggregateErrorPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AggregateErrorPrototype() override = default;
     virtual ~AggregateErrorPrototype() override = default;
 };
 };

+ 2 - 2
Userland/Libraries/LibJS/Runtime/ArgumentsObject.cpp

@@ -10,8 +10,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-ArgumentsObject::ArgumentsObject(GlobalObject& global_object, Environment& environment)
-    : Object(*global_object.object_prototype())
+ArgumentsObject::ArgumentsObject(Realm& realm, Environment& environment)
+    : Object(*realm.global_object().object_prototype())
     , m_environment(environment)
     , m_environment(environment)
 {
 {
 }
 }

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ArgumentsObject.h

@@ -16,7 +16,7 @@ class ArgumentsObject final : public Object {
     JS_OBJECT(ArgumentsObject, Object);
     JS_OBJECT(ArgumentsObject, Object);
 
 
 public:
 public:
-    ArgumentsObject(GlobalObject&, Environment&);
+    ArgumentsObject(Realm&, Environment&);
 
 
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~ArgumentsObject() override = default;
     virtual ~ArgumentsObject() override = default;

+ 2 - 2
Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp

@@ -13,8 +13,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-ArrayBufferConstructor::ArrayBufferConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.ArrayBuffer.as_string(), *global_object.function_prototype())
+ArrayBufferConstructor::ArrayBufferConstructor(Realm& realm)
+    : NativeFunction(vm().names.ArrayBuffer.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.h

@@ -14,7 +14,7 @@ class ArrayBufferConstructor final : public NativeFunction {
     JS_OBJECT(ArrayBufferConstructor, NativeFunction);
     JS_OBJECT(ArrayBufferConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit ArrayBufferConstructor(GlobalObject&);
+    explicit ArrayBufferConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~ArrayBufferConstructor() override = default;
     virtual ~ArrayBufferConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp

@@ -14,8 +14,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-ArrayBufferPrototype::ArrayBufferPrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.object_prototype())
+ArrayBufferPrototype::ArrayBufferPrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.h

@@ -15,7 +15,7 @@ class ArrayBufferPrototype final : public PrototypeObject<ArrayBufferPrototype,
     JS_PROTOTYPE_OBJECT(ArrayBufferPrototype, ArrayBuffer, ArrayBuffer);
     JS_PROTOTYPE_OBJECT(ArrayBufferPrototype, ArrayBuffer, ArrayBuffer);
 
 
 public:
 public:
-    explicit ArrayBufferPrototype(GlobalObject&);
+    explicit ArrayBufferPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~ArrayBufferPrototype() override = default;
     virtual ~ArrayBufferPrototype() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp

@@ -16,8 +16,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-ArrayConstructor::ArrayConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.Array.as_string(), *global_object.function_prototype())
+ArrayConstructor::ArrayConstructor(Realm& realm)
+    : NativeFunction(vm().names.Array.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ArrayConstructor.h

@@ -14,7 +14,7 @@ class ArrayConstructor final : public NativeFunction {
     JS_OBJECT(ArrayConstructor, NativeFunction);
     JS_OBJECT(ArrayConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit ArrayConstructor(GlobalObject&);
+    explicit ArrayConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~ArrayConstructor() override = default;
     virtual ~ArrayConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp

@@ -14,8 +14,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-ArrayIteratorPrototype::ArrayIteratorPrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.iterator_prototype())
+ArrayIteratorPrototype::ArrayIteratorPrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().iterator_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.h

@@ -15,7 +15,7 @@ class ArrayIteratorPrototype final : public PrototypeObject<ArrayIteratorPrototy
     JS_PROTOTYPE_OBJECT(ArrayIteratorPrototype, ArrayIterator, ArrayIterator);
     JS_PROTOTYPE_OBJECT(ArrayIteratorPrototype, ArrayIterator, ArrayIterator);
 
 
 public:
 public:
-    ArrayIteratorPrototype(GlobalObject&);
+    ArrayIteratorPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~ArrayIteratorPrototype() override = default;
     virtual ~ArrayIteratorPrototype() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp

@@ -28,8 +28,8 @@ namespace JS {
 
 
 static HashTable<Object*> s_array_join_seen_objects;
 static HashTable<Object*> s_array_join_seen_objects;
 
 
-ArrayPrototype::ArrayPrototype(GlobalObject& global_object)
-    : Array(*global_object.object_prototype())
+ArrayPrototype::ArrayPrototype(Realm& realm)
+    : Array(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ArrayPrototype.h

@@ -15,7 +15,7 @@ class ArrayPrototype final : public Array {
     JS_OBJECT(ArrayPrototype, Array);
     JS_OBJECT(ArrayPrototype, Array);
 
 
 public:
 public:
-    ArrayPrototype(GlobalObject&);
+    ArrayPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~ArrayPrototype() override = default;
     virtual ~ArrayPrototype() override = default;
 
 

+ 4 - 3
Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.cpp

@@ -13,11 +13,12 @@ namespace JS {
 
 
 AsyncFromSyncIterator* AsyncFromSyncIterator::create(GlobalObject& global_object, Iterator sync_iterator_record)
 AsyncFromSyncIterator* AsyncFromSyncIterator::create(GlobalObject& global_object, Iterator sync_iterator_record)
 {
 {
-    return global_object.heap().allocate<AsyncFromSyncIterator>(global_object, global_object, sync_iterator_record);
+    auto& realm = *global_object.associated_realm();
+    return global_object.heap().allocate<AsyncFromSyncIterator>(global_object, realm, sync_iterator_record);
 }
 }
 
 
-AsyncFromSyncIterator::AsyncFromSyncIterator(GlobalObject& global_object, Iterator sync_iterator_record)
-    : Object(*global_object.async_from_sync_iterator_prototype())
+AsyncFromSyncIterator::AsyncFromSyncIterator(Realm& realm, Iterator sync_iterator_record)
+    : Object(*realm.global_object().async_from_sync_iterator_prototype())
     , m_sync_iterator_record(sync_iterator_record)
     , m_sync_iterator_record(sync_iterator_record)
 {
 {
 }
 }

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AsyncFromSyncIterator.h

@@ -19,7 +19,7 @@ class AsyncFromSyncIterator final : public Object {
 public:
 public:
     static AsyncFromSyncIterator* create(GlobalObject&, Iterator sync_iterator_record);
     static AsyncFromSyncIterator* create(GlobalObject&, Iterator sync_iterator_record);
 
 
-    explicit AsyncFromSyncIterator(GlobalObject&, Iterator sync_iterator_record);
+    explicit AsyncFromSyncIterator(Realm&, Iterator sync_iterator_record);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AsyncFromSyncIterator() override = default;
     virtual ~AsyncFromSyncIterator() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp

@@ -14,8 +14,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-AsyncFromSyncIteratorPrototype::AsyncFromSyncIteratorPrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.async_iterator_prototype())
+AsyncFromSyncIteratorPrototype::AsyncFromSyncIteratorPrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().async_iterator_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.h

@@ -19,7 +19,7 @@ class AsyncFromSyncIteratorPrototype final : public PrototypeObject<AsyncFromSyn
     JS_PROTOTYPE_OBJECT(AsyncFromSyncIteratorPrototype, AsyncFromSyncIterator, AsyncFromSyncIterator);
     JS_PROTOTYPE_OBJECT(AsyncFromSyncIteratorPrototype, AsyncFromSyncIterator, AsyncFromSyncIterator);
 
 
 public:
 public:
-    explicit AsyncFromSyncIteratorPrototype(GlobalObject&);
+    explicit AsyncFromSyncIteratorPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AsyncFromSyncIteratorPrototype() override = default;
     virtual ~AsyncFromSyncIteratorPrototype() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp

@@ -12,8 +12,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-AsyncFunctionConstructor::AsyncFunctionConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.AsyncFunction.as_string(), *global_object.function_constructor())
+AsyncFunctionConstructor::AsyncFunctionConstructor(Realm& realm)
+    : NativeFunction(vm().names.AsyncFunction.as_string(), *realm.global_object().function_constructor())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.h

@@ -15,7 +15,7 @@ class AsyncFunctionConstructor final : public NativeFunction {
     JS_OBJECT(AsyncFunctionConstructor, NativeFunction);
     JS_OBJECT(AsyncFunctionConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit AsyncFunctionConstructor(GlobalObject&);
+    explicit AsyncFunctionConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AsyncFunctionConstructor() override = default;
     virtual ~AsyncFunctionConstructor() override = default;
 
 

+ 6 - 5
Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.cpp

@@ -14,17 +14,18 @@ namespace JS {
 
 
 ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(GlobalObject& global_object, GeneratorObject* generator_object)
 ThrowCompletionOr<Value> AsyncFunctionDriverWrapper::create(GlobalObject& global_object, GeneratorObject* generator_object)
 {
 {
-    auto wrapper = global_object.heap().allocate<AsyncFunctionDriverWrapper>(global_object, global_object, generator_object);
+    auto& realm = *global_object.associated_realm();
+    auto wrapper = global_object.heap().allocate<AsyncFunctionDriverWrapper>(global_object, realm, generator_object);
     return wrapper->react_to_async_task_completion(global_object.vm(), global_object, js_undefined(), true);
     return wrapper->react_to_async_task_completion(global_object.vm(), global_object, js_undefined(), true);
 }
 }
 
 
-AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(GlobalObject& global_object, GeneratorObject* generator_object)
-    : Promise(*global_object.promise_prototype())
+AsyncFunctionDriverWrapper::AsyncFunctionDriverWrapper(Realm& realm, GeneratorObject* generator_object)
+    : Promise(*realm.global_object().promise_prototype())
     , m_generator_object(generator_object)
     , m_generator_object(generator_object)
-    , m_on_fulfillment(NativeFunction::create(global_object, "async.on_fulfillment"sv, [this](VM& vm, GlobalObject& global_object) {
+    , m_on_fulfillment(NativeFunction::create(realm.global_object(), "async.on_fulfillment"sv, [this](VM& vm, GlobalObject& global_object) {
         return react_to_async_task_completion(vm, global_object, vm.argument(0), true);
         return react_to_async_task_completion(vm, global_object, vm.argument(0), true);
     }))
     }))
-    , m_on_rejection(NativeFunction::create(global_object, "async.on_rejection"sv, [this](VM& vm, GlobalObject& global_object) {
+    , m_on_rejection(NativeFunction::create(realm.global_object(), "async.on_rejection"sv, [this](VM& vm, GlobalObject& global_object) {
         return react_to_async_task_completion(vm, global_object, vm.argument(0), false);
         return react_to_async_task_completion(vm, global_object, vm.argument(0), false);
     }))
     }))
 {
 {

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AsyncFunctionDriverWrapper.h

@@ -19,7 +19,7 @@ class AsyncFunctionDriverWrapper final : public Promise {
 
 
 public:
 public:
     static ThrowCompletionOr<Value> create(GlobalObject&, GeneratorObject*);
     static ThrowCompletionOr<Value> create(GlobalObject&, GeneratorObject*);
-    explicit AsyncFunctionDriverWrapper(GlobalObject&, GeneratorObject*);
+    explicit AsyncFunctionDriverWrapper(Realm&, GeneratorObject*);
 
 
     virtual ~AsyncFunctionDriverWrapper() override = default;
     virtual ~AsyncFunctionDriverWrapper() override = default;
     void visit_edges(Cell::Visitor&) override;
     void visit_edges(Cell::Visitor&) override;

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AsyncFunctionPrototype.cpp

@@ -9,8 +9,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-AsyncFunctionPrototype::AsyncFunctionPrototype(GlobalObject& global_object)
-    : Object(*global_object.function_prototype())
+AsyncFunctionPrototype::AsyncFunctionPrototype(Realm& realm)
+    : Object(*realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AsyncFunctionPrototype.h

@@ -14,7 +14,7 @@ class AsyncFunctionPrototype final : public Object {
     JS_OBJECT(AsyncFunctionPrototype, Object);
     JS_OBJECT(AsyncFunctionPrototype, Object);
 
 
 public:
 public:
-    explicit AsyncFunctionPrototype(GlobalObject&);
+    explicit AsyncFunctionPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AsyncFunctionPrototype() override = default;
     virtual ~AsyncFunctionPrototype() override = default;
 };
 };

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp

@@ -12,8 +12,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-AsyncGeneratorFunctionConstructor::AsyncGeneratorFunctionConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.AsyncGeneratorFunction.as_string(), *global_object.function_prototype())
+AsyncGeneratorFunctionConstructor::AsyncGeneratorFunctionConstructor(Realm& realm)
+    : NativeFunction(vm().names.AsyncGeneratorFunction.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.h

@@ -14,7 +14,7 @@ class AsyncGeneratorFunctionConstructor final : public NativeFunction {
     JS_OBJECT(AsyncGeneratorFunctionConstructor, NativeFunction);
     JS_OBJECT(AsyncGeneratorFunctionConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit AsyncGeneratorFunctionConstructor(GlobalObject&);
+    explicit AsyncGeneratorFunctionConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AsyncGeneratorFunctionConstructor() override = default;
     virtual ~AsyncGeneratorFunctionConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionPrototype.cpp

@@ -11,8 +11,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-AsyncGeneratorFunctionPrototype::AsyncGeneratorFunctionPrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.function_prototype())
+AsyncGeneratorFunctionPrototype::AsyncGeneratorFunctionPrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionPrototype.h

@@ -14,7 +14,7 @@ class AsyncGeneratorFunctionPrototype final : public PrototypeObject<AsyncGenera
     JS_PROTOTYPE_OBJECT(AsyncGeneratorFunctionPrototype, AsyncGeneratorFunction, AsyncGeneratorFunction);
     JS_PROTOTYPE_OBJECT(AsyncGeneratorFunctionPrototype, AsyncGeneratorFunction, AsyncGeneratorFunction);
 
 
 public:
 public:
-    explicit AsyncGeneratorFunctionPrototype(GlobalObject&);
+    explicit AsyncGeneratorFunctionPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AsyncGeneratorFunctionPrototype() override = default;
     virtual ~AsyncGeneratorFunctionPrototype() override = default;
 };
 };

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AsyncGeneratorPrototype.cpp

@@ -9,8 +9,8 @@
 namespace JS {
 namespace JS {
 
 
 // 27.6.1 Properties of the AsyncGenerator Prototype Object, https://tc39.es/ecma262/#sec-properties-of-asyncgenerator-prototype
 // 27.6.1 Properties of the AsyncGenerator Prototype Object, https://tc39.es/ecma262/#sec-properties-of-asyncgenerator-prototype
-AsyncGeneratorPrototype::AsyncGeneratorPrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.async_iterator_prototype())
+AsyncGeneratorPrototype::AsyncGeneratorPrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().async_iterator_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AsyncGeneratorPrototype.h

@@ -15,7 +15,7 @@ class AsyncGeneratorPrototype final : public PrototypeObject<AsyncGeneratorProto
     JS_PROTOTYPE_OBJECT(AsyncGeneratorPrototype, AsyncGenerator, AsyncGenerator)
     JS_PROTOTYPE_OBJECT(AsyncGeneratorPrototype, AsyncGenerator, AsyncGenerator)
 
 
 public:
 public:
-    explicit AsyncGeneratorPrototype(GlobalObject&);
+    explicit AsyncGeneratorPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AsyncGeneratorPrototype() override = default;
     virtual ~AsyncGeneratorPrototype() override = default;
 };
 };

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AsyncIteratorPrototype.cpp

@@ -8,8 +8,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-AsyncIteratorPrototype::AsyncIteratorPrototype(GlobalObject& global_object)
-    : Object(*global_object.object_prototype())
+AsyncIteratorPrototype::AsyncIteratorPrototype(Realm& realm)
+    : Object(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AsyncIteratorPrototype.h

@@ -14,7 +14,7 @@ class AsyncIteratorPrototype final : public Object {
     JS_OBJECT(AsyncIteratorPrototype, Object)
     JS_OBJECT(AsyncIteratorPrototype, Object)
 
 
 public:
 public:
-    explicit AsyncIteratorPrototype(GlobalObject&);
+    explicit AsyncIteratorPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AsyncIteratorPrototype() override = default;
     virtual ~AsyncIteratorPrototype() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp

@@ -129,8 +129,8 @@ static ThrowCompletionOr<Value> perform_atomic_operation(GlobalObject& global_ob
     return atomic_read_modify_write(global_object, typed_array, index, value, move(operation_wrapper));
     return atomic_read_modify_write(global_object, typed_array, index, value, move(operation_wrapper));
 }
 }
 
 
-AtomicsObject::AtomicsObject(GlobalObject& global_object)
-    : Object(*global_object.object_prototype())
+AtomicsObject::AtomicsObject(Realm& realm)
+    : Object(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/AtomicsObject.h

@@ -14,7 +14,7 @@ class AtomicsObject : public Object {
     JS_OBJECT(AtomicsObject, Object);
     JS_OBJECT(AtomicsObject, Object);
 
 
 public:
 public:
-    explicit AtomicsObject(GlobalObject&);
+    explicit AtomicsObject(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~AtomicsObject() override = default;
     virtual ~AtomicsObject() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp

@@ -17,8 +17,8 @@ namespace JS {
 
 
 static const Crypto::SignedBigInteger BIGINT_ONE { 1 };
 static const Crypto::SignedBigInteger BIGINT_ONE { 1 };
 
 
-BigIntConstructor::BigIntConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.BigInt.as_string(), *global_object.function_prototype())
+BigIntConstructor::BigIntConstructor(Realm& realm)
+    : NativeFunction(vm().names.BigInt.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/BigIntConstructor.h

@@ -14,7 +14,7 @@ class BigIntConstructor final : public NativeFunction {
     JS_OBJECT(BigIntConstructor, NativeFunction);
     JS_OBJECT(BigIntConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit BigIntConstructor(GlobalObject&);
+    explicit BigIntConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~BigIntConstructor() override = default;
     virtual ~BigIntConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp

@@ -17,8 +17,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-BigIntPrototype::BigIntPrototype(GlobalObject& global_object)
-    : Object(*global_object.object_prototype())
+BigIntPrototype::BigIntPrototype(Realm& realm)
+    : Object(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/BigIntPrototype.h

@@ -14,7 +14,7 @@ class BigIntPrototype final : public Object {
     JS_OBJECT(BigIntPrototype, Object);
     JS_OBJECT(BigIntPrototype, Object);
 
 
 public:
 public:
-    explicit BigIntPrototype(GlobalObject&);
+    explicit BigIntPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~BigIntPrototype() override = default;
     virtual ~BigIntPrototype() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp

@@ -11,8 +11,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-BooleanConstructor::BooleanConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.Boolean.as_string(), *global_object.function_prototype())
+BooleanConstructor::BooleanConstructor(Realm& realm)
+    : NativeFunction(vm().names.Boolean.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/BooleanConstructor.h

@@ -14,7 +14,7 @@ class BooleanConstructor final : public NativeFunction {
     JS_OBJECT(BooleanConstructor, NativeFunction);
     JS_OBJECT(BooleanConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit BooleanConstructor(GlobalObject&);
+    explicit BooleanConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~BooleanConstructor() override = default;
     virtual ~BooleanConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp

@@ -12,8 +12,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-BooleanPrototype::BooleanPrototype(GlobalObject& global_object)
-    : BooleanObject(false, *global_object.object_prototype())
+BooleanPrototype::BooleanPrototype(Realm& realm)
+    : BooleanObject(false, *realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/BooleanPrototype.h

@@ -14,7 +14,7 @@ class BooleanPrototype final : public BooleanObject {
     JS_OBJECT(BooleanPrototype, BooleanObject);
     JS_OBJECT(BooleanPrototype, BooleanObject);
 
 
 public:
 public:
-    explicit BooleanPrototype(GlobalObject&);
+    explicit BooleanPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~BooleanPrototype() override = default;
     virtual ~BooleanPrototype() override = default;
 
 

+ 5 - 3
Userland/Libraries/LibJS/Runtime/BoundFunction.cpp

@@ -14,6 +14,8 @@ namespace JS {
 // 10.4.1.3 BoundFunctionCreate ( targetFunction, boundThis, boundArgs ), https://tc39.es/ecma262/#sec-boundfunctioncreate
 // 10.4.1.3 BoundFunctionCreate ( targetFunction, boundThis, boundArgs ), https://tc39.es/ecma262/#sec-boundfunctioncreate
 ThrowCompletionOr<BoundFunction*> BoundFunction::create(GlobalObject& global_object, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments)
 ThrowCompletionOr<BoundFunction*> BoundFunction::create(GlobalObject& global_object, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments)
 {
 {
+    auto& realm = *global_object.associated_realm();
+
     // 1. Let proto be ? targetFunction.[[GetPrototypeOf]]().
     // 1. Let proto be ? targetFunction.[[GetPrototypeOf]]().
     auto* prototype = TRY(target_function.internal_get_prototype_of());
     auto* prototype = TRY(target_function.internal_get_prototype_of());
 
 
@@ -26,14 +28,14 @@ ThrowCompletionOr<BoundFunction*> BoundFunction::create(GlobalObject& global_obj
     // 7. Set obj.[[BoundTargetFunction]] to targetFunction.
     // 7. Set obj.[[BoundTargetFunction]] to targetFunction.
     // 8. Set obj.[[BoundThis]] to boundThis.
     // 8. Set obj.[[BoundThis]] to boundThis.
     // 9. Set obj.[[BoundArguments]] to boundArgs.
     // 9. Set obj.[[BoundArguments]] to boundArgs.
-    auto* object = global_object.heap().allocate<BoundFunction>(global_object, global_object, target_function, bound_this, move(bound_arguments), prototype);
+    auto* object = global_object.heap().allocate<BoundFunction>(global_object, realm, target_function, bound_this, move(bound_arguments), prototype);
 
 
     // 10. Return obj.
     // 10. Return obj.
     return object;
     return object;
 }
 }
 
 
-BoundFunction::BoundFunction(GlobalObject& global_object, FunctionObject& bound_target_function, Value bound_this, Vector<Value> bound_arguments, Object* prototype)
-    : FunctionObject(global_object, prototype)
+BoundFunction::BoundFunction(Realm& realm, FunctionObject& bound_target_function, Value bound_this, Vector<Value> bound_arguments, Object* prototype)
+    : FunctionObject(realm, prototype)
     , m_bound_target_function(&bound_target_function)
     , m_bound_target_function(&bound_target_function)
     , m_bound_this(bound_this)
     , m_bound_this(bound_this)
     , m_bound_arguments(move(bound_arguments))
     , m_bound_arguments(move(bound_arguments))

+ 1 - 1
Userland/Libraries/LibJS/Runtime/BoundFunction.h

@@ -17,7 +17,7 @@ class BoundFunction final : public FunctionObject {
 public:
 public:
     static ThrowCompletionOr<BoundFunction*> create(GlobalObject&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments);
     static ThrowCompletionOr<BoundFunction*> create(GlobalObject&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments);
 
 
-    BoundFunction(GlobalObject&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments, Object* prototype);
+    BoundFunction(Realm&, FunctionObject& target_function, Value bound_this, Vector<Value> bound_arguments, Object* prototype);
     virtual ~BoundFunction() override = default;
     virtual ~BoundFunction() override = default;
 
 
     virtual ThrowCompletionOr<Value> internal_call(Value this_argument, MarkedVector<Value> arguments_list) override;
     virtual ThrowCompletionOr<Value> internal_call(Value this_argument, MarkedVector<Value> arguments_list) override;

+ 2 - 2
Userland/Libraries/LibJS/Runtime/ConsoleObject.cpp

@@ -12,8 +12,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-ConsoleObject::ConsoleObject(GlobalObject& global_object)
-    : Object(*global_object.object_prototype())
+ConsoleObject::ConsoleObject(Realm& realm)
+    : Object(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/ConsoleObject.h

@@ -14,7 +14,7 @@ class ConsoleObject final : public Object {
     JS_OBJECT(ConsoleObject, Object);
     JS_OBJECT(ConsoleObject, Object);
 
 
 public:
 public:
-    explicit ConsoleObject(GlobalObject&);
+    explicit ConsoleObject(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~ConsoleObject() override = default;
     virtual ~ConsoleObject() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp

@@ -13,8 +13,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-DataViewConstructor::DataViewConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.DataView.as_string(), *global_object.function_prototype())
+DataViewConstructor::DataViewConstructor(Realm& realm)
+    : NativeFunction(vm().names.DataView.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/DataViewConstructor.h

@@ -14,7 +14,7 @@ class DataViewConstructor final : public NativeFunction {
     JS_OBJECT(DataViewConstructor, NativeFunction);
     JS_OBJECT(DataViewConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit DataViewConstructor(GlobalObject&);
+    explicit DataViewConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~DataViewConstructor() override = default;
     virtual ~DataViewConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp

@@ -10,8 +10,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-DataViewPrototype::DataViewPrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.object_prototype())
+DataViewPrototype::DataViewPrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/DataViewPrototype.h

@@ -15,7 +15,7 @@ class DataViewPrototype final : public PrototypeObject<DataViewPrototype, DataVi
     JS_PROTOTYPE_OBJECT(DataViewPrototype, DataView, DataView);
     JS_PROTOTYPE_OBJECT(DataViewPrototype, DataView, DataView);
 
 
 public:
 public:
-    DataViewPrototype(GlobalObject&);
+    DataViewPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~DataViewPrototype() override = default;
     virtual ~DataViewPrototype() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/DateConstructor.cpp

@@ -162,8 +162,8 @@ static double parse_date_string(String const& date_string)
     return NAN;
     return NAN;
 }
 }
 
 
-DateConstructor::DateConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.Date.as_string(), *global_object.function_prototype())
+DateConstructor::DateConstructor(Realm& realm)
+    : NativeFunction(vm().names.Date.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/DateConstructor.h

@@ -14,7 +14,7 @@ class DateConstructor final : public NativeFunction {
     JS_OBJECT(DateConstructor, NativeFunction);
     JS_OBJECT(DateConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit DateConstructor(GlobalObject&);
+    explicit DateConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~DateConstructor() override = default;
     virtual ~DateConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/DatePrototype.cpp

@@ -30,8 +30,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-DatePrototype::DatePrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.object_prototype())
+DatePrototype::DatePrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/DatePrototype.h

@@ -15,7 +15,7 @@ class DatePrototype final : public PrototypeObject<DatePrototype, Date> {
     JS_PROTOTYPE_OBJECT(DatePrototype, Date, Date);
     JS_PROTOTYPE_OBJECT(DatePrototype, Date, Date);
 
 
 public:
 public:
-    explicit DatePrototype(GlobalObject&);
+    explicit DatePrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~DatePrototype() override = default;
     virtual ~DatePrototype() override = default;
 
 

+ 4 - 4
Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp

@@ -11,8 +11,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-ErrorConstructor::ErrorConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.Error.as_string(), *global_object.function_prototype())
+ErrorConstructor::ErrorConstructor(Realm& realm)
+    : NativeFunction(vm().names.Error.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 
@@ -63,8 +63,8 @@ ThrowCompletionOr<Object*> ErrorConstructor::construct(FunctionObject& new_targe
 }
 }
 
 
 #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType)                                                  \
 #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType)                                                  \
-    ConstructorName::ConstructorName(GlobalObject& global_object)                                                                         \
-        : NativeFunction(vm().names.ClassName.as_string(), *static_cast<Object*>(global_object.error_constructor()))                      \
+    ConstructorName::ConstructorName(Realm& realm)                                                                                        \
+        : NativeFunction(vm().names.ClassName.as_string(), *static_cast<Object*>(realm.global_object().error_constructor()))              \
     {                                                                                                                                     \
     {                                                                                                                                     \
     }                                                                                                                                     \
     }                                                                                                                                     \
                                                                                                                                           \
                                                                                                                                           \

+ 2 - 2
Userland/Libraries/LibJS/Runtime/ErrorConstructor.h

@@ -15,7 +15,7 @@ class ErrorConstructor final : public NativeFunction {
     JS_OBJECT(ErrorConstructor, NativeFunction);
     JS_OBJECT(ErrorConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit ErrorConstructor(GlobalObject&);
+    explicit ErrorConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~ErrorConstructor() override = default;
     virtual ~ErrorConstructor() override = default;
 
 
@@ -31,7 +31,7 @@ private:
         JS_OBJECT(ConstructorName, NativeFunction);                                             \
         JS_OBJECT(ConstructorName, NativeFunction);                                             \
                                                                                                 \
                                                                                                 \
     public:                                                                                     \
     public:                                                                                     \
-        explicit ConstructorName(GlobalObject&);                                                \
+        explicit ConstructorName(Realm&);                                                       \
         virtual void initialize(GlobalObject&) override;                                        \
         virtual void initialize(GlobalObject&) override;                                        \
         virtual ~ConstructorName() override;                                                    \
         virtual ~ConstructorName() override;                                                    \
         virtual ThrowCompletionOr<Value> call() override;                                       \
         virtual ThrowCompletionOr<Value> call() override;                                       \

+ 4 - 4
Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp

@@ -15,8 +15,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-ErrorPrototype::ErrorPrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.object_prototype())
+ErrorPrototype::ErrorPrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 
@@ -124,8 +124,8 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_setter)
 }
 }
 
 
 #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
 #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
-    PrototypeName::PrototypeName(GlobalObject& global_object)                            \
-        : PrototypeObject(*global_object.error_prototype())                              \
+    PrototypeName::PrototypeName(Realm& realm)                                           \
+        : PrototypeObject(*realm.global_object().error_prototype())                      \
     {                                                                                    \
     {                                                                                    \
     }                                                                                    \
     }                                                                                    \
                                                                                          \
                                                                                          \

+ 2 - 2
Userland/Libraries/LibJS/Runtime/ErrorPrototype.h

@@ -16,7 +16,7 @@ class ErrorPrototype final : public PrototypeObject<ErrorPrototype, Error> {
     JS_PROTOTYPE_OBJECT(ErrorPrototype, Error, Error);
     JS_PROTOTYPE_OBJECT(ErrorPrototype, Error, Error);
 
 
 public:
 public:
-    explicit ErrorPrototype(GlobalObject&);
+    explicit ErrorPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~ErrorPrototype() override = default;
     virtual ~ErrorPrototype() override = default;
 
 
@@ -31,7 +31,7 @@ private:
         JS_PROTOTYPE_OBJECT(PrototypeName, ClassName, ClassName);                             \
         JS_PROTOTYPE_OBJECT(PrototypeName, ClassName, ClassName);                             \
                                                                                               \
                                                                                               \
     public:                                                                                   \
     public:                                                                                   \
-        explicit PrototypeName(GlobalObject&);                                                \
+        explicit PrototypeName(Realm&);                                                       \
         virtual void initialize(GlobalObject&) override;                                      \
         virtual void initialize(GlobalObject&) override;                                      \
         virtual ~PrototypeName() override = default;                                          \
         virtual ~PrototypeName() override = default;                                          \
     };
     };

+ 2 - 2
Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.cpp

@@ -13,8 +13,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-FinalizationRegistryConstructor::FinalizationRegistryConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.FinalizationRegistry.as_string(), *global_object.function_prototype())
+FinalizationRegistryConstructor::FinalizationRegistryConstructor(Realm& realm)
+    : NativeFunction(vm().names.FinalizationRegistry.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.h

@@ -14,7 +14,7 @@ class FinalizationRegistryConstructor final : public NativeFunction {
     JS_OBJECT(FinalizationRegistryConstructor, NativeFunction);
     JS_OBJECT(FinalizationRegistryConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit FinalizationRegistryConstructor(GlobalObject&);
+    explicit FinalizationRegistryConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~FinalizationRegistryConstructor() override = default;
     virtual ~FinalizationRegistryConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp

@@ -9,8 +9,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-FinalizationRegistryPrototype::FinalizationRegistryPrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.object_prototype())
+FinalizationRegistryPrototype::FinalizationRegistryPrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.h

@@ -15,7 +15,7 @@ class FinalizationRegistryPrototype final : public PrototypeObject<FinalizationR
     JS_PROTOTYPE_OBJECT(FinalizationRegistryPrototype, FinalizationRegistry, FinalizationRegistry);
     JS_PROTOTYPE_OBJECT(FinalizationRegistryPrototype, FinalizationRegistry, FinalizationRegistry);
 
 
 public:
 public:
-    FinalizationRegistryPrototype(GlobalObject&);
+    FinalizationRegistryPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~FinalizationRegistryPrototype() override = default;
     virtual ~FinalizationRegistryPrototype() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp

@@ -19,8 +19,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-FunctionConstructor::FunctionConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.Function.as_string(), *global_object.function_prototype())
+FunctionConstructor::FunctionConstructor(Realm& realm)
+    : NativeFunction(vm().names.Function.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/FunctionConstructor.h

@@ -17,7 +17,7 @@ class FunctionConstructor final : public NativeFunction {
 public:
 public:
     static ThrowCompletionOr<ECMAScriptFunctionObject*> create_dynamic_function(GlobalObject& global_object, FunctionObject& constructor, FunctionObject* new_target, FunctionKind kind, MarkedVector<Value> const& args);
     static ThrowCompletionOr<ECMAScriptFunctionObject*> create_dynamic_function(GlobalObject& global_object, FunctionObject& constructor, FunctionObject* new_target, FunctionKind kind, MarkedVector<Value> const& args);
 
 
-    explicit FunctionConstructor(GlobalObject&);
+    explicit FunctionConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~FunctionConstructor() override = default;
     virtual ~FunctionConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/FunctionObject.cpp

@@ -11,8 +11,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-FunctionObject::FunctionObject(GlobalObject& global_object, Object* prototype)
-    : Object(global_object, prototype)
+FunctionObject::FunctionObject(Realm& realm, Object* prototype)
+    : Object(realm, prototype)
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/FunctionObject.h

@@ -40,7 +40,7 @@ public:
     virtual Realm* realm() const { return nullptr; }
     virtual Realm* realm() const { return nullptr; }
 
 
 protected:
 protected:
-    explicit FunctionObject(GlobalObject&, Object* prototype);
+    explicit FunctionObject(Realm&, Object* prototype);
     explicit FunctionObject(Object& prototype);
     explicit FunctionObject(Object& prototype);
 
 
 private:
 private:

+ 2 - 2
Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp

@@ -20,8 +20,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-FunctionPrototype::FunctionPrototype(GlobalObject& global_object)
-    : FunctionObject(*global_object.object_prototype())
+FunctionPrototype::FunctionPrototype(Realm& realm)
+    : FunctionObject(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/FunctionPrototype.h

@@ -14,7 +14,7 @@ class FunctionPrototype final : public FunctionObject {
     JS_OBJECT(FunctionPrototype, FunctionObject);
     JS_OBJECT(FunctionPrototype, FunctionObject);
 
 
 public:
 public:
-    explicit FunctionPrototype(GlobalObject&);
+    explicit FunctionPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~FunctionPrototype() override = default;
     virtual ~FunctionPrototype() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp

@@ -11,8 +11,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-GeneratorFunctionConstructor::GeneratorFunctionConstructor(GlobalObject& global_object)
-    : NativeFunction(*static_cast<Object*>(global_object.function_constructor()))
+GeneratorFunctionConstructor::GeneratorFunctionConstructor(Realm& realm)
+    : NativeFunction(static_cast<Object&>(*realm.global_object().function_constructor()))
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.h

@@ -15,7 +15,7 @@ class GeneratorFunctionConstructor final : public NativeFunction {
     JS_OBJECT(GeneratorFunctionConstructor, NativeFunction);
     JS_OBJECT(GeneratorFunctionConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit GeneratorFunctionConstructor(GlobalObject&);
+    explicit GeneratorFunctionConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~GeneratorFunctionConstructor() override = default;
     virtual ~GeneratorFunctionConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp

@@ -10,8 +10,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-GeneratorFunctionPrototype::GeneratorFunctionPrototype(GlobalObject& global_object)
-    : Object(*global_object.function_prototype())
+GeneratorFunctionPrototype::GeneratorFunctionPrototype(Realm& realm)
+    : Object(*realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.h

@@ -16,7 +16,7 @@ class GeneratorFunctionPrototype final : public Object {
     JS_OBJECT(GeneratorFunctionPrototype, Object);
     JS_OBJECT(GeneratorFunctionPrototype, Object);
 
 
 public:
 public:
-    explicit GeneratorFunctionPrototype(GlobalObject&);
+    explicit GeneratorFunctionPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~GeneratorFunctionPrototype() override = default;
     virtual ~GeneratorFunctionPrototype() override = default;
 };
 };

+ 4 - 2
Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp

@@ -15,6 +15,8 @@ namespace JS {
 
 
 ThrowCompletionOr<GeneratorObject*> GeneratorObject::create(GlobalObject& global_object, Value initial_value, ECMAScriptFunctionObject* generating_function, ExecutionContext execution_context, Bytecode::RegisterWindow frame)
 ThrowCompletionOr<GeneratorObject*> GeneratorObject::create(GlobalObject& global_object, Value initial_value, ECMAScriptFunctionObject* generating_function, ExecutionContext execution_context, Bytecode::RegisterWindow frame)
 {
 {
+    auto& realm = *global_object.associated_realm();
+
     // This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
     // This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
     Value generating_function_prototype;
     Value generating_function_prototype;
     if (generating_function->kind() == FunctionKind::Async) {
     if (generating_function->kind() == FunctionKind::Async) {
@@ -26,14 +28,14 @@ ThrowCompletionOr<GeneratorObject*> GeneratorObject::create(GlobalObject& global
         generating_function_prototype = TRY(generating_function->get(global_object.vm().names.prototype));
         generating_function_prototype = TRY(generating_function->get(global_object.vm().names.prototype));
     }
     }
     auto* generating_function_prototype_object = TRY(generating_function_prototype.to_object(global_object));
     auto* generating_function_prototype_object = TRY(generating_function_prototype.to_object(global_object));
-    auto object = global_object.heap().allocate<GeneratorObject>(global_object, global_object, *generating_function_prototype_object, move(execution_context));
+    auto object = global_object.heap().allocate<GeneratorObject>(global_object, realm, *generating_function_prototype_object, move(execution_context));
     object->m_generating_function = generating_function;
     object->m_generating_function = generating_function;
     object->m_frame = move(frame);
     object->m_frame = move(frame);
     object->m_previous_value = initial_value;
     object->m_previous_value = initial_value;
     return object;
     return object;
 }
 }
 
 
-GeneratorObject::GeneratorObject(GlobalObject&, Object& prototype, ExecutionContext context)
+GeneratorObject::GeneratorObject(Realm&, Object& prototype, ExecutionContext context)
     : Object(prototype)
     : Object(prototype)
     , m_execution_context(move(context))
     , m_execution_context(move(context))
 {
 {

+ 1 - 1
Userland/Libraries/LibJS/Runtime/GeneratorObject.h

@@ -17,7 +17,7 @@ class GeneratorObject final : public Object {
 
 
 public:
 public:
     static ThrowCompletionOr<GeneratorObject*> create(GlobalObject&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::RegisterWindow);
     static ThrowCompletionOr<GeneratorObject*> create(GlobalObject&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::RegisterWindow);
-    GeneratorObject(GlobalObject&, Object& prototype, ExecutionContext);
+    GeneratorObject(Realm&, Object& prototype, ExecutionContext);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~GeneratorObject() override = default;
     virtual ~GeneratorObject() override = default;
     void visit_edges(Cell::Visitor&) override;
     void visit_edges(Cell::Visitor&) override;

+ 2 - 2
Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp

@@ -9,8 +9,8 @@
 
 
 namespace JS {
 namespace JS {
 
 
-GeneratorPrototype::GeneratorPrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.iterator_prototype())
+GeneratorPrototype::GeneratorPrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().iterator_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/GeneratorPrototype.h

@@ -16,7 +16,7 @@ class GeneratorPrototype final : public PrototypeObject<GeneratorPrototype, Gene
     JS_PROTOTYPE_OBJECT(GeneratorPrototype, GeneratorObject, Generator);
     JS_PROTOTYPE_OBJECT(GeneratorPrototype, GeneratorObject, Generator);
 
 
 public:
 public:
-    explicit GeneratorPrototype(GlobalObject&);
+    explicit GeneratorPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~GeneratorPrototype() override = default;
     virtual ~GeneratorPrototype() override = default;
 
 

+ 18 - 18
Userland/Libraries/LibJS/Runtime/GlobalObject.cpp

@@ -155,8 +155,8 @@ void GlobalObject::initialize_global_object()
     VERIFY(associated_realm());
     VERIFY(associated_realm());
     auto& realm = *associated_realm();
     auto& realm = *associated_realm();
     m_empty_object_shape = heap().allocate_without_global_object<Shape>(realm);
     m_empty_object_shape = heap().allocate_without_global_object<Shape>(realm);
-    m_object_prototype = heap().allocate_without_global_object<ObjectPrototype>(*this);
-    m_function_prototype = heap().allocate_without_global_object<FunctionPrototype>(*this);
+    m_object_prototype = heap().allocate_without_global_object<ObjectPrototype>(realm);
+    m_function_prototype = heap().allocate_without_global_object<FunctionPrototype>(realm);
 
 
     m_new_object_shape = vm.heap().allocate_without_global_object<Shape>(realm);
     m_new_object_shape = vm.heap().allocate_without_global_object<Shape>(realm);
     m_new_object_shape->set_prototype_without_transition(m_object_prototype);
     m_new_object_shape->set_prototype_without_transition(m_object_prototype);
@@ -174,29 +174,29 @@ void GlobalObject::initialize_global_object()
     Object::set_prototype(m_object_prototype);
     Object::set_prototype(m_object_prototype);
 
 
     // This must be initialized before allocating AggregateErrorPrototype, which uses ErrorPrototype as its prototype.
     // This must be initialized before allocating AggregateErrorPrototype, which uses ErrorPrototype as its prototype.
-    m_error_prototype = heap().allocate<ErrorPrototype>(*this, *this);
+    m_error_prototype = heap().allocate<ErrorPrototype>(*this, realm);
 
 
 #define __JS_ENUMERATE(ClassName, snake_name) \
 #define __JS_ENUMERATE(ClassName, snake_name) \
     if (!m_##snake_name##_prototype)          \
     if (!m_##snake_name##_prototype)          \
-        m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(*this, *this);
+        m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(*this, realm);
     JS_ENUMERATE_ITERATOR_PROTOTYPES
     JS_ENUMERATE_ITERATOR_PROTOTYPES
 #undef __JS_ENUMERATE
 #undef __JS_ENUMERATE
 
 
     // These must be initialized separately as they have no companion constructor
     // These must be initialized separately as they have no companion constructor
-    m_async_from_sync_iterator_prototype = heap().allocate<AsyncFromSyncIteratorPrototype>(*this, *this);
-    m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(*this, *this);
-    m_generator_prototype = heap().allocate<GeneratorPrototype>(*this, *this);
-    m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(*this, *this);
+    m_async_from_sync_iterator_prototype = heap().allocate<AsyncFromSyncIteratorPrototype>(*this, realm);
+    m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(*this, realm);
+    m_generator_prototype = heap().allocate<GeneratorPrototype>(*this, realm);
+    m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(*this, realm);
 
 
 #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
 #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
     if (!m_##snake_name##_prototype)                                                     \
     if (!m_##snake_name##_prototype)                                                     \
-        m_##snake_name##_prototype = heap().allocate<PrototypeName>(*this, *this);
+        m_##snake_name##_prototype = heap().allocate<PrototypeName>(*this, realm);
     JS_ENUMERATE_BUILTIN_TYPES
     JS_ENUMERATE_BUILTIN_TYPES
 #undef __JS_ENUMERATE
 #undef __JS_ENUMERATE
 
 
 #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
 #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
     if (!m_intl_##snake_name##_prototype)                                     \
     if (!m_intl_##snake_name##_prototype)                                     \
-        m_intl_##snake_name##_prototype = heap().allocate<Intl::PrototypeName>(*this, *this);
+        m_intl_##snake_name##_prototype = heap().allocate<Intl::PrototypeName>(*this, realm);
     JS_ENUMERATE_INTL_OBJECTS
     JS_ENUMERATE_INTL_OBJECTS
 #undef __JS_ENUMERATE
 #undef __JS_ENUMERATE
 
 
@@ -208,7 +208,7 @@ void GlobalObject::initialize_global_object()
 
 
 #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
 #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
     if (!m_temporal_##snake_name##_prototype)                                 \
     if (!m_temporal_##snake_name##_prototype)                                 \
-        m_temporal_##snake_name##_prototype = heap().allocate<Temporal::PrototypeName>(*this, *this);
+        m_temporal_##snake_name##_prototype = heap().allocate<Temporal::PrototypeName>(*this, realm);
     JS_ENUMERATE_TEMPORAL_OBJECTS
     JS_ENUMERATE_TEMPORAL_OBJECTS
 #undef __JS_ENUMERATE
 #undef __JS_ENUMERATE
 
 
@@ -250,13 +250,13 @@ void GlobalObject::initialize_global_object()
     define_direct_property(vm.names.undefined, js_undefined(), 0);
     define_direct_property(vm.names.undefined, js_undefined(), 0);
 
 
     define_direct_property(vm.names.globalThis, this, attr);
     define_direct_property(vm.names.globalThis, this, attr);
-    define_direct_property(vm.names.console, heap().allocate<ConsoleObject>(*this, *this), attr);
-    define_direct_property(vm.names.Atomics, heap().allocate<AtomicsObject>(*this, *this), attr);
-    define_direct_property(vm.names.Math, heap().allocate<MathObject>(*this, *this), attr);
-    define_direct_property(vm.names.JSON, heap().allocate<JSONObject>(*this, *this), attr);
-    define_direct_property(vm.names.Reflect, heap().allocate<ReflectObject>(*this, *this), attr);
-    define_direct_property(vm.names.Intl, heap().allocate<Intl::Intl>(*this, *this), attr);
-    define_direct_property(vm.names.Temporal, heap().allocate<Temporal::Temporal>(*this, *this), attr);
+    define_direct_property(vm.names.console, heap().allocate<ConsoleObject>(*this, realm), attr);
+    define_direct_property(vm.names.Atomics, heap().allocate<AtomicsObject>(*this, realm), attr);
+    define_direct_property(vm.names.Math, heap().allocate<MathObject>(*this, realm), attr);
+    define_direct_property(vm.names.JSON, heap().allocate<JSONObject>(*this, realm), attr);
+    define_direct_property(vm.names.Reflect, heap().allocate<ReflectObject>(*this, realm), attr);
+    define_direct_property(vm.names.Intl, heap().allocate<Intl::Intl>(*this, realm), attr);
+    define_direct_property(vm.names.Temporal, heap().allocate<Temporal::Temporal>(*this, realm), attr);
 
 
     // This must be initialized before allocating AggregateErrorConstructor, which uses ErrorConstructor as its prototype.
     // This must be initialized before allocating AggregateErrorConstructor, which uses ErrorConstructor as its prototype.
     initialize_constructor(vm.names.Error, m_error_constructor, m_error_prototype);
     initialize_constructor(vm.names.Error, m_error_constructor, m_error_prototype);

+ 2 - 1
Userland/Libraries/LibJS/Runtime/GlobalObject.h

@@ -177,7 +177,8 @@ template<typename ConstructorType>
 inline void GlobalObject::initialize_constructor(PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype, PropertyAttributes attributes)
 inline void GlobalObject::initialize_constructor(PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype, PropertyAttributes attributes)
 {
 {
     auto& vm = this->vm();
     auto& vm = this->vm();
-    constructor = heap().allocate<ConstructorType>(*this, *this);
+    auto& realm = *associated_realm();
+    constructor = heap().allocate<ConstructorType>(*this, realm);
     constructor->define_direct_property(vm.names.name, js_string(heap(), property_key.as_string()), Attribute::Configurable);
     constructor->define_direct_property(vm.names.name, js_string(heap(), property_key.as_string()), Attribute::Configurable);
     if (prototype)
     if (prototype)
         prototype->define_direct_property(vm.names.constructor, constructor, attributes);
         prototype->define_direct_property(vm.names.constructor, constructor, attributes);

+ 4 - 3
Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.cpp

@@ -13,11 +13,12 @@ namespace JS::Intl {
 
 
 CollatorCompareFunction* CollatorCompareFunction::create(GlobalObject& global_object, Collator& collator)
 CollatorCompareFunction* CollatorCompareFunction::create(GlobalObject& global_object, Collator& collator)
 {
 {
-    return global_object.heap().allocate<CollatorCompareFunction>(global_object, global_object, collator);
+    auto& realm = *global_object.associated_realm();
+    return global_object.heap().allocate<CollatorCompareFunction>(global_object, realm, collator);
 }
 }
 
 
-CollatorCompareFunction::CollatorCompareFunction(GlobalObject& global_object, Collator& collator)
-    : NativeFunction(*global_object.function_prototype())
+CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator)
+    : NativeFunction(*realm.global_object().function_prototype())
     , m_collator(collator)
     , m_collator(collator)
 {
 {
 }
 }

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/CollatorCompareFunction.h

@@ -16,7 +16,7 @@ class CollatorCompareFunction : public NativeFunction {
 public:
 public:
     static CollatorCompareFunction* create(GlobalObject&, Collator&);
     static CollatorCompareFunction* create(GlobalObject&, Collator&);
 
 
-    explicit CollatorCompareFunction(GlobalObject&, Collator&);
+    CollatorCompareFunction(Realm&, Collator&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~CollatorCompareFunction() override = default;
     virtual ~CollatorCompareFunction() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.cpp

@@ -132,8 +132,8 @@ static ThrowCompletionOr<Collator*> initialize_collator(GlobalObject& global_obj
 }
 }
 
 
 // 10.1 The Intl.Collator Constructor, https://tc39.es/ecma402/#sec-the-intl-collator-constructor
 // 10.1 The Intl.Collator Constructor, https://tc39.es/ecma402/#sec-the-intl-collator-constructor
-CollatorConstructor::CollatorConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.Collator.as_string(), *global_object.function_prototype())
+CollatorConstructor::CollatorConstructor(Realm& realm)
+    : NativeFunction(vm().names.Collator.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/CollatorConstructor.h

@@ -14,7 +14,7 @@ class CollatorConstructor final : public NativeFunction {
     JS_OBJECT(CollatorConstructor, NativeFunction);
     JS_OBJECT(CollatorConstructor, NativeFunction);
 
 
 public:
 public:
-    explicit CollatorConstructor(GlobalObject&);
+    explicit CollatorConstructor(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~CollatorConstructor() override = default;
     virtual ~CollatorConstructor() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.cpp

@@ -12,8 +12,8 @@
 namespace JS::Intl {
 namespace JS::Intl {
 
 
 // 10.3 Properties of the Intl.Collator Prototype Object, https://tc39.es/ecma402/#sec-properties-of-the-intl-collator-prototype-object
 // 10.3 Properties of the Intl.Collator Prototype Object, https://tc39.es/ecma402/#sec-properties-of-the-intl-collator-prototype-object
-CollatorPrototype::CollatorPrototype(GlobalObject& global_object)
-    : PrototypeObject(*global_object.object_prototype())
+CollatorPrototype::CollatorPrototype(Realm& realm)
+    : PrototypeObject(*realm.global_object().object_prototype())
 {
 {
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/CollatorPrototype.h

@@ -15,7 +15,7 @@ class CollatorPrototype final : public PrototypeObject<CollatorPrototype, Collat
     JS_PROTOTYPE_OBJECT(CollatorPrototype, Collator, Collator);
     JS_PROTOTYPE_OBJECT(CollatorPrototype, Collator, Collator);
 
 
 public:
 public:
-    explicit CollatorPrototype(GlobalObject&);
+    explicit CollatorPrototype(Realm&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;
     virtual ~CollatorPrototype() override = default;
     virtual ~CollatorPrototype() override = default;
 
 

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp

@@ -17,8 +17,8 @@
 namespace JS::Intl {
 namespace JS::Intl {
 
 
 // 11.1 The Intl.DateTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-datetimeformat-constructor
 // 11.1 The Intl.DateTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-datetimeformat-constructor
-DateTimeFormatConstructor::DateTimeFormatConstructor(GlobalObject& global_object)
-    : NativeFunction(vm().names.DateTimeFormat.as_string(), *global_object.function_prototype())
+DateTimeFormatConstructor::DateTimeFormatConstructor(Realm& realm)
+    : NativeFunction(vm().names.DateTimeFormat.as_string(), *realm.global_object().function_prototype())
 {
 {
 }
 }
 
 

Some files were not shown because too many files changed in this diff