mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
auto merge of #2622 : Ms2ger/servo/variadic, r=jdm
This commit is contained in:
commit
1d35650d4f
3 changed files with 87 additions and 23 deletions
|
@ -551,10 +551,6 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
|||
raise TypeError("Can't handle sequence arguments yet")
|
||||
|
||||
if type.isUnion():
|
||||
if isMember:
|
||||
raise TypeError("Can't handle unions as members, we have a "
|
||||
"holderType")
|
||||
|
||||
declType = CGGeneric(type.name + "::" + type.name)
|
||||
if type.nullable():
|
||||
declType = CGWrapper(declType, pre="Option<", post=" >")
|
||||
|
@ -890,9 +886,6 @@ class CGArgumentConverter(CGThing):
|
|||
def __init__(self, argument, index, argv, argc, descriptorProvider,
|
||||
invalidEnumValueFatal=True):
|
||||
CGThing.__init__(self)
|
||||
if argument.variadic:
|
||||
raise TypeError("We don't support variadic arguments yet " +
|
||||
str(argument.location))
|
||||
assert(not argument.defaultValue or argument.optional)
|
||||
|
||||
replacer = {
|
||||
|
@ -914,26 +907,57 @@ class CGArgumentConverter(CGThing):
|
|||
treatNullAs=argument.treatNullAs,
|
||||
isEnforceRange=argument.enforceRange,
|
||||
isClamp=argument.clamp,
|
||||
isMember="Variadic" if argument.variadic else False,
|
||||
allowTreatNonObjectAsNull=argument.allowTreatNonCallableAsNull())
|
||||
|
||||
if argument.optional:
|
||||
if argument.defaultValue:
|
||||
assert default
|
||||
template = CGIfElseWrapper(condition,
|
||||
CGGeneric(template),
|
||||
CGGeneric(default)).define()
|
||||
if not argument.variadic:
|
||||
if argument.optional:
|
||||
if argument.defaultValue:
|
||||
assert default
|
||||
template = CGIfElseWrapper(condition,
|
||||
CGGeneric(template),
|
||||
CGGeneric(default)).define()
|
||||
else:
|
||||
assert not default
|
||||
declType = CGWrapper(declType, pre="Option<", post=">")
|
||||
template = CGIfElseWrapper(condition,
|
||||
CGGeneric("Some(%s)" % template),
|
||||
CGGeneric("None")).define()
|
||||
else:
|
||||
assert not default
|
||||
declType = CGWrapper(declType, pre="Option<", post=">")
|
||||
template = CGIfElseWrapper(condition,
|
||||
CGGeneric("Some(%s)" % template),
|
||||
CGGeneric("None")).define()
|
||||
else:
|
||||
assert not default
|
||||
|
||||
self.converter = instantiateJSToNativeConversionTemplate(
|
||||
template, replacementVariables, declType, "arg%d" % index,
|
||||
needsRooting)
|
||||
self.converter = instantiateJSToNativeConversionTemplate(
|
||||
template, replacementVariables, declType, "arg%d" % index,
|
||||
needsRooting)
|
||||
else:
|
||||
assert argument.optional
|
||||
variadicConversion = {
|
||||
"val": string.Template("(*${argv}.offset(variadicArg as int))").substitute(replacer),
|
||||
}
|
||||
innerConverter = instantiateJSToNativeConversionTemplate(
|
||||
template, variadicConversion, declType, "slot",
|
||||
needsRooting)
|
||||
|
||||
seqType = CGTemplatedType("Vec", declType)
|
||||
variadicConversion = string.Template(
|
||||
"{\n"
|
||||
" let mut vector: ${seqType} = Vec::with_capacity((${argc} - ${index}) as uint);\n"
|
||||
" for variadicArg in range(${index}, ${argc}) {\n"
|
||||
"${inner}\n"
|
||||
" vector.push(slot);\n"
|
||||
" }\n"
|
||||
" vector\n"
|
||||
"}"
|
||||
).substitute({
|
||||
"index": index,
|
||||
"argc": argc,
|
||||
"seqType": seqType.define(),
|
||||
"inner": CGIndenter(innerConverter, 4).define(),
|
||||
})
|
||||
|
||||
self.converter = instantiateJSToNativeConversionTemplate(
|
||||
variadicConversion, replacementVariables, seqType, "arg%d" % index,
|
||||
False)
|
||||
|
||||
def define(self):
|
||||
return self.converter.define()
|
||||
|
@ -4023,7 +4047,7 @@ class CGDictionary(CGThing):
|
|||
(member,
|
||||
getJSToNativeConversionTemplate(member.type,
|
||||
descriptorProvider,
|
||||
isMember=True,
|
||||
isMember="Dictionary",
|
||||
defaultValue=member.defaultValue,
|
||||
failureCode="return Err(());",
|
||||
exceptionCode="return Err(());"))
|
||||
|
|
|
@ -255,6 +255,26 @@ pub trait TestBindingMethods {
|
|||
// fn PassOptionalNullableDoubleWithNonNullDefault(&self, _: Option<f64>) {}
|
||||
fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option<DOMString>) {}
|
||||
// fn PassOptionalNullableEnumWithNonNullDefault(&self, _: Option<TestEnum>) {}
|
||||
|
||||
fn PassVariadicBoolean(&self, _: Vec<bool>) {}
|
||||
fn PassVariadicByte(&self, _: Vec<i8>) {}
|
||||
fn PassVariadicOctet(&self, _: Vec<u8>) {}
|
||||
fn PassVariadicShort(&self, _: Vec<i16>) {}
|
||||
fn PassVariadicUnsignedShort(&self, _: Vec<u16>) {}
|
||||
fn PassVariadicLong(&self, _: Vec<i32>) {}
|
||||
fn PassVariadicUnsignedLong(&self, _: Vec<u32>) {}
|
||||
fn PassVariadicLongLong(&self, _: Vec<i64>) {}
|
||||
fn PassVariadicUnsignedLongLong(&self, _: Vec<u64>) {}
|
||||
fn PassVariadicFloat(&self, _: Vec<f32>) {}
|
||||
fn PassVariadicDouble(&self, _: Vec<f64>) {}
|
||||
fn PassVariadicString(&self, _: Vec<DOMString>) {}
|
||||
fn PassVariadicByteString(&self, _: Vec<ByteString>) {}
|
||||
fn PassVariadicEnum(&self, _: Vec<TestEnum>) {}
|
||||
// fn PassVariadicInterface(&self, _: Vec<JSRef<Blob>>) {}
|
||||
fn PassVariadicUnion(&self, _: Vec<HTMLElementOrLong>) {}
|
||||
fn PassVariadicUnion2(&self, _: Vec<EventOrString>) {}
|
||||
fn PassVariadicUnion3(&self, _: Vec<BlobOrString>) {}
|
||||
fn PassVariadicAny(&self, _: *mut JSContext, _: Vec<JSVal>) {}
|
||||
}
|
||||
|
||||
impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
||||
|
|
|
@ -246,4 +246,24 @@ interface TestBinding {
|
|||
// void passOptionalNullableEnumWithNonNullDefault(optional TestEnum? arg = "foo");
|
||||
// void passOptionalNullableUnionWithNonNullDefault(optional (HTMLElement or long)? arg = 7);
|
||||
// void passOptionalNullableUnion2WithNonNullDefault(optional (Event or DOMString)? data = "foo");
|
||||
|
||||
void passVariadicBoolean(boolean... args);
|
||||
void passVariadicByte(byte... args);
|
||||
void passVariadicOctet(octet... args);
|
||||
void passVariadicShort(short... args);
|
||||
void passVariadicUnsignedShort(unsigned short... args);
|
||||
void passVariadicLong(long... args);
|
||||
void passVariadicUnsignedLong(unsigned long... args);
|
||||
void passVariadicLongLong(long long... args);
|
||||
void passVariadicUnsignedLongLong(unsigned long long... args);
|
||||
void passVariadicFloat(float... args);
|
||||
void passVariadicDouble(double... args);
|
||||
void passVariadicString(DOMString... args);
|
||||
void passVariadicByteString(ByteString... args);
|
||||
void passVariadicEnum(TestEnum... args);
|
||||
// void passVariadicInterface(Blob... args);
|
||||
void passVariadicUnion((HTMLElement or long)... args);
|
||||
void passVariadicUnion2((Event or DOMString)... args);
|
||||
void passVariadicUnion3((Blob or DOMString)... args);
|
||||
void passVariadicAny(any... args);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue