diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-07-05 15:01:57 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-07-05 14:40:49 +0100 |
commit | 6468a2bf214742e13dc1c3419f8a39995770ee5d (patch) | |
tree | 28c59f112f490c7b764ffa0f98374daca0aa086c /Userland/Libraries/LibWeb | |
parent | 073071c634ab27ab3c2ec16237d4e1fd018f662e (diff) | |
download | serenity-6468a2bf214742e13dc1c3419f8a39995770ee5d.zip |
LibWeb: Replace usage of native properties with accessors in Location
This is required by the WebIDL specification.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/LocationObject.cpp | 37 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/LocationObject.h | 18 |
2 files changed, 28 insertions, 27 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index f42b2548fb..227a6aebee 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -23,13 +23,13 @@ void LocationObject::initialize(JS::GlobalObject& global_object) { Object::initialize(global_object); u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable; - define_native_property("href", href_getter, href_setter, attr); - define_native_property("host", host_getter, nullptr, attr); - define_native_property("hostname", hostname_getter, nullptr, attr); - define_native_property("pathname", pathname_getter, nullptr, attr); - define_native_property("hash", hash_getter, nullptr, attr); - define_native_property("search", search_getter, nullptr, attr); - define_native_property("protocol", protocol_getter, nullptr, attr); + define_native_accessor("href", href_getter, href_setter, attr); + define_native_accessor("host", host_getter, {}, attr); + define_native_accessor("hostname", hostname_getter, {}, attr); + define_native_accessor("pathname", pathname_getter, {}, attr); + define_native_accessor("hash", hash_getter, {}, attr); + define_native_accessor("search", search_getter, {}, attr); + define_native_accessor("protocol", protocol_getter, {}, attr); define_native_function("reload", reload, 0, JS::Attribute::Enumerable); } @@ -38,46 +38,47 @@ LocationObject::~LocationObject() { } -JS_DEFINE_NATIVE_GETTER(LocationObject::href_getter) +JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter) { auto& window = static_cast<WindowObject&>(global_object); return JS::js_string(vm, window.impl().document().url().to_string()); } -JS_DEFINE_NATIVE_SETTER(LocationObject::href_setter) +JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter) { auto& window = static_cast<WindowObject&>(global_object); - auto new_href = value.to_string(global_object); + auto new_href = vm.argument(0).to_string(global_object); if (vm.exception()) - return; + return {}; auto href_url = window.impl().document().complete_url(new_href); if (!href_url.is_valid()) { vm.throw_exception<JS::URIError>(global_object, String::formatted("Invalid URL '{}'", new_href)); - return; + return {}; } window.impl().did_set_location_href({}, href_url); + return JS::js_undefined(); } -JS_DEFINE_NATIVE_GETTER(LocationObject::pathname_getter) +JS_DEFINE_NATIVE_FUNCTION(LocationObject::pathname_getter) { auto& window = static_cast<WindowObject&>(global_object); return JS::js_string(vm, window.impl().document().url().path()); } -JS_DEFINE_NATIVE_GETTER(LocationObject::hostname_getter) +JS_DEFINE_NATIVE_FUNCTION(LocationObject::hostname_getter) { auto& window = static_cast<WindowObject&>(global_object); return JS::js_string(vm, window.impl().document().url().host()); } -JS_DEFINE_NATIVE_GETTER(LocationObject::host_getter) +JS_DEFINE_NATIVE_FUNCTION(LocationObject::host_getter) { auto& window = static_cast<WindowObject&>(global_object); auto url = window.impl().document().url(); return JS::js_string(vm, String::formatted("{}:{}", url.host(), url.port())); } -JS_DEFINE_NATIVE_GETTER(LocationObject::hash_getter) +JS_DEFINE_NATIVE_FUNCTION(LocationObject::hash_getter) { auto& window = static_cast<WindowObject&>(global_object); auto fragment = window.impl().document().url().fragment(); @@ -89,7 +90,7 @@ JS_DEFINE_NATIVE_GETTER(LocationObject::hash_getter) return JS::js_string(vm, builder.to_string()); } -JS_DEFINE_NATIVE_GETTER(LocationObject::search_getter) +JS_DEFINE_NATIVE_FUNCTION(LocationObject::search_getter) { auto& window = static_cast<WindowObject&>(global_object); auto query = window.impl().document().url().query(); @@ -101,7 +102,7 @@ JS_DEFINE_NATIVE_GETTER(LocationObject::search_getter) return JS::js_string(vm, builder.to_string()); } -JS_DEFINE_NATIVE_GETTER(LocationObject::protocol_getter) +JS_DEFINE_NATIVE_FUNCTION(LocationObject::protocol_getter) { auto& window = static_cast<WindowObject&>(global_object); StringBuilder builder; diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.h b/Userland/Libraries/LibWeb/Bindings/LocationObject.h index 10b9e947be..282104f888 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.h +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.h @@ -23,15 +23,15 @@ public: private: JS_DECLARE_NATIVE_FUNCTION(reload); - JS_DECLARE_NATIVE_GETTER(href_getter); - JS_DECLARE_NATIVE_SETTER(href_setter); - - JS_DECLARE_NATIVE_GETTER(host_getter); - JS_DECLARE_NATIVE_GETTER(hostname_getter); - JS_DECLARE_NATIVE_GETTER(pathname_getter); - JS_DECLARE_NATIVE_GETTER(hash_getter); - JS_DECLARE_NATIVE_GETTER(search_getter); - JS_DECLARE_NATIVE_GETTER(protocol_getter); + JS_DECLARE_NATIVE_FUNCTION(href_getter); + JS_DECLARE_NATIVE_FUNCTION(href_setter); + + JS_DECLARE_NATIVE_FUNCTION(host_getter); + JS_DECLARE_NATIVE_FUNCTION(hostname_getter); + JS_DECLARE_NATIVE_FUNCTION(pathname_getter); + JS_DECLARE_NATIVE_FUNCTION(hash_getter); + JS_DECLARE_NATIVE_FUNCTION(search_getter); + JS_DECLARE_NATIVE_FUNCTION(protocol_getter); }; } |