summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Bindings/WindowObject.cpp
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2020-05-26 21:33:37 -0700
committerAndreas Kling <kling@serenityos.org>2020-05-27 13:17:35 +0200
commitdd08c992e8d884f646bdf9e9e75b2236ad5d38c8 (patch)
tree695ac51fb004e0a41d9374c1f1646dc51dbefeaf /Libraries/LibWeb/Bindings/WindowObject.cpp
parent59a32f29b05857d7928789f0374930b8f5db4c62 (diff)
downloadserenity-dd08c992e8d884f646bdf9e9e75b2236ad5d38c8.zip
LibJS: Simplify and normalize publicly-exposed Object functions
Previously, the Object class had many different types of functions for each action. For example: get_by_index, get(PropertyName), get(FlyString). This is a bit verbose, so these methods have been shortened to simply use the PropertyName structure. The methods then internally call _by_index if necessary. Note that the _by_index have been made private to enforce this change. Secondly, a clear distinction has been made between "putting" and "defining" an object property. "Putting" should mean modifying a (potentially) already existing property. This is akin to doing "a.b = 'foo'". This implies two things about put operations: - They will search the prototype chain for setters and call them, if necessary. - If no property exists with a particular key, the put operation should create a new property with the default attributes (configurable, writable, and enumerable). In contrast, "defining" a property should completely overwrite any existing value without calling setters (if that property is configurable, of course). Thus, all of the many JS objects have had any "put" calls changed to "define_property" calls. Additionally, "put_native_function" and "put_native_property" have had their "put" replaced with "define". Finally, "put_own_property" has been made private, as all necessary functionality should be exposed with the put and define_property methods.
Diffstat (limited to 'Libraries/LibWeb/Bindings/WindowObject.cpp')
-rw-r--r--Libraries/LibWeb/Bindings/WindowObject.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/Libraries/LibWeb/Bindings/WindowObject.cpp b/Libraries/LibWeb/Bindings/WindowObject.cpp
index dc816d50ac..6c6adaa4c9 100644
--- a/Libraries/LibWeb/Bindings/WindowObject.cpp
+++ b/Libraries/LibWeb/Bindings/WindowObject.cpp
@@ -51,21 +51,21 @@ void WindowObject::initialize()
{
GlobalObject::initialize();
- put("window", this, JS::Attribute::Enumerable);
- put_native_property("document", document_getter, document_setter, JS::Attribute::Enumerable);
- put_native_function("alert", alert);
- put_native_function("confirm", confirm);
- put_native_function("setInterval", set_interval, 1);
- put_native_function("setTimeout", set_timeout, 1);
- put_native_function("requestAnimationFrame", request_animation_frame, 1);
- put_native_function("cancelAnimationFrame", cancel_animation_frame, 1);
-
- put("navigator", heap().allocate<NavigatorObject>(), JS::Attribute::Enumerable | JS::Attribute::Configurable);
- put("location", heap().allocate<LocationObject>(), JS::Attribute::Enumerable | JS::Attribute::Configurable);
+ define_property("window", this, JS::Attribute::Enumerable);
+ define_native_property("document", document_getter, document_setter, JS::Attribute::Enumerable);
+ define_native_function("alert", alert);
+ define_native_function("confirm", confirm);
+ define_native_function("setInterval", set_interval, 1);
+ define_native_function("setTimeout", set_timeout, 1);
+ define_native_function("requestAnimationFrame", request_animation_frame, 1);
+ define_native_function("cancelAnimationFrame", cancel_animation_frame, 1);
+
+ define_property("navigator", heap().allocate<NavigatorObject>(), JS::Attribute::Enumerable | JS::Attribute::Configurable);
+ define_property("location", heap().allocate<LocationObject>(), JS::Attribute::Enumerable | JS::Attribute::Configurable);
m_xhr_prototype = heap().allocate<XMLHttpRequestPrototype>();
m_xhr_constructor = heap().allocate<XMLHttpRequestConstructor>();
- m_xhr_constructor->put("prototype", m_xhr_prototype, 0);
+ m_xhr_constructor->define_property("prototype", m_xhr_prototype, 0);
add_constructor("XMLHttpRequest", m_xhr_constructor, *m_xhr_prototype);
}