Avoid a type error with a non-null default value for an optional nullable string argument.

This commit is contained in:
Ms2ger 2014-03-06 22:42:26 +01:00
parent 716e1ce144
commit 54a59b9d38
3 changed files with 15 additions and 9 deletions

View file

@ -1063,13 +1063,19 @@ for (uint32_t i = 0; i < length; ++i) {
assert(type.nullable())
return handleDefault(conversionCode,
"%s.SetNull()" % varName)
return handleDefault(
conversionCode,
("static data: [u8, ..%s] = [ %s ];\n"
"%s = str::from_utf8(data).to_owned()" %
value = "str::from_utf8(data).to_owned()"
if type.nullable():
value = "Some(%s)" % value
default = (
"static data: [u8, ..%s] = [ %s ];\n"
"%s = %s" %
(len(defaultValue.value) + 1,
", ".join(["'" + char + "' as u8" for char in defaultValue.value] + ["0"]),
varName)))
varName, value))
return handleDefault(conversionCode, default)
if isMember:
# We have to make a copy, because our jsval may well not

View file

@ -134,7 +134,7 @@ impl TestBinding {
pub fn PassOptionalNullableUnsignedLongLongWithNonNullDefault(&self, _: Option<u64>) {}
// pub fn PassOptionalNullableFloatWithNonNullDefault(&self, _: Option<f32>) {}
// pub fn PassOptionalNullableDoubleWithNonNullDefault(&self, _: Option<f64>) {}
// pub fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option<DOMString>) {}
pub fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option<DOMString>) {}
}
impl Reflectable for TestBinding {

View file

@ -94,5 +94,5 @@ interface TestBinding {
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 = "");
void passOptionalNullableStringWithNonNullDefault(optional DOMString? arg = "");
};