mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:57:35 +00:00
LibWeb: Implement URL.canParse(url, base)
This patch adds an implementation of the URL.canParse(url, base) static function :^)
This commit is contained in:
parent
0e552f1d7a
commit
b1e43c9ea1
3 changed files with 19 additions and 0 deletions
|
@ -96,6 +96,20 @@ void URL::visit_edges(Cell::Visitor& visitor)
|
||||||
visitor.visit(m_query.ptr());
|
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
|
WebIDL::ExceptionOr<String> URL::href() const
|
||||||
{
|
{
|
||||||
auto& vm = realm().vm();
|
auto& vm = realm().vm();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||||
* Copyright (c) 2021, the SerenityOS developers.
|
* Copyright (c) 2021, the SerenityOS developers.
|
||||||
|
* Copyright (c) 2023, networkException <networkexception@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -23,6 +24,8 @@ public:
|
||||||
|
|
||||||
virtual ~URL() override;
|
virtual ~URL() override;
|
||||||
|
|
||||||
|
static bool can_parse(JS::VM&, String const& url, Optional<String> const& base = {});
|
||||||
|
|
||||||
WebIDL::ExceptionOr<String> href() const;
|
WebIDL::ExceptionOr<String> href() const;
|
||||||
WebIDL::ExceptionOr<void> set_href(String const&);
|
WebIDL::ExceptionOr<void> set_href(String const&);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
interface URL {
|
interface URL {
|
||||||
constructor(USVString url, optional USVString base);
|
constructor(USVString url, optional USVString base);
|
||||||
|
|
||||||
|
static boolean canParse(USVString url, optional USVString base);
|
||||||
|
|
||||||
stringifier attribute USVString href;
|
stringifier attribute USVString href;
|
||||||
readonly attribute USVString origin;
|
readonly attribute USVString origin;
|
||||||
attribute USVString protocol;
|
attribute USVString protocol;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue