Update step numbers in URL constructor

Two commits have been made ahead of the current implementation of
Servo's URL constructor:

- Align with a more modern IDL definition style [1]
- Add URL.canParse() [2]

Since these commits don't alter the actual behavior, this commit only
updates the step numbers and adds brief descriptions for each step.

No behavior change is expected with this commit.

[1]: ea3b75d333
[2]: ae3c28b84e

Signed-off-by: Yutaro Ohno <yutaro.ono.418@gmail.com>
This commit is contained in:
Yutaro Ohno 2023-05-06 15:10:28 +09:00
parent f29834608a
commit 3336bf6cce

View file

@ -77,38 +77,38 @@ impl URL {
url: USVString, url: USVString,
base: Option<USVString>, base: Option<USVString>,
) -> Fallible<DomRoot<URL>> { ) -> Fallible<DomRoot<URL>> {
// Step 1. Parse url with base.
let parsed_base = match base { let parsed_base = match base {
None => { None => None,
// Step 1. Some(base) => {
None
},
Some(base) =>
// Step 2.1.
{
match ServoUrl::parse(&base.0) { match ServoUrl::parse(&base.0) {
Ok(base) => Some(base), Ok(base) => Some(base),
Err(error) => { Err(error) => {
// Step 2.2. // Step 2. Throw a TypeError if URL parsing fails.
return Err(Error::Type(format!("could not parse base: {}", error))); return Err(Error::Type(format!("could not parse base: {}", error)));
}, },
} }
}, },
}; };
// Step 3.
let parsed_url = match ServoUrl::parse_with_base(parsed_base.as_ref(), &url.0) { let parsed_url = match ServoUrl::parse_with_base(parsed_base.as_ref(), &url.0) {
Ok(url) => url, Ok(url) => url,
Err(error) => { Err(error) => {
// Step 4. // Step 2. Throw a TypeError if URL parsing fails.
return Err(Error::Type(format!("could not parse URL: {}", error))); return Err(Error::Type(format!("could not parse URL: {}", error)));
}, },
}; };
// Step 5: Skip (see step 8 below).
// Steps 6-7. // Skip the steps below.
let result = URL::new(global, parsed_url); // Instead of construcing a new `URLSearchParams` object here, construct it
// Step 8: Instead of construcing a new `URLSearchParams` object here, construct it // on-demand inside `URL::SearchParams`.
// on-demand inside `URL::SearchParams`. //
// Step 9. // Step 3. Let query be parsedURLs query.
Ok(result) // Step 5. Set thiss query object to a new URLSearchParams object.
// Step 6. Initialize thiss query object with query.
// Step 7. Set thiss query objects URL object to this.
// Step 4. Set thiss URL to parsedURL.
Ok(URL::new(global, parsed_url))
} }
// https://url.spec.whatwg.org/#dom-url-canparse // https://url.spec.whatwg.org/#dom-url-canparse