mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 17:18:11 +00:00
LibWeb: Port WorkerLocation to new String
This commit is contained in:
parent
511ce240f2
commit
9c5bdb0b86
3 changed files with 48 additions and 34 deletions
|
@ -11,109 +11,123 @@
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-href
|
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-href
|
||||||
DeprecatedString WorkerLocation::href() const
|
WebIDL::ExceptionOr<String> WorkerLocation::href() const
|
||||||
{
|
{
|
||||||
|
auto& vm = realm().vm();
|
||||||
// The href getter steps are to return this's WorkerGlobalScope object's url, serialized.
|
// The href getter steps are to return this's WorkerGlobalScope object's url, serialized.
|
||||||
return m_global_scope.url().serialize();
|
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_global_scope.url().serialize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-origin
|
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-origin
|
||||||
DeprecatedString WorkerLocation::origin() const
|
WebIDL::ExceptionOr<String> WorkerLocation::origin() const
|
||||||
{
|
{
|
||||||
|
auto& vm = realm().vm();
|
||||||
// The origin getter steps are to return the serialization of this's WorkerGlobalScope object's url's origin.
|
// The origin getter steps are to return the serialization of this's WorkerGlobalScope object's url's origin.
|
||||||
return m_global_scope.url().serialize_origin();
|
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_global_scope.url().serialize_origin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-protocol
|
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-protocol
|
||||||
DeprecatedString WorkerLocation::protocol() const
|
WebIDL::ExceptionOr<String> WorkerLocation::protocol() const
|
||||||
{
|
{
|
||||||
|
auto& vm = realm().vm();
|
||||||
// The protocol getter steps are to return this's WorkerGlobalScope object's url's scheme, followed by ":".
|
// The protocol getter steps are to return this's WorkerGlobalScope object's url's scheme, followed by ":".
|
||||||
return DeprecatedString::formatted("{}:", m_global_scope.url().scheme());
|
return TRY_OR_THROW_OOM(vm, String::formatted("{}:", m_global_scope.url().scheme().view()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-host
|
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-host
|
||||||
DeprecatedString WorkerLocation::host() const
|
WebIDL::ExceptionOr<String> WorkerLocation::host() const
|
||||||
{
|
{
|
||||||
|
auto& vm = realm().vm();
|
||||||
|
|
||||||
// The host getter steps are:
|
// The host getter steps are:
|
||||||
// 1. Let url be this's WorkerGlobalScope object's url.
|
// 1. Let url be this's WorkerGlobalScope object's url.
|
||||||
auto const& url = m_global_scope.url();
|
auto const& url = m_global_scope.url();
|
||||||
|
|
||||||
// 2. If url's host is null, return the empty string.
|
// 2. If url's host is null, return the empty string.
|
||||||
if (url.host().is_empty())
|
if (url.host().is_empty())
|
||||||
return "";
|
return String {};
|
||||||
|
|
||||||
// 3. If url's port is null, return url's host, serialized.
|
// 3. If url's port is null, return url's host, serialized.
|
||||||
if (!url.port().has_value())
|
if (!url.port().has_value())
|
||||||
return url.host();
|
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(url.host()));
|
||||||
|
|
||||||
// 4. Return url's host, serialized, followed by ":" and url's port, serialized.
|
// 4. Return url's host, serialized, followed by ":" and url's port, serialized.
|
||||||
return DeprecatedString::formatted("{}:{}", url.host(), url.port().value());
|
return TRY_OR_THROW_OOM(vm, String::formatted("{}:{}", url.host().view(), url.port().value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-hostname
|
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-hostname
|
||||||
DeprecatedString WorkerLocation::hostname() const
|
WebIDL::ExceptionOr<String> WorkerLocation::hostname() const
|
||||||
{
|
{
|
||||||
|
auto& vm = realm().vm();
|
||||||
|
|
||||||
// The hostname getter steps are:
|
// The hostname getter steps are:
|
||||||
// 1. Let host be this's WorkerGlobalScope object's url's host.
|
// 1. Let host be this's WorkerGlobalScope object's url's host.
|
||||||
auto const& host = m_global_scope.url().host();
|
auto const& host = m_global_scope.url().host();
|
||||||
|
|
||||||
// 2. If host is null, return the empty string.
|
// 2. If host is null, return the empty string.
|
||||||
if (host.is_empty())
|
if (host.is_empty())
|
||||||
return "";
|
return String {};
|
||||||
|
|
||||||
// 3. Return host, serialized.
|
// 3. Return host, serialized.
|
||||||
return host;
|
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(host));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-port
|
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-port
|
||||||
DeprecatedString WorkerLocation::port() const
|
WebIDL::ExceptionOr<String> WorkerLocation::port() const
|
||||||
{
|
{
|
||||||
|
auto& vm = realm().vm();
|
||||||
|
|
||||||
// The port getter steps are:
|
// The port getter steps are:
|
||||||
// 1. Let port be this's WorkerGlobalScope object's url's port.
|
// 1. Let port be this's WorkerGlobalScope object's url's port.
|
||||||
auto const& port = m_global_scope.url().port();
|
auto const& port = m_global_scope.url().port();
|
||||||
|
|
||||||
// 2. If port is null, return the empty string.
|
// 2. If port is null, return the empty string.
|
||||||
if (!port.has_value())
|
if (!port.has_value())
|
||||||
return "";
|
return String {};
|
||||||
// 3. Return port, serialized.
|
// 3. Return port, serialized.
|
||||||
return DeprecatedString::number(port.value());
|
return TRY_OR_THROW_OOM(vm, String::number(port.value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-pathname
|
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-pathname
|
||||||
DeprecatedString WorkerLocation::pathname() const
|
WebIDL::ExceptionOr<String> WorkerLocation::pathname() const
|
||||||
{
|
{
|
||||||
|
auto& vm = realm().vm();
|
||||||
// The pathname getter steps are to return the result of URL path serializing this's WorkerGlobalScope object's url.
|
// The pathname getter steps are to return the result of URL path serializing this's WorkerGlobalScope object's url.
|
||||||
return m_global_scope.url().path();
|
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_global_scope.url().path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-search
|
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-search
|
||||||
DeprecatedString WorkerLocation::search() const
|
WebIDL::ExceptionOr<String> WorkerLocation::search() const
|
||||||
{
|
{
|
||||||
|
auto& vm = realm().vm();
|
||||||
|
|
||||||
// The search getter steps are:
|
// The search getter steps are:
|
||||||
// 1. Let query be this's WorkerGlobalScope object's url's query.
|
// 1. Let query be this's WorkerGlobalScope object's url's query.
|
||||||
auto const& query = m_global_scope.url().query();
|
auto const& query = m_global_scope.url().query();
|
||||||
|
|
||||||
// 2. If query is either null or the empty string, return the empty string.
|
// 2. If query is either null or the empty string, return the empty string.
|
||||||
if (query.is_empty())
|
if (query.is_empty())
|
||||||
return "";
|
return String {};
|
||||||
|
|
||||||
// 3. Return "?", followed by query.
|
// 3. Return "?", followed by query.
|
||||||
return DeprecatedString::formatted("?{}", query);
|
return TRY_OR_THROW_OOM(vm, String::formatted("?{}", query.view()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-hash
|
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-hash
|
||||||
DeprecatedString WorkerLocation::hash() const
|
WebIDL::ExceptionOr<String> WorkerLocation::hash() const
|
||||||
{
|
{
|
||||||
|
auto& vm = realm().vm();
|
||||||
|
|
||||||
// The hash getter steps are:
|
// The hash getter steps are:
|
||||||
// 1. Let fragment be this's WorkerGlobalScope object's url's fragment.
|
// 1. Let fragment be this's WorkerGlobalScope object's url's fragment.
|
||||||
auto const& fragment = m_global_scope.url().fragment();
|
auto const& fragment = m_global_scope.url().fragment();
|
||||||
|
|
||||||
// 2. If fragment is either null or the empty string, return the empty string.
|
// 2. If fragment is either null or the empty string, return the empty string.
|
||||||
if (fragment.is_empty())
|
if (fragment.is_empty())
|
||||||
return "";
|
return String {};
|
||||||
|
|
||||||
// 3. Return "#", followed by fragment.
|
// 3. Return "#", followed by fragment.
|
||||||
return DeprecatedString::formatted("#{}", fragment);
|
return TRY_OR_THROW_OOM(vm, String::formatted("#{}", fragment.view()));
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkerLocation::WorkerLocation(WorkerGlobalScope& global_scope)
|
WorkerLocation::WorkerLocation(WorkerGlobalScope& global_scope)
|
||||||
|
|
|
@ -17,15 +17,15 @@ class WorkerLocation : public Bindings::PlatformObject {
|
||||||
public:
|
public:
|
||||||
virtual ~WorkerLocation() override;
|
virtual ~WorkerLocation() override;
|
||||||
|
|
||||||
DeprecatedString href() const;
|
WebIDL::ExceptionOr<String> href() const;
|
||||||
DeprecatedString origin() const;
|
WebIDL::ExceptionOr<String> origin() const;
|
||||||
DeprecatedString protocol() const;
|
WebIDL::ExceptionOr<String> protocol() const;
|
||||||
DeprecatedString host() const;
|
WebIDL::ExceptionOr<String> host() const;
|
||||||
DeprecatedString hostname() const;
|
WebIDL::ExceptionOr<String> hostname() const;
|
||||||
DeprecatedString port() const;
|
WebIDL::ExceptionOr<String> port() const;
|
||||||
DeprecatedString pathname() const;
|
WebIDL::ExceptionOr<String> pathname() const;
|
||||||
DeprecatedString search() const;
|
WebIDL::ExceptionOr<String> search() const;
|
||||||
DeprecatedString hash() const;
|
WebIDL::ExceptionOr<String> hash() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit WorkerLocation(WorkerGlobalScope&);
|
explicit WorkerLocation(WorkerGlobalScope&);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[Exposed=Worker]
|
[Exposed=Worker, UseNewAKString]
|
||||||
interface WorkerLocation {
|
interface WorkerLocation {
|
||||||
stringifier readonly attribute USVString href;
|
stringifier readonly attribute USVString href;
|
||||||
readonly attribute USVString origin;
|
readonly attribute USVString origin;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue