1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:17:34 +00:00

LibWeb: Replace usage of native properties with accessors in Window

This is required by the WebIDL specification.
This commit is contained in:
Idan Horowitz 2021-07-05 15:04:18 +03:00 committed by Linus Groh
parent 4fdf4bfbd0
commit c830de4983
2 changed files with 25 additions and 24 deletions

View file

@ -46,16 +46,17 @@ void WindowObject::initialize_global_object()
auto success = Object::internal_set_prototype_of(&ensure_web_prototype<EventTargetPrototype>("EventTarget")); auto success = Object::internal_set_prototype_of(&ensure_web_prototype<EventTargetPrototype>("EventTarget"));
VERIFY(success); VERIFY(success);
// FIXME: These should be native accessors, not properties
define_property("window", this, JS::Attribute::Enumerable); define_property("window", this, JS::Attribute::Enumerable);
define_property("frames", this, JS::Attribute::Enumerable); define_property("frames", this, JS::Attribute::Enumerable);
define_property("self", this, JS::Attribute::Enumerable); define_property("self", this, JS::Attribute::Enumerable);
define_native_property("top", top_getter, nullptr, JS::Attribute::Enumerable); define_native_accessor("top", top_getter, nullptr, JS::Attribute::Enumerable);
define_native_property("parent", parent_getter, nullptr, JS::Attribute::Enumerable); define_native_accessor("parent", parent_getter, {}, JS::Attribute::Enumerable);
define_native_property("document", document_getter, nullptr, JS::Attribute::Enumerable); define_native_accessor("document", document_getter, {}, JS::Attribute::Enumerable);
define_native_property("performance", performance_getter, nullptr, JS::Attribute::Enumerable); define_native_accessor("performance", performance_getter, {}, JS::Attribute::Enumerable);
define_native_property("screen", screen_getter, nullptr, JS::Attribute::Enumerable); define_native_accessor("screen", screen_getter, {}, JS::Attribute::Enumerable);
define_native_property("innerWidth", inner_width_getter, nullptr, JS::Attribute::Enumerable); define_native_accessor("innerWidth", inner_width_getter, {}, JS::Attribute::Enumerable);
define_native_property("innerHeight", inner_height_getter, nullptr, JS::Attribute::Enumerable); define_native_accessor("innerHeight", inner_height_getter, {}, JS::Attribute::Enumerable);
define_native_function("alert", alert); define_native_function("alert", alert);
define_native_function("confirm", confirm); define_native_function("confirm", confirm);
define_native_function("prompt", prompt); define_native_function("prompt", prompt);
@ -69,7 +70,7 @@ void WindowObject::initialize_global_object()
define_native_function("btoa", btoa, 1); define_native_function("btoa", btoa, 1);
// Legacy // Legacy
define_native_property("event", event_getter, nullptr, JS::Attribute::Enumerable); define_native_accessor("event", event_getter, {}, JS::Attribute::Enumerable);
define_property("navigator", heap().allocate<NavigatorObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); define_property("navigator", heap().allocate<NavigatorObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); define_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable);
@ -341,7 +342,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa)
} }
// https://html.spec.whatwg.org/multipage/browsers.html#dom-top // https://html.spec.whatwg.org/multipage/browsers.html#dom-top
JS_DEFINE_NATIVE_GETTER(WindowObject::top_getter) JS_DEFINE_NATIVE_FUNCTION(WindowObject::top_getter)
{ {
auto* impl = impl_from(vm, global_object); auto* impl = impl_from(vm, global_object);
if (!impl) if (!impl)
@ -357,7 +358,7 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::top_getter)
} }
// https://html.spec.whatwg.org/multipage/browsers.html#dom-parent // https://html.spec.whatwg.org/multipage/browsers.html#dom-parent
JS_DEFINE_NATIVE_GETTER(WindowObject::parent_getter) JS_DEFINE_NATIVE_FUNCTION(WindowObject::parent_getter)
{ {
auto* impl = impl_from(vm, global_object); auto* impl = impl_from(vm, global_object);
if (!impl) if (!impl)
@ -376,7 +377,7 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::parent_getter)
return impl->wrapper(); return impl->wrapper();
} }
JS_DEFINE_NATIVE_GETTER(WindowObject::document_getter) JS_DEFINE_NATIVE_FUNCTION(WindowObject::document_getter)
{ {
auto* impl = impl_from(vm, global_object); auto* impl = impl_from(vm, global_object);
if (!impl) if (!impl)
@ -384,7 +385,7 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::document_getter)
return wrap(global_object, impl->document()); return wrap(global_object, impl->document());
} }
JS_DEFINE_NATIVE_GETTER(WindowObject::performance_getter) JS_DEFINE_NATIVE_FUNCTION(WindowObject::performance_getter)
{ {
auto* impl = impl_from(vm, global_object); auto* impl = impl_from(vm, global_object);
if (!impl) if (!impl)
@ -392,7 +393,7 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::performance_getter)
return wrap(global_object, impl->performance()); return wrap(global_object, impl->performance());
} }
JS_DEFINE_NATIVE_GETTER(WindowObject::screen_getter) JS_DEFINE_NATIVE_FUNCTION(WindowObject::screen_getter)
{ {
auto* impl = impl_from(vm, global_object); auto* impl = impl_from(vm, global_object);
if (!impl) if (!impl)
@ -400,7 +401,7 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::screen_getter)
return wrap(global_object, impl->screen()); return wrap(global_object, impl->screen());
} }
JS_DEFINE_NATIVE_GETTER(WindowObject::event_getter) JS_DEFINE_NATIVE_FUNCTION(WindowObject::event_getter)
{ {
auto* impl = impl_from(vm, global_object); auto* impl = impl_from(vm, global_object);
if (!impl) if (!impl)
@ -410,7 +411,7 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::event_getter)
return wrap(global_object, const_cast<DOM::Event&>(*impl->current_event())); return wrap(global_object, const_cast<DOM::Event&>(*impl->current_event()));
} }
JS_DEFINE_NATIVE_GETTER(WindowObject::inner_width_getter) JS_DEFINE_NATIVE_FUNCTION(WindowObject::inner_width_getter)
{ {
auto* impl = impl_from(vm, global_object); auto* impl = impl_from(vm, global_object);
if (!impl) if (!impl)
@ -418,7 +419,7 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::inner_width_getter)
return JS::Value(impl->inner_width()); return JS::Value(impl->inner_width());
} }
JS_DEFINE_NATIVE_GETTER(WindowObject::inner_height_getter) JS_DEFINE_NATIVE_FUNCTION(WindowObject::inner_height_getter)
{ {
auto* impl = impl_from(vm, global_object); auto* impl = impl_from(vm, global_object);
if (!impl) if (!impl)

View file

@ -58,19 +58,19 @@ public:
private: private:
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;
JS_DECLARE_NATIVE_GETTER(top_getter); JS_DECLARE_NATIVE_FUNCTION(top_getter);
JS_DECLARE_NATIVE_GETTER(document_getter); JS_DECLARE_NATIVE_FUNCTION(document_getter);
JS_DECLARE_NATIVE_GETTER(performance_getter); JS_DECLARE_NATIVE_FUNCTION(performance_getter);
JS_DECLARE_NATIVE_GETTER(screen_getter); JS_DECLARE_NATIVE_FUNCTION(screen_getter);
JS_DECLARE_NATIVE_GETTER(event_getter); JS_DECLARE_NATIVE_FUNCTION(event_getter);
JS_DECLARE_NATIVE_GETTER(inner_width_getter); JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
JS_DECLARE_NATIVE_GETTER(inner_height_getter); JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
JS_DECLARE_NATIVE_GETTER(parent_getter); JS_DECLARE_NATIVE_FUNCTION(parent_getter);
JS_DECLARE_NATIVE_FUNCTION(alert); JS_DECLARE_NATIVE_FUNCTION(alert);
JS_DECLARE_NATIVE_FUNCTION(confirm); JS_DECLARE_NATIVE_FUNCTION(confirm);