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

Make URLSearchParams iterable #13022 #13077

Closed
wants to merge 8 commits into from
Closed

Conversation

@yoyo930021
Copy link
Contributor

yoyo930021 commented Aug 27, 2016


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #13022 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Aug 27, 2016

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @connorgbrewster (or someone else) soon.

@highfive
Copy link

highfive commented Aug 27, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/webidls/URLSearchParams.webidl, components/script/dom/urlsearchparams.rs
@shinglyu shinglyu modified the milestone: Taiwan Code Sprint Aug 27, 2016
@izgzhen
Copy link
Contributor

izgzhen commented Aug 27, 2016

Use ./mach update-manifest instead of changing it manually can solve the manifest_changed.sh problem

<script>
test(function() {
var params = new URLSearchParams('a=1&b=2&c=3');
for(var URLSearchParam in params){

This comment has been minimized.

@jdm

jdm Aug 27, 2016

Member

This test doesn't actually verify that the keys are present. I don't think for in works on iterators this way, either, since Firefox didn't show me any of those keys when I tried it.

This comment has been minimized.

@yoyo930021

yoyo930021 Aug 27, 2016

Author Contributor

Yes, I test.
for-in isn't used iterators.

@emilio
Copy link
Member

emilio commented Aug 27, 2016

Review status: 0 of 4 files reviewed at latest revision, 3 unresolved discussions, some commit checks failed.


components/script/dom/urlsearchparams.rs, line 172 [r2] (raw file):

    pub fn sort_list(&self) -> Vec<(String, String)> {
        let borrowed_list = self.list.borrow();
        let URLSearchParams_iter = borrowed_list.iter();

nit: Use snake_case variable names.


components/script/dom/urlsearchparams.rs, line 194 [r2] (raw file):

    fn get_value_at_index(&self, n: u32) -> USVString {
        let sorted_URLSearchParam_vec = self.sort_list();

why are we sorting this each time we're accessed? I don't think that's necessary?


Comments from Reviewable

@yoyo930021
Copy link
Contributor Author

yoyo930021 commented Aug 27, 2016

@emilio
Yes,no need sort.
I finished.

type Value = USVString;

fn get_iterable_length(&self) -> u32 {
self.list.borrow().iter().count() as u32

This comment has been minimized.

@KiChjang

KiChjang Aug 27, 2016

Member

Doesn't self.list.borrow().len() work?

This comment has been minimized.

@emilio

emilio Aug 27, 2016

Member

Yes, it should, r=me with that. A test with something like what is described in #10351 would be great too :)

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" ]

This comment has been minimized.

@yoyo930021

yoyo930021 Aug 27, 2016

Author Contributor

@KiChjang
It work!
Thank you.

This comment has been minimized.

@yoyo930021

yoyo930021 Aug 27, 2016

Author Contributor

@emilio
Add test!
finish!

@emilio
Copy link
Member

emilio commented Aug 27, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Aug 27, 2016

Trying commit 8a16a43 with merge 638b553...

bors-servo added a commit that referenced this pull request Aug 27, 2016
Make URLSearchParams iterable #13022

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13022  (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

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

nox commented Aug 27, 2016

The test is incorrect, it could pass if the URLSearchParams is thought to be empty.

@yoyo930021
Copy link
Contributor Author

yoyo930021 commented Aug 27, 2016

@nox
tests to add
if URLSearchParams is nothing?


test(function() {
var params = new URLSearchParams('a=1&b=2&c=3');
params.forEach(function(value,index){

This comment has been minimized.

@Ms2ger

Ms2ger Aug 31, 2016

Contributor

I think the suggestion was to make this test more like

var found = [];
params.forEach(function(value, index) {
  found.push(value);
});
assert_array_equals(['1', '2', '3']);

This comment has been minimized.

@emilio

emilio Sep 21, 2016

Member

nit: space after comma here.

@Ms2ger
Copy link
Contributor

Ms2ger commented Sep 5, 2016

@yoyo930021 hey, do you know if you'll have time to finish this PR?

@yoyo930021
Copy link
Contributor Author

yoyo930021 commented Sep 5, 2016

I dont know!
I will try tomorrow.

@cbrewster
Copy link
Member

cbrewster commented Sep 12, 2016

r? @emilio

@highfive highfive assigned emilio and unassigned cbrewster Sep 12, 2016
Copy link
Member

emilio left a comment

Sorry for the huge delay in reviewing this! There are only formatting nits to fix.

If for some reason you're busy and have the PR marked as editable for the Servo members, I can make the fixes myself and get this landed.

Thank you so much for your contribution, and sorry for the delay again, it has totally been my fault!

let b = a.searchParams;
var c = [];
for (i of b) {
a.search="x=1&y=2&z=3";

This comment has been minimized.

@emilio

emilio Sep 21, 2016

Member

nit: Space before and after equals here.

}, "For-of Check");

test(function(){
let a=new URL("http://a.b/c");

This comment has been minimized.

@emilio

emilio Sep 21, 2016

Member

nit: Space before and after equals here.

for (i of b) {
c.push(i);
}
assert_equals(c.length,0);

This comment has been minimized.

@emilio

emilio Sep 21, 2016

Member

nit: Space after comma here.

@bors-servo
Copy link
Contributor

bors-servo commented Oct 7, 2016

The latest upstream changes (presumably #13596) made this pull request unmergeable. Please resolve the merge conflicts.

Ms2ger added a commit that referenced this pull request Oct 7, 2016
Fixes #13022.
Fixes #13077.
bors-servo added a commit that referenced this pull request Oct 7, 2016
Make URLSearchParams iterable.

Fixes #13022.
Fixes #13077.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13637)
<!-- Reviewable:end -->
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.

You can’t perform that action at this time.