Auto merge of #24469 - saschanaz:urp-default, r=Manishearth

Support USVString as default value of a union argument

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

I don't expect this fixes any test though...

---
<!-- 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 #22543

<!-- Either: -->
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2019-10-18 04:02:13 -04:00 committed by GitHub
commit 32eb858a6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 8 deletions

View file

@ -732,6 +732,10 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
default = "%s::Boolean(%s)" % ( default = "%s::Boolean(%s)" % (
union_native_type(type), union_native_type(type),
"true" if defaultValue.value else "false") "true" if defaultValue.value else "false")
elif tag is IDLType.Tags.usvstring:
default = '%s::USVString(USVString("%s".to_owned()))' % (
union_native_type(type),
defaultValue.value)
else: else:
raise("We don't currently support default values that aren't null, boolean or default dictionary") raise("We don't currently support default values that aren't null, boolean or default dictionary")
elif dictionaries: elif dictionaries:

View file

@ -47,12 +47,12 @@ impl URLSearchParams {
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams // https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
pub fn Constructor( pub fn Constructor(
global: &GlobalScope, global: &GlobalScope,
init: Option<USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString>, init: USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString,
) -> Fallible<DomRoot<URLSearchParams>> { ) -> Fallible<DomRoot<URLSearchParams>> {
// Step 1. // Step 1.
let query = URLSearchParams::new(global, None); let query = URLSearchParams::new(global, None);
match init { match init {
Some(USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString::USVStringSequenceSequence(init)) => { USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString::USVStringSequenceSequence(init) => {
// Step 2. // Step 2.
// Step 2-1. // Step 2-1.
@ -64,12 +64,12 @@ impl URLSearchParams {
*query.list.borrow_mut() = *query.list.borrow_mut() =
init.iter().map(|pair| (pair[0].to_string(), pair[1].to_string())).collect::<Vec<_>>(); init.iter().map(|pair| (pair[0].to_string(), pair[1].to_string())).collect::<Vec<_>>();
}, },
Some(USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString::USVStringUSVStringRecord(init)) => { USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString::USVStringUSVStringRecord(init) => {
// Step 3. // Step 3.
*query.list.borrow_mut() = *query.list.borrow_mut() =
(*init).iter().map(|(name, value)| (name.to_string(), value.to_string())).collect::<Vec<_>>(); (*init).iter().map(|(name, value)| (name.to_string(), value.to_string())).collect::<Vec<_>>();
}, },
Some(USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString::USVString(init)) => { USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString::USVString(init) => {
// Step 4. // Step 4.
let init_bytes = match init.0.chars().next() { let init_bytes = match init.0.chars().next() {
Some(first_char) if first_char == '?' => { Some(first_char) if first_char == '?' => {
@ -82,8 +82,7 @@ impl URLSearchParams {
*query.list.borrow_mut() = *query.list.borrow_mut() =
form_urlencoded::parse(init_bytes).into_owned().collect(); form_urlencoded::parse(init_bytes).into_owned().collect();
}, }
None => {},
} }
// Step 5. // Step 5.

View file

@ -8,8 +8,7 @@
[Exposed=(Window,Worker)] [Exposed=(Window,Worker)]
interface URLSearchParams { interface URLSearchParams {
[Throws] constructor( [Throws] constructor(optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init = "");
optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init);
void append(USVString name, USVString value); void append(USVString name, USVString value);
void delete(USVString name); void delete(USVString name);
USVString? get(USVString name); USVString? get(USVString name);