Permalink
Browse files

Auto merge of #22638 - CYBAI:urlsearchparams-sort, r=nox

Implement URLSearchParams.prototype.sort()

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #22545
- [x] There are tests for these changes

<!-- 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/22638)
<!-- Reviewable:end -->
  • Loading branch information...
bors-servo committed Jan 10, 2019
2 parents e6e00cb + f43c604 commit 2e15cf0f81d3a61a5f9b40699b51575fcefac857
@@ -168,6 +168,17 @@ impl URLSearchParamsMethods for URLSearchParams {
self.update_steps();
}

// https://url.spec.whatwg.org/#dom-urlsearchparams-sort
fn Sort(&self) {
// Step 1.
self.list
.borrow_mut()
.sort_by(|(a, _), (b, _)| a.encode_utf16().cmp(b.encode_utf16()));

// Step 2.
self.update_steps();
}

// https://url.spec.whatwg.org/#stringification-behavior
fn Stringifier(&self) -> DOMString {
DOMString::from(self.serialize_utf8())
@@ -182,9 +193,7 @@ impl URLSearchParams {
.extend_pairs(&*list)
.finish()
}
}

impl URLSearchParams {
// https://url.spec.whatwg.org/#concept-urlsearchparams-update
fn update_steps(&self) {
if let Some(url) = self.url.root() {
@@ -16,6 +16,9 @@ interface URLSearchParams {
sequence<USVString> getAll(USVString name);
boolean has(USVString name);
void set(USVString name, USVString value);

void sort();

// Be careful with implementing iterable interface.
// Search params might be mutated by URL::SetSearch while iterating (discussed in PR #10351).
iterable<USVString, USVString>;
@@ -2,15 +2,9 @@
[idlharness]
expected: FAIL

[URLSearchParams interface: operation sort()]
expected: FAIL

[Testing Symbol.iterator property of iterable interface URLSearchParams]
expected: FAIL

[URLSearchParams interface: new URLSearchParams("hi=there&thank=you") must inherit property "sort()" with the proper type]
expected: FAIL

[URL interface: legacy window alias]
expected: FAIL

@@ -19,12 +13,5 @@
[idlharness]
expected: FAIL

[URLSearchParams interface: operation sort()]
expected: FAIL

[Testing Symbol.iterator property of iterable interface URLSearchParams]
expected: FAIL

[URLSearchParams interface: new URLSearchParams("hi=there&thank=you") must inherit property "sort()" with the proper type]
expected: FAIL

@@ -1,105 +1,7 @@
[urlsearchparams-sort.any.html]
[Parse and sort: a🌈&a💩]
expected: FAIL

[URL parse and sort: z=z&a=a&z=y&a=b&z=x&a=c&z=w&a=d&z=v&a=e&z=u&a=f&z=t&a=g]
expected: FAIL

[URL parse and sort: bbb&bb&aaa&aa=x&aa=y]
expected: FAIL

[URL parse and sort: é&e�&é]
expected: FAIL

[Parse and sort: ffi&🌈]
expected: FAIL

[URL parse and sort: �=x&&�=a]
expected: FAIL

[Parse and sort: z=z&=f&=t&=x]
expected: FAIL

[Sorting non-existent params removes ? from URL]
expected: FAIL

[Parse and sort: é&e�&é]
expected: FAIL

[URL parse and sort: ffi&🌈]
expected: FAIL

[Parse and sort: z=z&a=a&z=y&a=b&z=x&a=c&z=w&a=d&z=v&a=e&z=u&a=f&z=t&a=g]
expected: FAIL

[Parse and sort: z=b&a=b&z=a&a=a]
expected: FAIL

[Parse and sort: bbb&bb&aaa&aa=x&aa=y]
expected: FAIL

[Parse and sort: �=x&&�=a]
expected: FAIL

[URL parse and sort: a🌈&a💩]
expected: FAIL

[URL parse and sort: z=b&a=b&z=a&a=a]
expected: FAIL

[URL parse and sort: z=z&=f&=t&=x]
expected: FAIL


[urlsearchparams-sort.any.worker.html]
[Parse and sort: a🌈&a💩]
expected: FAIL

[URL parse and sort: z=z&a=a&z=y&a=b&z=x&a=c&z=w&a=d&z=v&a=e&z=u&a=f&z=t&a=g]
expected: FAIL

[URL parse and sort: bbb&bb&aaa&aa=x&aa=y]
expected: FAIL

[URL parse and sort: é&e�&é]
expected: FAIL

[Parse and sort: ffi&🌈]
expected: FAIL

[URL parse and sort: �=x&&�=a]
expected: FAIL

[Parse and sort: z=z&=f&=t&=x]
expected: FAIL

[Sorting non-existent params removes ? from URL]
expected: FAIL

[Parse and sort: é&e�&é]
expected: FAIL

[URL parse and sort: ffi&🌈]
expected: FAIL

[Parse and sort: z=z&a=a&z=y&a=b&z=x&a=c&z=w&a=d&z=v&a=e&z=u&a=f&z=t&a=g]
expected: FAIL

[Parse and sort: z=b&a=b&z=a&a=a]
expected: FAIL

[Parse and sort: bbb&bb&aaa&aa=x&aa=y]
expected: FAIL

[Parse and sort: �=x&&�=a]
expected: FAIL

[URL parse and sort: a🌈&a💩]
expected: FAIL

[URL parse and sort: z=b&a=b&z=a&a=a]
expected: FAIL

[URL parse and sort: z=z&=f&=t&=x]
expected: FAIL

0 comments on commit 2e15cf0

Please sign in to comment.