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

Implement URL.searchParams #10351

Merged
merged 1 commit into from Apr 6, 2016
Merged

Conversation

@stjepang
Copy link
Contributor

stjepang commented Apr 1, 2016

@highfive
Copy link

highfive commented Apr 1, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/url.rs, components/script/dom/webidls/URL.webidl
@highfive
Copy link

highfive commented Apr 1, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@larsbergstrom
Copy link
Contributor

larsbergstrom commented Apr 1, 2016

r? @Manishearth
(since you commented in the original issue with details on the spec, etc.)

@highfive highfive assigned Manishearth and unassigned larsbergstrom Apr 1, 2016
@@ -24,19 +26,24 @@ pub struct URL {

// https://url.spec.whatwg.org/#concept-urlutils-get-the-base
base: Option<Url>,

// https://url.spec.whatwg.org/#dom-url-searchparams
query: JS<URLSearchParams>,

This comment has been minimized.

@Manishearth

Manishearth Apr 2, 2016

Member

Can we calculate this on-demand instead of storing it?

This comment has been minimized.

@Manishearth

Manishearth Apr 2, 2016

Member

Technically we can't; a quick test in Firefox shows that mutating the object returned on url.searchParams will be reflected when accessed again. The spec does mention that a URL object has an associated URLSearchParams object, so this is correct I guess.

cc @Ms2ger does this particularly matter?

This comment has been minimized.

@Manishearth

Manishearth Apr 2, 2016

Member

Chrome doesn't seem to support searchParams at all? It autocompletes in the console but is undefined.

This comment has been minimized.

@Manishearth

Manishearth Apr 2, 2016

Member

Actually, this is a bit hairier if URLSearchParams is mutable through URL. It's also an iterator.

What happens if I mutate the original URL whilst iterating it?

This comment has been minimized.

@Manishearth

Manishearth Apr 2, 2016

Member

Firefox iterates index-wise, if you change the query string it will continue to iterate from that index in the new query string if that index exists.

let a=new URL("http://a.b/c?a=1&b=2&c=3&d=4");
let b = a.searchParams;
for (i of b) {
    a.search="x=1&y=2&z=3";
    console.log(i);
}
// outputs
Array [ "a", "1" ]
Array [ "y", "2" ]
Array [ "z", "3" ]
@@ -191,6 +202,11 @@ impl URLMethods for URL {
UrlHelper::SetSearch(&mut self.url.borrow_mut(), value);

This comment has been minimized.

@Manishearth

Manishearth Apr 2, 2016

Member

All the setters should update the stored query object if we're going to store it as a field.

This comment has been minimized.

@stjepang

stjepang Apr 2, 2016

Author Contributor

Instead of calculating query pairs on-demand, I'd rather stick to the spec and store them immediately.

Regarding iteration, this is something we currently don't handle - it's commented in URLSearchParams.webidl:
// iterable<USVString, USVString>;
Please correct me if I'm wrong.

Firefox's approach looks reasonable to me. We'll just have to be careful when implementing the iterable interface.

@Manishearth
Copy link
Member

Manishearth commented Apr 2, 2016

Review status: 0 of 2 files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/url.rs, line 31 [r1] (raw file):
Agreed. Perhaps we should store a MutNullableHeap<JS> instead and lazy-load it when content asks for it? I don't like creating extra JS objects here and there.

Also, please leave a comment about the iterable stuff somewhere. I think that bit is simply unspecced, so ultimately it might not matter much.


Comments from Reviewable

@stjepang
Copy link
Contributor Author

stjepang commented Apr 3, 2016

Review status: 0 of 2 files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/url.rs, line 31 [r1] (raw file):
Perhaps. :) If you insist on using MutNullableHeap, I'll do that.
In that case... URLSearchParams::Constructor requires a GlobalRef as an argument. What would be the best way to obtain a GlobalRef when constructing it?

I'll write a comment about the iterable stuff.


Comments from Reviewable

@nox
Copy link
Member

nox commented Apr 3, 2016

Review status: 0 of 4 files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/url.rs, line 31 [r1] (raw file):
It should definitely be MutNullableHeap and you can get the global object of any DOM instance with foo.global(), just use that on the URL value. Also you should probably not use Constructor anyway but new.

I just remembered I had started to implement this, if you need some inspiration.


Comments from Reviewable

@stjepang
Copy link
Contributor Author

stjepang commented Apr 3, 2016

Review status: 0 of 4 files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/url.rs, line 31 [r1] (raw file):
Thanks, that's very useful!


Comments from Reviewable

@Manishearth
Copy link
Member

Manishearth commented Apr 5, 2016

@bors-servo r+

Thanks!


Reviewed 1 of 2 files at r1, 1 of 3 files at r2, 2 of 2 files at r3.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


Comments from Reviewable

@bors-servo
Copy link
Contributor

bors-servo commented Apr 5, 2016

📌 Commit 471a490 has been approved by Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented Apr 5, 2016

Testing commit 471a490 with merge 4eb1915...

bors-servo added a commit that referenced this pull request Apr 5, 2016
Implement URL.searchParams

Spec: https://url.spec.whatwg.org/#dom-url-searchparams
Closes #10335.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10351)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Apr 5, 2016

💔 Test failed - mac-rel-wpt

@jdm
Copy link
Member

jdm commented Apr 5, 2016

  ▶ Unexpected subtest result in /url/interfaces.html:
  └ PASS [expected FAIL] URL interface: attribute searchParams

  ▶ Unexpected subtest result in /url/interfaces.html:
  └ PASS [expected FAIL] URL interface: new URL("http://foo") must inherit property "searchParams" with the proper type (12)
@Manishearth
Copy link
Member

Manishearth commented Apr 5, 2016

r=me once you squash these commits

@stjepang stjepang force-pushed the stjepang:impl-url-searchparams branch from 7e0cd7a to 7b38f28 Apr 5, 2016
@Manishearth
Copy link
Member

Manishearth commented Apr 5, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Apr 5, 2016

📌 Commit 7b38f28 has been approved by Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented Apr 5, 2016

💔 Test failed - status-appveyor

@KiChjang
Copy link
Member

KiChjang commented Apr 5, 2016

@bors-servo retry

  • infra
@bors-servo
Copy link
Contributor

bors-servo commented Apr 5, 2016

Testing commit 7b38f28 with merge a2deaa8...

bors-servo added a commit that referenced this pull request Apr 5, 2016
Implement URL.searchParams

Spec: https://url.spec.whatwg.org/#dom-url-searchparams
Closes #10335.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10351)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Apr 5, 2016

💔 Test failed - status-appveyor

@KiChjang
Copy link
Member

KiChjang commented Apr 5, 2016

@bors-servo retry

  • The Annoying AppVeyor
@bors-servo
Copy link
Contributor

bors-servo commented Apr 5, 2016

Testing commit 7b38f28 with merge 7d05445...

bors-servo added a commit that referenced this pull request Apr 5, 2016
Implement URL.searchParams

Spec: https://url.spec.whatwg.org/#dom-url-searchparams
Closes #10335.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10351)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Apr 5, 2016

💔 Test failed - status-appveyor

@jdm
Copy link
Member

jdm commented Apr 5, 2016

@bors-servo: retry

  • let's do this one more time
@Ms2ger
Copy link
Contributor

Ms2ger commented Apr 6, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Apr 6, 2016

Testing commit 7b38f28 with merge e36e3be...

bors-servo added a commit that referenced this pull request Apr 6, 2016
Implement URL.searchParams

Spec: https://url.spec.whatwg.org/#dom-url-searchparams
Closes #10335.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10351)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Apr 6, 2016

@bors-servo bors-servo merged commit 7b38f28 into servo:master Apr 6, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@emilio emilio mentioned this pull request Aug 27, 2016
4 of 5 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

9 participants
You can’t perform that action at this time.