-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update step numbers in URL constructor #29703
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,38 +77,38 @@ impl URL { | |
url: USVString, | ||
base: Option<USVString>, | ||
) -> Fallible<DomRoot<URL>> { | ||
// Step 1. Parse url with base. | ||
let parsed_base = match base { | ||
None => { | ||
// Step 1. | ||
None | ||
}, | ||
Some(base) => | ||
// Step 2.1. | ||
{ | ||
None => None, | ||
Some(base) => { | ||
match ServoUrl::parse(&base.0) { | ||
Ok(base) => Some(base), | ||
Err(error) => { | ||
// Step 2.2. | ||
// Step 2. Throw a TypeError if URL parsing fails. | ||
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) { | ||
Ok(url) => url, | ||
Err(error) => { | ||
// Step 4. | ||
// Step 2. Throw a TypeError if URL parsing fails. | ||
return Err(Error::Type(format!("could not parse URL: {}", error))); | ||
}, | ||
}; | ||
// Step 5: Skip (see step 8 below). | ||
// Steps 6-7. | ||
let result = URL::new(global, parsed_url); | ||
// Step 8: Instead of construcing a new `URLSearchParams` object here, construct it | ||
// on-demand inside `URL::SearchParams`. | ||
// Step 9. | ||
Ok(result) | ||
|
||
// Skip the steps below. | ||
// Instead of construcing a new `URLSearchParams` object here, construct it | ||
// on-demand inside `URL::SearchParams`. | ||
// | ||
// Step 3. Let query be parsedURL’s query. | ||
// Step 5. Set this’s query object to a new URLSearchParams object. | ||
// Step 6. Initialize this’s query object with query. | ||
// Step 7. Set this’s query object’s URL object to this. | ||
Comment on lines
+105
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit confusing. Step 5 and 8, which were previously skipped, seem to correspond these four steps. Step 8 is split into some parts here: Here's the current spec: |
||
|
||
// Step 4. Set this’s URL to parsedURL. | ||
Ok(URL::new(global, parsed_url)) | ||
} | ||
|
||
// https://url.spec.whatwg.org/#dom-url-canparse | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know exactly why this happened, but this PR doesn't change the behavior around
URLSearchParams
, continuing to ignore the related steps.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change just updating the step numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The corresponding spec change related to this PR can be found here: whatwg/url@ae3c28b8
(I probably should have mentioned this somewhere, such as in commit message.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the code changes are an improvement here, because they increase the nesting level of the method. Would it be possible to avoid changing the code if there is no behavior changes and also to paste a small description of each step in quotes. With a small amount of text, at least it will still be clear what each step does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that makes sense. I'll make the change. Thank you!