mirror of
https://github.com/servo/servo.git
synced 2025-06-25 09:34:32 +01:00
auto merge of #1846 : Ms2ger/servo/non-null-default, r=jdm
This commit is contained in:
commit
134d1f6fe3
3 changed files with 47 additions and 12 deletions
|
@ -1063,13 +1063,19 @@ for (uint32_t i = 0; i < length; ++i) {
|
||||||
assert(type.nullable())
|
assert(type.nullable())
|
||||||
return handleDefault(conversionCode,
|
return handleDefault(conversionCode,
|
||||||
"%s.SetNull()" % varName)
|
"%s.SetNull()" % varName)
|
||||||
return handleDefault(
|
|
||||||
conversionCode,
|
value = "str::from_utf8(data).to_owned()"
|
||||||
("static data: [u8, ..%s] = [ %s ];\n"
|
if type.nullable():
|
||||||
"%s = str::from_utf8(data).to_owned()" %
|
value = "Some(%s)" % value
|
||||||
(len(defaultValue.value) + 1,
|
|
||||||
", ".join(["'" + char + "' as u8" for char in defaultValue.value] + ["0"]),
|
default = (
|
||||||
varName)))
|
"static data: [u8, ..%s] = [ %s ];\n"
|
||||||
|
"%s = %s" %
|
||||||
|
(len(defaultValue.value) + 1,
|
||||||
|
", ".join(["'" + char + "' as u8" for char in defaultValue.value] + ["0"]),
|
||||||
|
varName, value))
|
||||||
|
|
||||||
|
return handleDefault(conversionCode, default)
|
||||||
|
|
||||||
if isMember:
|
if isMember:
|
||||||
# We have to make a copy, because our jsval may well not
|
# We have to make a copy, because our jsval may well not
|
||||||
|
@ -1255,7 +1261,6 @@ for (uint32_t i = 0; i < length; ++i) {
|
||||||
else:
|
else:
|
||||||
assert(defaultValue is None or
|
assert(defaultValue is None or
|
||||||
not isinstance(defaultValue, IDLNullValue))
|
not isinstance(defaultValue, IDLNullValue))
|
||||||
dataLoc = "${declName}"
|
|
||||||
#XXXjdm conversionBehavior should be used
|
#XXXjdm conversionBehavior should be used
|
||||||
successVal = "v"
|
successVal = "v"
|
||||||
if preSuccess or postSuccess:
|
if preSuccess or postSuccess:
|
||||||
|
@ -1263,8 +1268,8 @@ for (uint32_t i = 0; i < length; ++i) {
|
||||||
template = (
|
template = (
|
||||||
"match JSValConvertible::from_jsval(cx, ${val}) {\n"
|
"match JSValConvertible::from_jsval(cx, ${val}) {\n"
|
||||||
" Err(_) => %s,\n"
|
" Err(_) => %s,\n"
|
||||||
" Ok(v) => %s = %s\n"
|
" Ok(v) => ${declName} = %s\n"
|
||||||
"}" % (failureCode, dataLoc, successVal))
|
"}" % (failureCode, successVal))
|
||||||
declType = CGGeneric(typeName)
|
declType = CGGeneric(typeName)
|
||||||
if (defaultValue is not None and
|
if (defaultValue is not None and
|
||||||
# We already handled IDLNullValue, so just deal with the other ones
|
# We already handled IDLNullValue, so just deal with the other ones
|
||||||
|
@ -1275,12 +1280,16 @@ for (uint32_t i = 0; i < length; ++i) {
|
||||||
else:
|
else:
|
||||||
assert(tag == IDLType.Tags.bool)
|
assert(tag == IDLType.Tags.bool)
|
||||||
defaultStr = toStringBool(defaultValue.value)
|
defaultStr = toStringBool(defaultValue.value)
|
||||||
|
|
||||||
|
if type.nullable():
|
||||||
|
defaultStr = "Some(%s)" % defaultStr
|
||||||
|
|
||||||
template = CGWrapper(CGIndenter(CGGeneric(template)),
|
template = CGWrapper(CGIndenter(CGGeneric(template)),
|
||||||
pre="if ${haveValue} {\n",
|
pre="if ${haveValue} {\n",
|
||||||
post=("\n"
|
post=("\n"
|
||||||
"} else {\n"
|
"} else {\n"
|
||||||
" %s = %s;\n"
|
" ${declName} = %s;\n"
|
||||||
"}" % (dataLoc, defaultStr))).define()
|
"}" % defaultStr)).define()
|
||||||
|
|
||||||
initialVal = "false" if typeName == "bool" else ("0 as %s" % typeName)
|
initialVal = "false" if typeName == "bool" else ("0 as %s" % typeName)
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
|
|
|
@ -122,6 +122,19 @@ impl TestBinding {
|
||||||
pub fn PassOptionalNullableDoubleWithDefault(&self, _: Option<f64>) {}
|
pub fn PassOptionalNullableDoubleWithDefault(&self, _: Option<f64>) {}
|
||||||
// pub fn PassOptionalNullableStringWithDefault(&self, _: Option<DOMString>) {}
|
// pub fn PassOptionalNullableStringWithDefault(&self, _: Option<DOMString>) {}
|
||||||
pub fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<JS<Blob>>) {}
|
pub fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<JS<Blob>>) {}
|
||||||
|
|
||||||
|
pub fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
|
||||||
|
pub fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
|
||||||
|
pub fn PassOptionalNullableOctetWithNonNullDefault(&self, _: Option<u8>) {}
|
||||||
|
pub fn PassOptionalNullableShortWithNonNullDefault(&self, _: Option<i16>) {}
|
||||||
|
pub fn PassOptionalNullableUnsignedShortWithNonNullDefault(&self, _: Option<u16>) {}
|
||||||
|
pub fn PassOptionalNullableLongWithNonNullDefault(&self, _: Option<i32>) {}
|
||||||
|
pub fn PassOptionalNullableUnsignedLongWithNonNullDefault(&self, _: Option<u32>) {}
|
||||||
|
pub fn PassOptionalNullableLongLongWithNonNullDefault(&self, _: Option<i64>) {}
|
||||||
|
pub fn PassOptionalNullableUnsignedLongLongWithNonNullDefault(&self, _: Option<u64>) {}
|
||||||
|
// pub fn PassOptionalNullableFloatWithNonNullDefault(&self, _: Option<f32>) {}
|
||||||
|
// pub fn PassOptionalNullableDoubleWithNonNullDefault(&self, _: Option<f64>) {}
|
||||||
|
pub fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option<DOMString>) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reflectable for TestBinding {
|
impl Reflectable for TestBinding {
|
||||||
|
|
|
@ -82,4 +82,17 @@ interface TestBinding {
|
||||||
void passOptionalNullableUnsignedLongLongWithDefault(optional unsigned long long? arg = null);
|
void passOptionalNullableUnsignedLongLongWithDefault(optional unsigned long long? arg = null);
|
||||||
// void passOptionalNullableStringWithDefault(optional DOMString? arg = null);
|
// void passOptionalNullableStringWithDefault(optional DOMString? arg = null);
|
||||||
void passOptionalNullableInterfaceWithDefault(optional Blob? arg = null);
|
void passOptionalNullableInterfaceWithDefault(optional Blob? arg = null);
|
||||||
|
|
||||||
|
void passOptionalNullableBooleanWithNonNullDefault(optional boolean? arg = false);
|
||||||
|
void passOptionalNullableByteWithNonNullDefault(optional byte? arg = 7);
|
||||||
|
void passOptionalNullableOctetWithNonNullDefault(optional octet? arg = 7);
|
||||||
|
void passOptionalNullableShortWithNonNullDefault(optional short? arg = 7);
|
||||||
|
void passOptionalNullableUnsignedShortWithNonNullDefault(optional unsigned short? arg = 7);
|
||||||
|
void passOptionalNullableLongWithNonNullDefault(optional long? arg = 7);
|
||||||
|
void passOptionalNullableUnsignedLongWithNonNullDefault(optional unsigned long? arg = 7);
|
||||||
|
void passOptionalNullableLongLongWithNonNullDefault(optional long long? arg = 7);
|
||||||
|
void passOptionalNullableUnsignedLongLongWithNonNullDefault(optional unsigned long long? arg = 7);
|
||||||
|
// void passOptionalNullableFloatWithNonNullDefault(optional float? arg = 0.0);
|
||||||
|
// void passOptionalNullableDoubleWithNonNullDefault(optional double? arg = 0.0);
|
||||||
|
void passOptionalNullableStringWithNonNullDefault(optional DOMString? arg = "");
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue