summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-18 21:44:45 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-18 21:48:44 +0200
commit74b88a8156a0ab10fc9523c3f5871e1185f10728 (patch)
tree34ebf44839d048fb2cf58af11708f9ec3dadb483 /Userland
parent407cf048840e2d241796c7dbb1d2412648df102d (diff)
downloadserenity-74b88a8156a0ab10fc9523c3f5871e1185f10728.zip
LibWeb: Implement window.location.port
This returns the port of the current document's URL. :^)
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/LocationObject.cpp7
-rw-r--r--Userland/Libraries/LibWeb/Bindings/LocationObject.h1
2 files changed, 8 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp
index a31e1e56e2..0702ad4ce1 100644
--- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp
@@ -29,6 +29,7 @@ void LocationObject::initialize(JS::GlobalObject& global_object)
define_native_accessor("hash", hash_getter, {}, attr);
define_native_accessor("search", search_getter, {}, attr);
define_native_accessor("protocol", protocol_getter, {}, attr);
+ define_native_accessor("port", port_getter, {}, attr);
define_native_function("reload", reload, 0, JS::Attribute::Enumerable);
}
@@ -110,6 +111,12 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::protocol_getter)
return JS::js_string(vm, builder.to_string());
}
+JS_DEFINE_NATIVE_FUNCTION(LocationObject::port_getter)
+{
+ auto& window = static_cast<WindowObject&>(global_object);
+ return JS::Value(window.impl().associated_document().url().port_or_default());
+}
+
JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload)
{
auto& window = static_cast<WindowObject&>(global_object);
diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.h b/Userland/Libraries/LibWeb/Bindings/LocationObject.h
index df01f699e5..d1e3ea5212 100644
--- a/Userland/Libraries/LibWeb/Bindings/LocationObject.h
+++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.h
@@ -39,6 +39,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(hash_getter);
JS_DECLARE_NATIVE_FUNCTION(search_getter);
JS_DECLARE_NATIVE_FUNCTION(protocol_getter);
+ JS_DECLARE_NATIVE_FUNCTION(port_getter);
};
}