Throw SyntaxError from Location::SetHref (#39051)

It was originally throwing a TypeError, which was making WPT fail.

Testing: Many happy WPT subtests
Fixes: #39050

---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Co-authored-by: Sam <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Ashwin Naren 2025-09-02 10:19:10 -07:00 committed by GitHub
parent 47551fc6fa
commit b0b70ec6b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 10 additions and 610 deletions

View file

@ -412,14 +412,14 @@ impl LocationMethods<crate::DomTypeHolder> for Location {
// Step 1: If this Location object's relevant Document is null, then return.
if self.has_document() {
// Note: no call to self.check_same_origin_domain()
// Step 2: Parse the given value relative to the entry settings object.
// If that failed, throw a TypeError exception.
// Step 2: Let url be the result of encoding-parsing a URL given the given value, relative to the entry settings object.
// Step 3: If url is failure, then throw a "SyntaxError" DOMException.
let base_url = self.entry_settings_object().api_base_url();
let url = match base_url.join(&value.0) {
Ok(url) => url,
Err(e) => return Err(Error::Type(format!("Couldn't parse URL: {}", e))),
Err(e) => return Err(Error::Syntax(Some(format!("Couldn't parse URL: {}", e)))),
};
// Step 3: Location-object navigate to the resulting URL record.
// Step 4: Location-object navigate this to url.
self.navigate(
url,
NavigationHistoryBehavior::Push,