summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authornetworkException <git@nwex.de>2023-04-11 14:57:34 +0200
committerLinus Groh <mail@linusgroh.de>2023-04-11 16:28:20 +0200
commitb1e43c9ea1a2dde97a2e0fdd02895337bcc55a7e (patch)
tree4275cb32033c5b9d4ab9e77431f920f955b19658 /Userland/Libraries/LibWeb
parent0e552f1d7a4832dcf755b05f2a3757e7de68d977 (diff)
downloadserenity-b1e43c9ea1a2dde97a2e0fdd02895337bcc55a7e.zip
LibWeb: Implement URL.canParse(url, base)
This patch adds an implementation of the URL.canParse(url, base) static function :^)
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/URL/URL.cpp14
-rw-r--r--Userland/Libraries/LibWeb/URL/URL.h3
-rw-r--r--Userland/Libraries/LibWeb/URL/URL.idl2
3 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/URL/URL.cpp b/Userland/Libraries/LibWeb/URL/URL.cpp
index 14ff13894d..8771b9534f 100644
--- a/Userland/Libraries/LibWeb/URL/URL.cpp
+++ b/Userland/Libraries/LibWeb/URL/URL.cpp
@@ -96,6 +96,20 @@ void URL::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_query.ptr());
}
+// https://url.spec.whatwg.org/#dom-url-canparse
+bool URL::can_parse(JS::VM&, String const& url, Optional<String> const& base)
+{
+ // 1. Let parsedURL be the result of running the API URL parser on url with base, if given.
+ auto parsed_url = parse_api_url(url, base);
+
+ // 2. If parsedURL is failure, then return false.
+ if (!parsed_url.has_value())
+ return false;
+
+ // 3. Return true.
+ return true;
+}
+
WebIDL::ExceptionOr<String> URL::href() const
{
auto& vm = realm().vm();
diff --git a/Userland/Libraries/LibWeb/URL/URL.h b/Userland/Libraries/LibWeb/URL/URL.h
index 449d55ff86..f723308eb2 100644
--- a/Userland/Libraries/LibWeb/URL/URL.h
+++ b/Userland/Libraries/LibWeb/URL/URL.h
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021, the SerenityOS developers.
+ * Copyright (c) 2023, networkException <networkexception@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -23,6 +24,8 @@ public:
virtual ~URL() override;
+ static bool can_parse(JS::VM&, String const& url, Optional<String> const& base = {});
+
WebIDL::ExceptionOr<String> href() const;
WebIDL::ExceptionOr<void> set_href(String const&);
diff --git a/Userland/Libraries/LibWeb/URL/URL.idl b/Userland/Libraries/LibWeb/URL/URL.idl
index d149a998e9..702e551c1a 100644
--- a/Userland/Libraries/LibWeb/URL/URL.idl
+++ b/Userland/Libraries/LibWeb/URL/URL.idl
@@ -5,6 +5,8 @@
interface URL {
constructor(USVString url, optional USVString base);
+ static boolean canParse(USVString url, optional USVString base);
+
stringifier attribute USVString href;
readonly attribute USVString origin;
attribute USVString protocol;