2020-05-18 21:42:40 +02:00
/*
2024-10-04 13:19:50 +02:00
* Copyright ( c ) 2020 - 2023 , Andreas Kling < andreas @ ladybird . org >
2023-01-18 17:41:12 +00:00
* Copyright ( c ) 2022 - 2023 , Linus Groh < linusg @ serenityos . org >
2025-04-22 13:50:18 +12:00
* Copyright ( c ) 2025 , Shannon Booth < shannon @ serenityos . org >
2020-05-18 21:42:40 +02:00
*
2021-04-22 01:24:48 -07:00
* SPDX - License - Identifier : BSD - 2 - Clause
2020-05-18 21:42:40 +02:00
*/
2023-03-04 22:16:07 +00:00
# include <AK/String.h>
2020-05-18 21:59:16 +02:00
# include <AK/StringBuilder.h>
2024-12-26 14:32:52 +01:00
# include <LibGC/RootVector.h>
2021-09-28 23:54:42 +01:00
# include <LibJS/Runtime/Completion.h>
2022-03-06 00:24:18 +01:00
# include <LibJS/Runtime/PropertyDescriptor.h>
# include <LibJS/Runtime/PropertyKey.h>
2024-03-18 16:22:27 +13:00
# include <LibURL/Parser.h>
2022-04-05 17:54:04 -03:00
# include <LibWeb/Bindings/LocationPrototype.h>
2020-05-18 21:42:40 +02:00
# include <LibWeb/DOM/Document.h>
2022-09-24 14:02:47 +01:00
# include <LibWeb/HTML/CrossOrigin/AbstractOperations.h>
2023-01-18 17:41:12 +00:00
# include <LibWeb/HTML/Location.h>
2023-08-28 18:06:10 +02:00
# include <LibWeb/HTML/Navigation.h>
2022-03-07 23:08:26 +01:00
# include <LibWeb/HTML/Window.h>
2022-09-25 17:28:46 +01:00
# include <LibWeb/WebIDL/DOMException.h>
2020-05-18 21:42:40 +02:00
2023-01-18 17:41:12 +00:00
namespace Web : : HTML {
2020-05-18 21:42:40 +02:00
2024-11-15 04:01:23 +13:00
GC_DEFINE_ALLOCATOR ( Location ) ;
2023-11-19 19:47:52 +01:00
2022-03-04 23:35:34 +01:00
// https://html.spec.whatwg.org/multipage/history.html#the-location-interface
2023-01-18 17:41:12 +00:00
Location : : Location ( JS : : Realm & realm )
2023-11-09 07:29:52 +00:00
: PlatformObject ( realm , MayInterfereWithIndexedPropertyAccess : : Yes )
2020-06-20 17:28:13 +02:00
{
2022-09-04 16:55:50 +02:00
}
2023-01-18 17:41:12 +00:00
Location : : ~ Location ( ) = default ;
2022-09-04 16:55:50 +02:00
2023-01-18 17:41:12 +00:00
void Location : : visit_edges ( Cell : : Visitor & visitor )
2022-09-04 16:55:50 +02:00
{
Base : : visit_edges ( visitor ) ;
2025-05-16 04:14:12 +01:00
visitor . visit ( m_default_properties ) ;
2020-06-20 17:28:13 +02:00
}
2024-12-01 02:56:22 +04:00
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-location-interface
2023-08-07 08:41:28 +02:00
void Location : : initialize ( JS : : Realm & realm )
2020-05-18 21:42:40 +02:00
{
2024-03-16 13:13:08 +01:00
WEB_SET_PROTOTYPE_FOR_INTERFACE ( Location ) ;
2025-04-20 16:22:57 +02:00
Base : : initialize ( realm ) ;
2024-12-09 17:04:20 +00:00
Bindings : : LocationPrototype : : define_unforgeable_attributes ( realm , * this ) ;
2022-08-22 21:47:35 +01:00
2024-12-01 02:56:22 +04:00
auto & vm = this - > vm ( ) ;
2025-04-22 13:49:35 +12:00
// 2. Let valueOf be location's relevant realm.[[Intrinsics]].[[%Object.prototype.valueOf%]].
2024-12-01 02:56:22 +04:00
auto & intrinsics = realm . intrinsics ( ) ;
auto value_of_function = intrinsics . object_prototype ( ) - > get_without_side_effects ( vm . names . valueOf ) ;
2025-04-22 13:49:35 +12:00
// 3. Perform ! location.[[DefineOwnProperty]]("valueOf", { [[Value]]: valueOf, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
2024-12-01 02:56:22 +04:00
auto value_of_property_descriptor = JS : : PropertyDescriptor {
. value = value_of_function ,
. writable = false ,
. enumerable = false ,
. configurable = false ,
} ;
MUST ( internal_define_own_property ( vm . names . valueOf , value_of_property_descriptor ) ) ;
2025-04-22 13:49:35 +12:00
// 4. Perform ! location.[[DefineOwnProperty]](%Symbol.toPrimitive%, { [[Value]]: undefined, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
2024-12-01 02:56:22 +04:00
auto to_primitive_property_descriptor = JS : : PropertyDescriptor {
. value = JS : : js_undefined ( ) ,
. writable = false ,
. enumerable = false ,
. configurable = false ,
} ;
MUST ( internal_define_own_property ( vm . well_known_symbol_to_primitive ( ) , to_primitive_property_descriptor ) ) ;
2022-03-06 00:24:18 +01:00
// 5. Set the value of the [[DefaultProperties]] internal slot of location to location.[[OwnPropertyKeys]]().
// NOTE: In LibWeb this happens before the ESO is set up, so we must avoid location's custom [[OwnPropertyKeys]].
m_default_properties . extend ( MUST ( Object : : internal_own_property_keys ( ) ) ) ;
2020-05-18 21:42:40 +02:00
}
2022-03-05 00:15:36 +01:00
// https://html.spec.whatwg.org/multipage/history.html#relevant-document
2024-11-15 04:01:23 +13:00
GC : : Ptr < DOM : : Document > Location : : relevant_document ( ) const
2022-03-05 00:15:36 +01:00
{
// A Location object has an associated relevant Document, which is this Location object's
// relevant global object's browsing context's active document, if this Location object's
// relevant global object's browsing context is non-null, and null otherwise.
2025-01-21 09:12:05 -05:00
auto * browsing_context = as < HTML : : Window > ( HTML : : relevant_global_object ( * this ) ) . browsing_context ( ) ;
2022-03-05 00:15:36 +01:00
return browsing_context ? browsing_context - > active_document ( ) : nullptr ;
}
2023-08-22 18:12:10 +02:00
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#location-object-navigate
2024-03-28 12:58:43 +01:00
WebIDL : : ExceptionOr < void > Location : : navigate ( URL : : URL url , Bindings : : NavigationHistoryBehavior history_handling )
2023-08-22 18:12:10 +02:00
{
// 1. Let navigable be location's relevant global object's navigable.
2025-01-21 09:12:05 -05:00
auto navigable = as < HTML : : Window > ( HTML : : relevant_global_object ( * this ) ) . navigable ( ) ;
2023-08-22 18:12:10 +02:00
// 2. Let sourceDocument be the incumbent global object's associated Document.
2025-01-21 09:12:05 -05:00
auto & source_document = as < HTML : : Window > ( incumbent_global_object ( ) ) . associated_document ( ) ;
2023-08-22 18:12:10 +02:00
// 3. If location's relevant Document is not yet completely loaded, and the incumbent global object does not have transient activation, then set historyHandling to "replace".
2025-01-21 09:12:05 -05:00
if ( ! relevant_document ( ) - > is_completely_loaded ( ) & & ! as < HTML : : Window > ( incumbent_global_object ( ) ) . has_transient_activation ( ) ) {
2024-03-28 12:58:43 +01:00
history_handling = Bindings : : NavigationHistoryBehavior : : Replace ;
2023-08-22 18:12:10 +02:00
}
// 4. Navigate navigable to url using sourceDocument, with exceptionsEnabled set to true and historyHandling set to historyHandling.
2025-04-22 13:50:18 +12:00
TRY ( navigable - > navigate ( { . url = move ( url ) ,
2023-10-10 16:05:38 +02:00
. source_document = source_document ,
. exceptions_enabled = true ,
2024-03-28 12:58:43 +01:00
. history_handling = history_handling } ) ) ;
2023-08-22 18:12:10 +02:00
return { } ;
}
2022-03-05 00:17:47 +01:00
// https://html.spec.whatwg.org/multipage/history.html#concept-location-url
2024-03-18 16:22:27 +13:00
URL : : URL Location : : url ( ) const
2022-03-05 00:17:47 +01:00
{
// A Location object has an associated url, which is this Location object's relevant Document's URL,
// if this Location object's relevant Document is non-null, and about:blank otherwise.
2023-03-04 22:37:12 +00:00
auto const relevant_document = this - > relevant_document ( ) ;
2025-02-15 23:51:45 +13:00
return relevant_document ? relevant_document - > url ( ) : URL : : about_blank ( ) ;
2022-03-05 00:17:47 +01:00
}
2022-03-04 23:35:34 +01:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-href
2023-03-04 22:16:07 +00:00
WebIDL : : ExceptionOr < String > Location : : href ( ) const
2020-05-18 21:42:40 +02:00
{
2023-03-04 22:37:12 +00:00
// 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
auto const relevant_document = this - > relevant_document ( ) ;
if ( relevant_document & & ! relevant_document - > origin ( ) . is_same_origin_domain ( entry_settings_object ( ) . origin ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2022-03-04 23:35:34 +01:00
// 2. Return this's url, serialized.
2024-12-03 22:31:33 +13:00
return url ( ) . serialize ( ) ;
2020-05-18 21:42:40 +02:00
}
2022-03-04 23:35:34 +01:00
// https://html.spec.whatwg.org/multipage/history.html#the-location-interface:dom-location-href-2
2023-03-04 22:19:14 +00:00
WebIDL : : ExceptionOr < void > Location : : set_href ( String const & new_href )
2020-05-18 21:42:40 +02:00
{
2024-10-06 09:29:49 +13:00
auto & realm = this - > realm ( ) ;
2022-03-04 23:35:34 +01:00
2023-03-04 22:37:12 +00:00
// 1. If this's relevant Document is null, then return.
auto const relevant_document = this - > relevant_document ( ) ;
if ( ! relevant_document )
return { } ;
2022-03-04 23:35:34 +01:00
2024-12-06 16:24:08 -05:00
// 2. Let url be the result of encoding-parsing a URL given the given value, relative to the entry settings object.
auto url = entry_settings_object ( ) . encoding_parse_url ( new_href . to_byte_string ( ) ) ;
2024-10-06 09:29:49 +13:00
// 3. If url is failure, then throw a "SyntaxError" DOMException.
2025-02-16 14:01:09 +13:00
if ( ! url . has_value ( ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SyntaxError : : create ( realm , Utf16String : : formatted ( " Invalid URL '{}' " , new_href ) ) ;
2022-03-04 23:35:34 +01:00
2024-10-06 09:29:49 +13:00
// 4. Location-object navigate this to url.
2025-02-16 14:01:09 +13:00
TRY ( navigate ( url . release_value ( ) ) ) ;
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
return { } ;
2020-05-18 21:42:40 +02:00
}
2023-01-18 17:41:12 +00:00
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-origin
2023-03-04 22:16:07 +00:00
WebIDL : : ExceptionOr < String > Location : : origin ( ) const
2020-05-18 21:42:40 +02:00
{
2023-03-04 22:37:12 +00:00
// 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
auto const relevant_document = this - > relevant_document ( ) ;
if ( relevant_document & & ! relevant_document - > origin ( ) . is_same_origin_domain ( entry_settings_object ( ) . origin ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
// 2. Return the serialization of this's url's origin.
2024-11-23 20:10:34 +13:00
return url ( ) . origin ( ) . serialize ( ) ;
2020-05-18 21:42:40 +02:00
}
2023-01-18 17:41:12 +00:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-protocol
2023-03-04 22:16:07 +00:00
WebIDL : : ExceptionOr < String > Location : : protocol ( ) const
2020-05-18 21:42:40 +02:00
{
2023-03-04 22:16:07 +00:00
auto & vm = this - > vm ( ) ;
2023-03-04 22:37:12 +00:00
// 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
auto const relevant_document = this - > relevant_document ( ) ;
if ( relevant_document & & ! relevant_document - > origin ( ) . is_same_origin_domain ( entry_settings_object ( ) . origin ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
// 2. Return this's url's scheme, followed by ":".
2023-03-04 22:16:07 +00:00
return TRY_OR_THROW_OOM ( vm , String : : formatted ( " {}: " , url ( ) . scheme ( ) ) ) ;
2023-01-18 17:41:12 +00:00
}
2022-03-05 00:22:48 +01:00
2024-08-16 22:00:29 +01:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-protocol
WebIDL : : ExceptionOr < void > Location : : set_protocol ( String const & value )
2023-01-18 17:41:12 +00:00
{
2024-08-16 22:00:29 +01:00
auto relevant_document = this - > relevant_document ( ) ;
// 1. If this's relevant Document is null, then return.
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 ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2024-08-16 22:00:29 +01:00
// 3. Let copyURL be a copy of this's url.
auto copy_url = this - > url ( ) ;
// 4. Let possibleFailure be the result of basic URL parsing the given value, followed by ":", with copyURL as url and scheme start state as state override.
2025-04-25 21:46:49 +12:00
auto possible_failure = URL : : Parser : : basic_parse ( MUST ( String : : formatted ( " {}: " , value ) ) , { } , & copy_url , URL : : Parser : : State : : SchemeStart ) ;
2024-08-16 22:00:29 +01:00
// 5. If possibleFailure is failure, then throw a "SyntaxError" DOMException.
2025-01-10 04:50:34 +13:00
if ( ! possible_failure . has_value ( ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SyntaxError : : create ( realm ( ) , Utf16String : : formatted ( " Failed to set protocol. '{}' is an invalid protocol " , value ) ) ;
2024-08-16 22:00:29 +01:00
// 6. if copyURL's scheme is not an HTTP(S) scheme, then terminate these steps.
if ( ! ( copy_url . scheme ( ) = = " http " sv | | copy_url . scheme ( ) = = " https " sv ) )
return { } ;
// 7. Location-object navigate this to copyURL.
TRY ( navigate ( copy_url ) ) ;
return { } ;
2020-05-18 21:42:40 +02:00
}
2022-03-04 23:35:34 +01:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-host
2023-03-04 22:16:07 +00:00
WebIDL : : ExceptionOr < String > Location : : host ( ) const
2020-05-18 21:59:16 +02:00
{
2023-03-04 22:16:07 +00:00
auto & vm = this - > vm ( ) ;
2023-03-04 22:37:12 +00:00
// 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
auto const relevant_document = this - > relevant_document ( ) ;
if ( relevant_document & & ! relevant_document - > origin ( ) . is_same_origin_domain ( entry_settings_object ( ) . origin ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2022-03-04 23:35:34 +01:00
// 2. Let url be this's url.
2023-01-18 17:41:12 +00:00
auto url = this - > url ( ) ;
2022-03-04 23:35:34 +01:00
2022-03-05 00:22:48 +01:00
// 3. If url's host is null, return the empty string.
2024-11-27 12:48:28 +00:00
if ( ! url . host ( ) . has_value ( ) )
2023-03-04 22:16:07 +00:00
return String { } ;
2022-03-05 00:22:48 +01:00
// 4. If url's port is null, return url's host, serialized.
if ( ! url . port ( ) . has_value ( ) )
2024-11-28 14:32:07 +00:00
return url . serialized_host ( ) ;
2022-03-04 23:35:34 +01:00
// 5. Return url's host, serialized, followed by ":" and url's port, serialized.
2024-11-28 14:32:07 +00:00
return TRY_OR_THROW_OOM ( vm , String : : formatted ( " {}:{} " , url . serialized_host ( ) , * url . port ( ) ) ) ;
2020-05-18 21:59:16 +02:00
}
2025-04-22 13:50:18 +12:00
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-host
WebIDL : : ExceptionOr < void > Location : : set_host ( String const & value )
2020-05-18 21:42:40 +02:00
{
2025-04-22 13:50:18 +12:00
// 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 ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2025-04-22 13:50:18 +12:00
// 3. Let copyURL be a copy of this's url.
auto copy_url = this - > url ( ) ;
// 4. If copyURL has an opaque path, then return.
if ( copy_url . has_an_opaque_path ( ) )
return { } ;
// 5. Basic URL parse the given value, with copyURL as url and host state as state override.
( void ) URL : : Parser : : basic_parse ( value , { } , & copy_url , URL : : Parser : : State : : Host ) ;
// 6. Location-object navigate this to copyURL.
TRY ( navigate ( copy_url ) ) ;
return { } ;
2023-01-18 17:41:12 +00:00
}
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-hostname
2023-03-04 22:16:07 +00:00
WebIDL : : ExceptionOr < String > Location : : hostname ( ) const
2023-01-18 17:41:12 +00:00
{
2023-03-04 22:37:12 +00:00
// 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
auto const relevant_document = this - > relevant_document ( ) ;
if ( relevant_document & & ! relevant_document - > origin ( ) . is_same_origin_domain ( entry_settings_object ( ) . origin ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
auto url = this - > url ( ) ;
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
// 2. If this's url's host is null, return the empty string.
2024-11-27 12:48:28 +00:00
if ( ! url . host ( ) . has_value ( ) )
2023-03-04 22:16:07 +00:00
return String { } ;
2023-01-18 17:41:12 +00:00
// 3. Return this's url's host, serialized.
2024-11-28 14:32:07 +00:00
return url . serialized_host ( ) ;
2020-05-18 21:42:40 +02:00
}
2025-04-22 13:50:18 +12:00
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-hostname
WebIDL : : ExceptionOr < void > Location : : set_hostname ( String const & value )
2020-05-18 21:42:40 +02:00
{
2025-04-22 13:50:18 +12:00
// 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 ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2025-04-22 13:50:18 +12:00
// 3. Let copyURL be a copy of this's url.
auto copy_url = this - > url ( ) ;
// 4. If copyURL has an opaque path, then return.
if ( copy_url . has_an_opaque_path ( ) )
return { } ;
// 5. Basic URL parse the given value, with copyURL as url and hostname state as state override.
( void ) URL : : Parser : : basic_parse ( value , { } , & copy_url , URL : : Parser : : State : : Hostname ) ;
// 6. Location-object navigate this to copyURL.
TRY ( navigate ( copy_url ) ) ;
return { } ;
2023-01-18 17:41:12 +00:00
}
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-port
2023-03-04 22:16:07 +00:00
WebIDL : : ExceptionOr < String > Location : : port ( ) const
2023-01-18 17:41:12 +00:00
{
2023-03-04 22:37:12 +00:00
// 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
auto const relevant_document = this - > relevant_document ( ) ;
if ( relevant_document & & ! relevant_document - > origin ( ) . is_same_origin_domain ( entry_settings_object ( ) . origin ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
auto url = this - > url ( ) ;
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
// 2. If this's url's port is null, return the empty string.
if ( ! url . port ( ) . has_value ( ) )
2023-03-04 22:16:07 +00:00
return String { } ;
2023-01-18 17:41:12 +00:00
// 3. Return this's url's port, serialized.
2024-10-14 10:05:01 +02:00
return String : : number ( * url . port ( ) ) ;
2020-05-18 21:42:40 +02:00
}
2025-04-22 13:50:18 +12:00
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-port
WebIDL : : ExceptionOr < void > Location : : set_port ( String const & value )
2020-05-18 21:59:16 +02:00
{
2025-04-22 13:50:18 +12:00
// 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 ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2025-04-22 13:50:18 +12:00
// 3. Let copyURL be a copy of this's url.
auto copy_url = this - > url ( ) ;
// 4. If copyURL cannot have a username/password/port, then return.
if ( copy_url . cannot_have_a_username_or_password_or_port ( ) )
return { } ;
// 5. If the given value is the empty string, then set copyURL's port to null.
if ( value . is_empty ( ) ) {
copy_url . set_port ( { } ) ;
}
// 5. Otherwise, basic URL parse the given value, with copyURL as url and port state as state override.
else {
( void ) URL : : Parser : : basic_parse ( value , { } , & copy_url , URL : : Parser : : State : : Port ) ;
}
// 6. Location-object navigate this to copyURL.
TRY ( navigate ( copy_url ) ) ;
return { } ;
2023-01-18 17:41:12 +00:00
}
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-pathname
2023-03-04 22:16:07 +00:00
WebIDL : : ExceptionOr < String > Location : : pathname ( ) const
2023-01-18 17:41:12 +00:00
{
2023-03-04 22:37:12 +00:00
// 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
auto const relevant_document = this - > relevant_document ( ) ;
if ( relevant_document & & ! relevant_document - > origin ( ) . is_same_origin_domain ( entry_settings_object ( ) . origin ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
// 2. Return the result of URL path serializing this Location object's url.
2024-08-05 16:55:39 +12:00
return url ( ) . serialize_path ( ) ;
2020-05-18 21:59:16 +02:00
}
2025-04-22 13:50:18 +12:00
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-search
WebIDL : : ExceptionOr < void > Location : : set_pathname ( String const & value )
2021-09-18 21:44:45 +02:00
{
2025-04-22 13:50:18 +12:00
// 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 ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2025-04-22 13:50:18 +12:00
// 3. Let copyURL be a copy of this's url.
auto copy_url = this - > url ( ) ;
// 4. If copyURL has an opaque path, then return.
if ( copy_url . has_an_opaque_path ( ) )
return { } ;
// 5. Set copyURL's path to the empty list.
copy_url . set_paths ( { } ) ;
// 6. Basic URL parse the given value, with copyURL as url and path start state as state override.
( void ) URL : : Parser : : basic_parse ( value , { } , & copy_url , URL : : Parser : : State : : PathStart ) ;
// 7. Location-object navigate this to copyURL.
TRY ( navigate ( copy_url ) ) ;
return { } ;
2023-01-18 17:41:12 +00:00
}
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-search
2023-03-04 22:16:07 +00:00
WebIDL : : ExceptionOr < String > Location : : search ( ) const
2023-01-18 17:41:12 +00:00
{
2023-03-04 22:16:07 +00:00
auto & vm = this - > vm ( ) ;
2023-03-04 22:37:12 +00:00
// 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
auto const relevant_document = this - > relevant_document ( ) ;
if ( relevant_document & & ! relevant_document - > origin ( ) . is_same_origin_domain ( entry_settings_object ( ) . origin ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
auto url = this - > url ( ) ;
2022-03-04 23:35:34 +01:00
2023-01-18 17:41:12 +00:00
// 2. If this's url's query is either null or the empty string, return the empty string.
2023-08-12 19:28:19 +12:00
if ( ! url . query ( ) . has_value ( ) | | url . query ( ) - > is_empty ( ) )
2023-03-04 22:16:07 +00:00
return String { } ;
2023-01-18 17:41:12 +00:00
// 3. Return "?", followed by this's url's query.
2023-03-04 22:16:07 +00:00
return TRY_OR_THROW_OOM ( vm , String : : formatted ( " ?{} " , url . query ( ) ) ) ;
2021-09-18 21:44:45 +02:00
}
2024-08-20 15:22:14 +02:00
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-search
WebIDL : : ExceptionOr < void > Location : : set_search ( String const & value )
2022-11-04 22:48:42 -03:00
{
2024-08-20 15:22:14 +02:00
// The search setter steps are:
auto const relevant_document = this - > relevant_document ( ) ;
// 1. If this's relevant Document is null, then return.
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 ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2024-08-20 15:22:14 +02:00
// 3. Let copyURL be a copy of this's url.
auto copy_url = this - > url ( ) ;
// 4. If the given value is the empty string, set copyURL's query to null.
if ( value . is_empty ( ) ) {
copy_url . set_query ( { } ) ;
}
// 5. Otherwise, run these substeps:
else {
2025-04-22 13:49:35 +12:00
// 1. Let input be the given value with a single leading "?" removed, if any.
2024-08-20 15:22:14 +02:00
auto value_as_string_view = value . bytes_as_string_view ( ) ;
auto input = value_as_string_view . substring_view ( value_as_string_view . starts_with ( ' ? ' ) ) ;
2025-04-22 13:49:35 +12:00
// 2. Set copyURL's query to the empty string.
2024-08-20 15:22:14 +02:00
copy_url . set_query ( String { } ) ;
2025-04-22 13:49:35 +12:00
// 3. Basic URL parse input, with null, the relevant Document's document's character encoding, copyURL as url, and query state as state override.
2024-08-20 15:22:14 +02:00
( void ) URL : : Parser : : basic_parse ( input , { } , & copy_url , URL : : Parser : : State : : Query ) ;
}
// 6. Location-object navigate this to copyURL.
TRY ( navigate ( copy_url ) ) ;
return { } ;
2023-01-18 17:41:12 +00:00
}
2022-11-04 22:48:42 -03:00
2023-01-18 17:41:12 +00:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-hash
2023-03-04 22:16:07 +00:00
WebIDL : : ExceptionOr < String > Location : : hash ( ) const
2023-01-18 17:41:12 +00:00
{
2023-03-04 22:16:07 +00:00
auto & vm = this - > vm ( ) ;
2023-03-04 22:37:12 +00:00
// 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
auto const relevant_document = this - > relevant_document ( ) ;
if ( relevant_document & & ! relevant_document - > origin ( ) . is_same_origin_domain ( entry_settings_object ( ) . origin ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2022-11-04 22:48:42 -03:00
2023-01-18 17:41:12 +00:00
auto url = this - > url ( ) ;
// 2. If this's url's fragment is either null or the empty string, return the empty string.
2023-08-12 16:52:42 +12:00
if ( ! url . fragment ( ) . has_value ( ) | | url . fragment ( ) - > is_empty ( ) )
2023-03-04 22:16:07 +00:00
return String { } ;
2023-01-18 17:41:12 +00:00
// 3. Return "#", followed by this's url's fragment.
2023-08-12 16:52:42 +12:00
return TRY_OR_THROW_OOM ( vm , String : : formatted ( " #{} " , * url . fragment ( ) ) ) ;
2023-01-18 17:41:12 +00:00
}
2023-02-11 12:19:28 +01:00
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-hash
2025-04-23 17:00:56 +12:00
WebIDL : : ExceptionOr < void > Location : : set_hash ( StringView value )
2023-01-18 17:41:12 +00:00
{
2023-02-11 12:19:28 +01:00
// 1. If this's relevant Document is null, then return.
2025-04-22 13:49:35 +12:00
auto const relevant_document = this - > relevant_document ( ) ;
2023-03-04 22:37:12 +00:00
if ( ! relevant_document )
2023-02-11 12:19:28 +01:00
return { } ;
2023-03-04 22:37:12 +00:00
// 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 ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2023-02-11 12:19:28 +01:00
// 3. Let copyURL be a copy of this's url.
auto copy_url = this - > url ( ) ;
2025-04-22 19:18:24 +12:00
// 4. Let thisURLFragment be copyURL's fragment if it is non-null; otherwise the empty string.
auto this_url_fragment = copy_url . fragment ( ) . has_value ( ) ? * copy_url . fragment ( ) : String { } ;
// 5. Let input be the given value with a single leading "#" removed, if any.
2025-04-23 17:00:56 +12:00
auto input = value . substring_view ( value . starts_with ( ' # ' ) ) ;
2023-02-11 12:19:28 +01:00
2025-04-22 19:18:24 +12:00
// 6. Set copyURL's fragment to the empty string.
2023-08-12 16:52:42 +12:00
copy_url . set_fragment ( String { } ) ;
2023-02-11 12:19:28 +01:00
2025-04-22 19:18:24 +12:00
// 7. Basic URL parse input, with copyURL as url and fragment state as state override.
2024-08-13 19:18:50 +12:00
( void ) URL : : Parser : : basic_parse ( input , { } , & copy_url , URL : : Parser : : State : : Fragment ) ;
2023-02-11 12:19:28 +01:00
2025-04-22 19:18:24 +12:00
// 8. If copyURL's fragment is thisURLFragment, then return.
if ( copy_url . fragment ( ) = = this_url_fragment )
2023-02-11 12:19:28 +01:00
return { } ;
2025-04-22 19:18:24 +12:00
// 9. Location-object navigate this to copyURL.
2023-08-22 18:33:20 +02:00
TRY ( navigate ( copy_url ) ) ;
2023-02-11 12:19:28 +01:00
return { } ;
2022-11-04 22:48:42 -03:00
}
2022-03-04 23:35:34 +01:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-reload
2023-01-18 17:41:12 +00:00
void Location : : reload ( ) const
2020-05-18 22:05:13 +02:00
{
2023-08-22 18:21:00 +02:00
// 1. Let document be this's relevant Document.
auto document = relevant_document ( ) ;
// 2. If document is null, then return.
if ( ! document )
return ;
2023-08-22 18:33:20 +02:00
2023-08-22 18:21:00 +02:00
// FIXME: 3. If document's origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
// 4. Reload document's node navigable.
document - > navigable ( ) - > reload ( ) ;
2020-05-18 22:05:13 +02:00
}
2022-03-04 23:35:34 +01:00
// https://html.spec.whatwg.org/multipage/history.html#dom-location-replace
2023-08-22 18:49:28 +02:00
WebIDL : : ExceptionOr < void > Location : : replace ( String const & url )
2021-10-03 23:31:52 +02:00
{
2023-08-22 18:49:28 +02:00
// 1. If this's relevant Document is null, then return.
if ( ! relevant_document ( ) )
return { } ;
// 2. Parse url relative to the entry settings object. If that failed, throw a "SyntaxError" DOMException.
auto replace_url = entry_settings_object ( ) . parse_url ( url ) ;
2025-02-16 14:01:09 +13:00
if ( ! replace_url . has_value ( ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SyntaxError : : create ( realm ( ) , Utf16String : : formatted ( " Invalid URL '{}' " , url ) ) ;
2023-08-22 18:49:28 +02:00
// 3. Location-object navigate this to the resulting URL record given "replace".
2025-02-16 14:01:09 +13:00
TRY ( navigate ( replace_url . release_value ( ) , Bindings : : NavigationHistoryBehavior : : Replace ) ) ;
2023-08-22 18:49:28 +02:00
return { } ;
2021-10-03 23:31:52 +02:00
}
2023-05-15 20:11:38 +01:00
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-assign
2023-08-22 18:33:20 +02:00
WebIDL : : ExceptionOr < void > Location : : assign ( String const & url )
2023-05-15 20:11:38 +01:00
{
// 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 ( ) ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SecurityError : : create ( realm ( ) , " Location's relevant document is not same origin-domain with the entry settings object's origin " _utf16 ) ;
2023-05-15 20:11:38 +01:00
// 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 ) ;
2025-02-16 14:01:09 +13:00
if ( ! assign_url . has_value ( ) )
2025-08-07 19:31:52 -04:00
return WebIDL : : SyntaxError : : create ( realm ( ) , Utf16String : : formatted ( " Invalid URL '{}' " , url ) ) ;
2023-05-15 20:11:38 +01:00
// 4. Location-object navigate this to the resulting URL record.
2025-02-16 14:01:09 +13:00
TRY ( navigate ( assign_url . release_value ( ) ) ) ;
2023-08-22 18:33:20 +02:00
2023-05-15 20:11:38 +01:00
return { } ;
}
2022-03-06 00:24:18 +01:00
// 7.10.5.1 [[GetPrototypeOf]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-getprototypeof
2023-01-18 17:41:12 +00:00
JS : : ThrowCompletionOr < JS : : Object * > Location : : internal_get_prototype_of ( ) const
2022-03-06 00:24:18 +01:00
{
// 1. If IsPlatformObjectSameOrigin(this) is true, then return ! OrdinaryGetPrototypeOf(this).
2022-09-24 14:02:47 +01:00
if ( HTML : : is_platform_object_same_origin ( * this ) )
2022-03-06 00:24:18 +01:00
return MUST ( JS : : Object : : internal_get_prototype_of ( ) ) ;
// 2. Return null.
return nullptr ;
}
// 7.10.5.2 [[SetPrototypeOf]] ( V ), https://html.spec.whatwg.org/multipage/history.html#location-setprototypeof
2023-01-18 17:41:12 +00:00
JS : : ThrowCompletionOr < bool > Location : : internal_set_prototype_of ( Object * prototype )
2021-09-12 14:54:17 +01:00
{
// 1. Return ! SetImmutablePrototype(this, V).
2021-10-03 19:52:13 +01:00
return MUST ( set_immutable_prototype ( prototype ) ) ;
2021-09-12 14:54:17 +01:00
}
2022-03-06 00:24:18 +01:00
// 7.10.5.3 [[IsExtensible]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-isextensible
2023-01-18 17:41:12 +00:00
JS : : ThrowCompletionOr < bool > Location : : internal_is_extensible ( ) const
2021-09-12 14:54:17 +01:00
{
// 1. Return true.
return true ;
}
2022-03-06 00:24:18 +01:00
// 7.10.5.4 [[PreventExtensions]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-preventextensions
2023-01-18 17:41:12 +00:00
JS : : ThrowCompletionOr < bool > Location : : internal_prevent_extensions ( )
2021-09-12 14:54:17 +01:00
{
// 1. Return false.
return false ;
2020-05-18 21:42:40 +02:00
}
2022-03-06 00:24:18 +01:00
// 7.10.5.5 [[GetOwnProperty]] ( P ), https://html.spec.whatwg.org/multipage/history.html#location-getownproperty
2023-01-18 17:41:12 +00:00
JS : : ThrowCompletionOr < Optional < JS : : PropertyDescriptor > > Location : : internal_get_own_property ( JS : : PropertyKey const & property_key ) const
2022-03-06 00:24:18 +01:00
{
2022-08-21 21:21:52 +01:00
auto & vm = this - > vm ( ) ;
2022-03-06 00:24:18 +01:00
// 1. If IsPlatformObjectSameOrigin(this) is true, then:
2022-09-24 14:02:47 +01:00
if ( HTML : : is_platform_object_same_origin ( * this ) ) {
2022-03-06 00:24:18 +01:00
// 1. Let desc be OrdinaryGetOwnProperty(this, P).
auto descriptor = MUST ( Object : : internal_get_own_property ( property_key ) ) ;
// 2. If the value of the [[DefaultProperties]] internal slot of this contains P, then set desc.[[Configurable]] to true.
2024-12-09 15:55:18 +04:00
// FIXME: This doesn't align with what the other browsers do. Spec issue: https://github.com/whatwg/html/issues/4157
2025-05-16 04:14:12 +01:00
auto property_key_value = property_key . is_symbol ( )
? JS : : Value { property_key . as_symbol ( ) }
: JS : : PrimitiveString : : create ( vm , property_key . to_string ( ) ) ;
if ( m_default_properties . contains_slow ( property_key_value ) )
2022-03-06 00:24:18 +01:00
descriptor - > configurable = true ;
// 3. Return desc.
return descriptor ;
}
// 2. Let property be CrossOriginGetOwnPropertyHelper(this, P).
2023-01-18 17:41:12 +00:00
auto property = HTML : : cross_origin_get_own_property_helper ( const_cast < Location * > ( this ) , property_key ) ;
2022-03-06 00:24:18 +01:00
// 3. If property is not undefined, then return property.
if ( property . has_value ( ) )
return property ;
// 4. Return ? CrossOriginPropertyFallback(P).
2022-09-24 14:02:47 +01:00
return TRY ( HTML : : cross_origin_property_fallback ( vm , property_key ) ) ;
2022-03-06 00:24:18 +01:00
}
// 7.10.5.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/history.html#location-defineownproperty
2025-09-15 16:43:27 +02:00
JS : : ThrowCompletionOr < bool > Location : : internal_define_own_property ( JS : : PropertyKey const & property_key , JS : : PropertyDescriptor & descriptor , Optional < JS : : PropertyDescriptor > * precomputed_get_own_property )
2022-03-06 00:24:18 +01:00
{
// 1. If IsPlatformObjectSameOrigin(this) is true, then:
2022-09-24 14:02:47 +01:00
if ( HTML : : is_platform_object_same_origin ( * this ) ) {
2022-03-06 00:24:18 +01:00
// 1. If the value of the [[DefaultProperties]] internal slot of this contains P, then return false.
// 2. Return ? OrdinaryDefineOwnProperty(this, P, Desc).
2024-11-01 21:03:18 +01:00
return JS : : Object : : internal_define_own_property ( property_key , descriptor , precomputed_get_own_property ) ;
2022-03-06 00:24:18 +01:00
}
// 2. Throw a "SecurityError" DOMException.
2025-08-07 19:31:52 -04:00
return throw_completion ( WebIDL : : SecurityError : : create ( realm ( ) , Utf16String : : formatted ( " Can't define property ' { } ' on cross - origin object " , property_key)));
2022-03-06 00:24:18 +01:00
}
// 7.10.5.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-get
2025-09-15 17:23:39 +02:00
JS : : ThrowCompletionOr < JS : : Value > Location : : internal_get ( JS : : PropertyKey const & property_key , JS : : Value receiver , JS : : CacheableGetPropertyMetadata * cacheable_metadata , PropertyLookupPhase phase ) const
2022-03-06 00:24:18 +01:00
{
2022-08-21 21:21:52 +01:00
auto & vm = this - > vm ( ) ;
2022-03-06 00:24:18 +01:00
// 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinaryGet(this, P, Receiver).
2022-09-24 14:02:47 +01:00
if ( HTML : : is_platform_object_same_origin ( * this ) )
2024-05-02 11:13:08 +02:00
return JS : : Object : : internal_get ( property_key , receiver , cacheable_metadata , phase ) ;
2022-03-06 00:24:18 +01:00
// 2. Return ? CrossOriginGet(this, P, Receiver).
2022-09-24 14:02:47 +01:00
return HTML : : cross_origin_get ( vm , static_cast < JS : : Object const & > ( * this ) , property_key , receiver ) ;
2022-03-06 00:24:18 +01:00
}
// 7.10.5.8 [[Set]] ( P, V, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-set
2025-09-15 17:23:39 +02:00
JS : : ThrowCompletionOr < bool > Location : : internal_set ( JS : : PropertyKey const & property_key , JS : : Value value , JS : : Value receiver , JS : : CacheableSetPropertyMetadata * cacheable_metadata , PropertyLookupPhase phase )
2022-03-06 00:24:18 +01:00
{
2022-08-21 21:21:52 +01:00
auto & vm = this - > vm ( ) ;
2022-03-06 00:24:18 +01:00
// 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinarySet(this, P, V, Receiver).
2022-09-24 14:02:47 +01:00
if ( HTML : : is_platform_object_same_origin ( * this ) )
2025-05-04 16:00:13 +02:00
return JS : : Object : : internal_set ( property_key , value , receiver , cacheable_metadata , phase ) ;
2022-03-06 00:24:18 +01:00
// 2. Return ? CrossOriginSet(this, P, V, Receiver).
2022-09-24 14:02:47 +01:00
return HTML : : cross_origin_set ( vm , static_cast < JS : : Object & > ( * this ) , property_key , value , receiver ) ;
2022-03-06 00:24:18 +01:00
}
// 7.10.5.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/history.html#location-delete
2023-01-18 17:41:12 +00:00
JS : : ThrowCompletionOr < bool > Location : : internal_delete ( JS : : PropertyKey const & property_key )
2022-03-06 00:24:18 +01:00
{
// 1. If IsPlatformObjectSameOrigin(this) is true, then return ? OrdinaryDelete(this, P).
2022-09-24 14:02:47 +01:00
if ( HTML : : is_platform_object_same_origin ( * this ) )
2022-03-06 00:24:18 +01:00
return JS : : Object : : internal_delete ( property_key ) ;
// 2. Throw a "SecurityError" DOMException.
2025-08-07 19:31:52 -04:00
return throw_completion ( WebIDL : : SecurityError : : create ( realm ( ) , Utf16String : : formatted ( " Can't delete property ' { } ' on cross - origin object " , property_key)));
2022-03-06 00:24:18 +01:00
}
// 7.10.5.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-ownpropertykeys
2025-05-16 04:14:12 +01:00
JS : : ThrowCompletionOr < GC : : RootVector < JS : : Value > > Location : : internal_own_property_keys ( ) const
2022-03-06 00:24:18 +01:00
{
// 1. If IsPlatformObjectSameOrigin(this) is true, then return OrdinaryOwnPropertyKeys(this).
2022-09-24 14:02:47 +01:00
if ( HTML : : is_platform_object_same_origin ( * this ) )
2022-03-06 00:24:18 +01:00
return JS : : Object : : internal_own_property_keys ( ) ;
// 2. Return CrossOriginOwnPropertyKeys(this).
2022-09-24 14:02:47 +01:00
return HTML : : cross_origin_own_property_keys ( this ) ;
2022-03-06 00:24:18 +01:00
}
2020-05-18 21:42:40 +02:00
}