Skip to content
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

Merged
merged 1 commit into from
May 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 17 additions & 17 deletions components/script/dom/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Comment on lines -108 to -109
Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.)

Copy link
Member

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.

Copy link
Contributor Author

@ohno418 ohno418 May 4, 2023

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!

// 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:
whatwg/url@ea3b75d#diff-29243b3b9b716b55c6a61970b0c4864f464b139d397fb961a05bb6e1e2b97cabL2840-L2842

Here's the current spec:
https://url.spec.whatwg.org/#constructors


// Step 4. Set this’s URL to parsedURL.
Ok(URL::new(global, parsed_url))
}

// https://url.spec.whatwg.org/#dom-url-canparse
Expand Down