diff options
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Location.cpp | 23 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Location.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Location.idl | 2 |
3 files changed, 25 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Location.cpp b/Userland/Libraries/LibWeb/HTML/Location.cpp index 21223b1c61..afcd037982 100644 --- a/Userland/Libraries/LibWeb/HTML/Location.cpp +++ b/Userland/Libraries/LibWeb/HTML/Location.cpp @@ -340,6 +340,29 @@ void Location::replace(String const& url) const window.did_call_location_replace({}, url.to_deprecated_string()); } +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-assign +WebIDL::ExceptionOr<void> Location::assign(String const& url) const +{ + // 1. If this's relevant Document is null, then return. + auto const relevant_document = this->relevant_document(); + if (!relevant_document) + return {}; + + // 2. If this's relevant Document's origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException. + if (!relevant_document->origin().is_same_origin_domain(entry_settings_object().origin())) + return WebIDL::SecurityError::create(realm(), "Location's relevant document is not same origin-domain with the entry settings object's origin"sv); + + // 3. Parse url relative to the entry settings object. If that failed, throw a "SyntaxError" DOMException. + auto assign_url = entry_settings_object().parse_url(url); + if (!assign_url.is_valid()) + return WebIDL::SyntaxError::create(realm(), DeprecatedString::formatted("Invalid URL '{}'", url)); + + // 4. Location-object navigate this to the resulting URL record. + auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); + window.did_set_location_href({}, assign_url); + return {}; +} + // 7.10.5.1 [[GetPrototypeOf]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-getprototypeof JS::ThrowCompletionOr<JS::Object*> Location::internal_get_prototype_of() const { diff --git a/Userland/Libraries/LibWeb/HTML/Location.h b/Userland/Libraries/LibWeb/HTML/Location.h index 5ea4493e8b..e154137562 100644 --- a/Userland/Libraries/LibWeb/HTML/Location.h +++ b/Userland/Libraries/LibWeb/HTML/Location.h @@ -50,6 +50,7 @@ public: void replace(String const& url) const; void reload() const; + WebIDL::ExceptionOr<void> assign(String const& url) const; virtual JS::ThrowCompletionOr<JS::Object*> internal_get_prototype_of() const override; virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override; diff --git a/Userland/Libraries/LibWeb/HTML/Location.idl b/Userland/Libraries/LibWeb/HTML/Location.idl index 60b9f0e3af..752ff5f18a 100644 --- a/Userland/Libraries/LibWeb/HTML/Location.idl +++ b/Userland/Libraries/LibWeb/HTML/Location.idl @@ -11,7 +11,7 @@ interface Location { // but see also additional creation steps and overridden in [LegacyUnforgeable] attribute USVString search; [LegacyUnforgeable] attribute USVString hash; - // TODO: [LegacyUnforgeable] undefined assign(USVString url); + [LegacyUnforgeable] undefined assign(USVString url); [LegacyUnforgeable] undefined replace(USVString url); [LegacyUnforgeable] undefined reload(); |