Support USVString as default value of a union argument

This commit is contained in:
Kagami Sascha Rosylight 2019-10-17 12:06:41 +09:00
parent c5d6bb604d
commit e905a4606a
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)" % (
union_native_type(type),
"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:
raise("We don't currently support default values that aren't null, boolean or default dictionary")
elif dictionaries:

View file

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

View file

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