mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 02:57:44 +00:00
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.
This commit is contained in:
parent
4c300cc5e8
commit
ecd163bdf1
315 changed files with 592 additions and 554 deletions
|
@ -14,8 +14,8 @@
|
|||
|
||||
namespace Web::Bindings {
|
||||
|
||||
AudioConstructor::AudioConstructor(JS::GlobalObject& global_object)
|
||||
: NativeFunction(*global_object.function_prototype())
|
||||
AudioConstructor::AudioConstructor(JS::Realm& realm)
|
||||
: NativeFunction(*realm.global_object().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Web::Bindings {
|
|||
|
||||
class AudioConstructor final : public JS::NativeFunction {
|
||||
public:
|
||||
explicit AudioConstructor(JS::GlobalObject&);
|
||||
explicit AudioConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~AudioConstructor() override = default;
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
|
||||
namespace Web::Bindings {
|
||||
|
||||
CSSNamespace::CSSNamespace(JS::GlobalObject& global_object)
|
||||
: JS::Object(*global_object.object_prototype())
|
||||
CSSNamespace::CSSNamespace(JS::Realm& realm)
|
||||
: JS::Object(*realm.global_object().object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class CSSNamespace final : public JS::Object {
|
|||
JS_OBJECT(CSSNamespace, JS::Object)
|
||||
|
||||
public:
|
||||
explicit CSSNamespace(JS::GlobalObject&);
|
||||
explicit CSSNamespace(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~CSSNamespace() override = default;
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
namespace Web {
|
||||
namespace Bindings {
|
||||
|
||||
EventListenerWrapper::EventListenerWrapper(JS::GlobalObject& global_object, DOM::IDLEventListener& impl)
|
||||
: Wrapper(*global_object.object_prototype())
|
||||
EventListenerWrapper::EventListenerWrapper(JS::Realm& realm, DOM::IDLEventListener& impl)
|
||||
: Wrapper(*realm.global_object().object_prototype())
|
||||
, m_impl(impl)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class EventListenerWrapper final : public Wrapper {
|
|||
JS_OBJECT(EventListenerWrapper, Wrapper);
|
||||
|
||||
public:
|
||||
EventListenerWrapper(JS::GlobalObject&, DOM::IDLEventListener&);
|
||||
EventListenerWrapper(JS::Realm& realm, DOM::IDLEventListener&);
|
||||
virtual ~EventListenerWrapper() override = default;
|
||||
|
||||
DOM::IDLEventListener& impl() { return *m_impl; }
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
namespace Web::Bindings {
|
||||
|
||||
ImageConstructor::ImageConstructor(JS::GlobalObject& global_object)
|
||||
: NativeFunction(*global_object.function_prototype())
|
||||
ImageConstructor::ImageConstructor(JS::Realm& realm)
|
||||
: NativeFunction(*realm.global_object().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Web::Bindings {
|
|||
|
||||
class ImageConstructor final : public JS::NativeFunction {
|
||||
public:
|
||||
explicit ImageConstructor(JS::GlobalObject&);
|
||||
explicit ImageConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~ImageConstructor() override = default;
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
namespace Web::Bindings {
|
||||
|
||||
LocationConstructor::LocationConstructor(JS::GlobalObject& global_object)
|
||||
: NativeFunction(*global_object.function_prototype())
|
||||
LocationConstructor::LocationConstructor(JS::Realm& realm)
|
||||
: NativeFunction(*realm.global_object().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class LocationConstructor : public JS::NativeFunction {
|
|||
JS_OBJECT(LocationConstructor, JS::NativeFunction);
|
||||
|
||||
public:
|
||||
explicit LocationConstructor(JS::GlobalObject&);
|
||||
explicit LocationConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~LocationConstructor() override;
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
namespace Web::Bindings {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/history.html#the-location-interface
|
||||
LocationObject::LocationObject(JS::GlobalObject& global_object)
|
||||
: Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<LocationPrototype>("Location"))
|
||||
LocationObject::LocationObject(JS::Realm& realm)
|
||||
: Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<LocationPrototype>("Location"))
|
||||
, m_default_properties(heap())
|
||||
{
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class LocationObject final : public JS::Object {
|
|||
JS_OBJECT(LocationObject, JS::Object);
|
||||
|
||||
public:
|
||||
explicit LocationObject(JS::GlobalObject&);
|
||||
explicit LocationObject(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~LocationObject() override = default;
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ class LocationPrototype final : public JS::Object {
|
|||
JS_OBJECT(LocationPrototype, JS::Object);
|
||||
|
||||
public:
|
||||
explicit LocationPrototype(JS::GlobalObject& global_object)
|
||||
: JS::Object(*global_object.object_prototype())
|
||||
explicit LocationPrototype(JS::Realm& realm)
|
||||
: JS::Object(*realm.global_object().object_prototype())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
namespace Web::Bindings {
|
||||
|
||||
NavigatorConstructor::NavigatorConstructor(JS::GlobalObject& global_object)
|
||||
: NativeFunction(*global_object.function_prototype())
|
||||
NavigatorConstructor::NavigatorConstructor(JS::Realm& realm)
|
||||
: NativeFunction(*realm.global_object().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class NavigatorConstructor : public JS::NativeFunction {
|
|||
JS_OBJECT(NavigatorConstructor, JS::NativeFunction);
|
||||
|
||||
public:
|
||||
explicit NavigatorConstructor(JS::GlobalObject&);
|
||||
explicit NavigatorConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~NavigatorConstructor() override;
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
namespace Web {
|
||||
namespace Bindings {
|
||||
|
||||
NavigatorObject::NavigatorObject(JS::GlobalObject& global_object)
|
||||
: Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<NavigatorPrototype>("Navigator"))
|
||||
NavigatorObject::NavigatorObject(JS::Realm& realm)
|
||||
: Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<NavigatorPrototype>("Navigator"))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class NavigatorObject final : public JS::Object {
|
|||
JS_OBJECT(NavigatorObject, JS::Object);
|
||||
|
||||
public:
|
||||
NavigatorObject(JS::GlobalObject&);
|
||||
NavigatorObject(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~NavigatorObject() override = default;
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ class NavigatorPrototype final : public JS::Object {
|
|||
JS_OBJECT(NavigatorPrototype, JS::Object);
|
||||
|
||||
public:
|
||||
explicit NavigatorPrototype(JS::GlobalObject& global_object)
|
||||
: JS::Object(*global_object.object_prototype())
|
||||
explicit NavigatorPrototype(JS::Realm& realm)
|
||||
: JS::Object(*realm.global_object().object_prototype())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
namespace Web::Bindings {
|
||||
|
||||
OptionConstructor::OptionConstructor(JS::GlobalObject& global_object)
|
||||
: NativeFunction(*global_object.function_prototype())
|
||||
OptionConstructor::OptionConstructor(JS::Realm& realm)
|
||||
: NativeFunction(*realm.global_object().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Web::Bindings {
|
|||
|
||||
class OptionConstructor final : public JS::NativeFunction {
|
||||
public:
|
||||
explicit OptionConstructor(JS::GlobalObject&);
|
||||
explicit OptionConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~OptionConstructor() override = default;
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
namespace Web::Bindings {
|
||||
|
||||
WindowConstructor::WindowConstructor(JS::GlobalObject& global_object)
|
||||
: NativeFunction(*global_object.function_prototype())
|
||||
WindowConstructor::WindowConstructor(JS::Realm& realm)
|
||||
: NativeFunction(*realm.global_object().function_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class WindowConstructor : public JS::NativeFunction {
|
|||
JS_OBJECT(WindowConstructor, JS::NativeFunction);
|
||||
|
||||
public:
|
||||
explicit WindowConstructor(JS::GlobalObject&);
|
||||
explicit WindowConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual ~WindowConstructor() override;
|
||||
|
||||
|
|
|
@ -63,6 +63,8 @@ void WindowObject::initialize_global_object()
|
|||
|
||||
Object::set_prototype(&ensure_web_prototype<WindowPrototype>("Window"));
|
||||
|
||||
auto& realm = *associated_realm();
|
||||
|
||||
// FIXME: These should be native accessors, not properties
|
||||
define_direct_property("window", this, JS::Attribute::Enumerable);
|
||||
define_direct_property("frames", this, JS::Attribute::Enumerable);
|
||||
|
@ -117,7 +119,7 @@ void WindowObject::initialize_global_object()
|
|||
define_native_accessor("screenLeft", screen_left_getter, {}, attr);
|
||||
define_native_accessor("screenTop", screen_top_getter, {}, attr);
|
||||
|
||||
define_direct_property("CSS", heap().allocate<CSSNamespace>(*this, *this), 0);
|
||||
define_direct_property("CSS", heap().allocate<CSSNamespace>(*this, realm), 0);
|
||||
|
||||
define_native_accessor("localStorage", local_storage_getter, {}, attr);
|
||||
define_native_accessor("sessionStorage", session_storage_getter, {}, attr);
|
||||
|
@ -126,9 +128,9 @@ void WindowObject::initialize_global_object()
|
|||
// Legacy
|
||||
define_native_accessor("event", event_getter, event_setter, JS::Attribute::Enumerable);
|
||||
|
||||
m_location_object = heap().allocate<LocationObject>(*this, *this);
|
||||
m_location_object = heap().allocate<LocationObject>(*this, realm);
|
||||
|
||||
auto* m_navigator_object = heap().allocate<NavigatorObject>(*this, *this);
|
||||
auto* m_navigator_object = heap().allocate<NavigatorObject>(*this, realm);
|
||||
define_direct_property("navigator", m_navigator_object, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
define_direct_property("clientInformation", m_navigator_object, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
|
||||
|
@ -136,7 +138,7 @@ void WindowObject::initialize_global_object()
|
|||
define_native_accessor("location", location_getter, location_setter, JS::Attribute::Enumerable);
|
||||
|
||||
// WebAssembly "namespace"
|
||||
define_direct_property("WebAssembly", heap().allocate<WebAssemblyObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
define_direct_property("WebAssembly", heap().allocate<WebAssemblyObject>(*this, realm), JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
|
||||
// HTML::GlobalEventHandlers and HTML::WindowEventHandlers
|
||||
#define __ENUMERATE(attribute, event_name) \
|
||||
|
|
|
@ -53,7 +53,8 @@ public:
|
|||
auto it = m_prototypes.find(class_name);
|
||||
if (it != m_prototypes.end())
|
||||
return *it->value;
|
||||
auto* prototype = heap().allocate<T>(*this, *this);
|
||||
auto& realm = *associated_realm();
|
||||
auto* prototype = heap().allocate<T>(*this, realm);
|
||||
m_prototypes.set(class_name, prototype);
|
||||
return *prototype;
|
||||
}
|
||||
|
@ -64,7 +65,8 @@ public:
|
|||
auto it = m_constructors.find(class_name);
|
||||
if (it != m_constructors.end())
|
||||
return *it->value;
|
||||
auto* constructor = heap().allocate<T>(*this, *this);
|
||||
auto& realm = *associated_realm();
|
||||
auto* constructor = heap().allocate<T>(*this, realm);
|
||||
m_constructors.set(class_name, constructor);
|
||||
define_direct_property(class_name, JS::Value(constructor), JS::Attribute::Writable | JS::Attribute::Configurable);
|
||||
return *constructor;
|
||||
|
|
|
@ -19,8 +19,8 @@ class WindowPrototype final : public JS::Object {
|
|||
JS_OBJECT(WindowPrototype, JS::Object);
|
||||
|
||||
public:
|
||||
explicit WindowPrototype(JS::GlobalObject& global_object)
|
||||
: JS::Object(static_cast<WindowObject&>(global_object).ensure_web_prototype<EventTargetPrototype>("EventTarget"))
|
||||
explicit WindowPrototype(JS::Realm& realm)
|
||||
: JS::Object(static_cast<WindowObject&>(realm.global_object()).ensure_web_prototype<EventTargetPrototype>("EventTarget"))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
namespace Web::Bindings {
|
||||
|
||||
// 7.4 The WindowProxy exotic object, https://html.spec.whatwg.org/multipage/window-object.html#the-windowproxy-exotic-object
|
||||
WindowProxy::WindowProxy(JS::GlobalObject& global_object, WindowObject& window)
|
||||
: JS::Object(global_object, nullptr)
|
||||
WindowProxy::WindowProxy(JS::Realm& realm, WindowObject& window)
|
||||
: JS::Object(realm, nullptr)
|
||||
, m_window(&window)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class WindowProxy final : public JS::Object {
|
|||
JS_OBJECT(WindowProxy, JS::Object);
|
||||
|
||||
public:
|
||||
WindowProxy(JS::GlobalObject&, WindowObject&);
|
||||
WindowProxy(JS::Realm&, WindowObject&);
|
||||
virtual ~WindowProxy() override = default;
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Object*> internal_get_prototype_of() const override;
|
||||
|
|
|
@ -28,8 +28,9 @@ private:
|
|||
template<class NativeObject>
|
||||
inline Wrapper* wrap_impl(JS::GlobalObject& global_object, NativeObject& native_object)
|
||||
{
|
||||
auto& realm = *global_object.associated_realm();
|
||||
if (!native_object.wrapper()) {
|
||||
native_object.set_wrapper(*global_object.heap().allocate<typename NativeObject::WrapperType>(global_object, global_object, native_object));
|
||||
native_object.set_wrapper(*global_object.heap().allocate<typename NativeObject::WrapperType>(global_object, realm, native_object));
|
||||
}
|
||||
return native_object.wrapper();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue