Implement URLSearchParams.prototype.sort()

This commit is contained in:
CYBAI 2019-01-07 00:19:30 +08:00
parent b5276194f4
commit f43c604bf3
4 changed files with 14 additions and 111 deletions

View file

@ -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())

View file

@ -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>;