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
+50
−18
Merged
Implement URL.searchParams #10351
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
| @@ -6,11 +6,13 @@ use dom::bindings::cell::DOMRefCell; | ||
| use dom::bindings::codegen::Bindings::URLBinding::{self, URLMethods}; | ||
| use dom::bindings::error::{Error, ErrorResult, Fallible}; | ||
| use dom::bindings::global::GlobalRef; | ||
| use dom::bindings::js::Root; | ||
| use dom::bindings::reflector::{Reflector, reflect_dom_object}; | ||
| use dom::bindings::js::{JS, MutNullableHeap, Root}; | ||
| use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; | ||
| use dom::bindings::str::USVString; | ||
| use dom::urlhelper::UrlHelper; | ||
| use dom::urlsearchparams::URLSearchParams; | ||
| use std::borrow::ToOwned; | ||
| use std::default::Default; | ||
| use url::{Host, ParseResult, Url, UrlParser}; | ||
| use util::str::DOMString; | ||
|
|
||
| @@ -24,6 +26,9 @@ pub struct URL { | ||
|
|
||
| // https://url.spec.whatwg.org/#concept-urlutils-get-the-base | ||
| base: Option<Url>, | ||
|
|
||
| // https://url.spec.whatwg.org/#dom-url-searchparams | ||
| search_params: MutNullableHeap<JS<URLSearchParams>>, | ||
| } | ||
|
|
||
| impl URL { | ||
| @@ -32,13 +37,18 @@ impl URL { | ||
| reflector_: Reflector::new(), | ||
| url: DOMRefCell::new(url), | ||
| base: base, | ||
| search_params: Default::default(), | ||
| } | ||
| } | ||
|
|
||
| pub fn new(global: GlobalRef, url: Url, base: Option<Url>) -> Root<URL> { | ||
| reflect_dom_object(box URL::new_inherited(url, base), | ||
| global, URLBinding::Wrap) | ||
| } | ||
|
|
||
| pub fn set_query(&self, query: String) { | ||
| self.url.borrow_mut().query = Some(query); | ||
| } | ||
| } | ||
|
|
||
| impl URL { | ||
| @@ -69,8 +79,13 @@ impl URL { | ||
| return Err(Error::Type(format!("could not parse URL: {}", error))); | ||
| } | ||
| }; | ||
| // Steps 5-8. | ||
| Ok(URL::new(global, parsed_url, parsed_base)) | ||
| // Step 5: Skip (see step 8 below). | ||
| // Steps 6-7. | ||
| let result = URL::new(global, parsed_url, parsed_base); | ||
| // Step 8: Instead of construcing a new `URLSearchParams` object here, construct it | ||
| // on-demand inside `URL::SearchParams`. | ||
| // Step 9. | ||
| Ok(result) | ||
| } | ||
|
|
||
| // https://url.spec.whatwg.org/#dom-url-domaintoasciidomain | ||
| @@ -189,6 +204,14 @@ impl URLMethods for URL { | ||
| // https://url.spec.whatwg.org/#dom-url-search | ||
| fn SetSearch(&self, value: USVString) { | ||
| UrlHelper::SetSearch(&mut self.url.borrow_mut(), value); | ||
stjepang
Author
Contributor
|
||
| if let Some(search_params) = self.search_params.get() { | ||
| search_params.set_list(self.url.borrow().query_pairs().unwrap_or_else(|| vec![])); | ||
| } | ||
| } | ||
|
|
||
| // https://url.spec.whatwg.org/#dom-url-searchparams | ||
| fn SearchParams(&self) -> Root<URLSearchParams> { | ||
| self.search_params.or_init(|| URLSearchParams::new(self.global().r(), Some(self))) | ||
| } | ||
|
|
||
| // https://url.spec.whatwg.org/#dom-url-href | ||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
All the setters should update the stored query object if we're going to store it as a field.