mirror of
https://github.com/servo/servo.git
synced 2025-06-16 12:24:29 +00:00
Implement support for returning nullable primitive types.
This commit is contained in:
parent
3d28f31ea9
commit
d063601ba0
3 changed files with 38 additions and 3 deletions
|
@ -1601,9 +1601,9 @@ if %(resultStr)s.is_null() {
|
|||
|
||||
if type.nullable():
|
||||
(recTemplate, recInfal) = getWrapTemplateForType(type.inner, descriptorProvider,
|
||||
"%s.Value()" % result, successCode,
|
||||
"%s.unwrap()" % result, successCode,
|
||||
isCreator, exceptionCode)
|
||||
return ("if (%s.IsNull()) {\n" % result +
|
||||
return ("if (%s.is_none()) {\n" % result +
|
||||
CGIndenter(CGGeneric(setValue("JSVAL_NULL"))).define() + "\n" +
|
||||
"}\n" + recTemplate, recInfal)
|
||||
|
||||
|
@ -1667,7 +1667,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
|
|||
if returnType.isPrimitive() and returnType.tag() in builtinNames:
|
||||
result = CGGeneric(builtinNames[returnType.tag()])
|
||||
if returnType.nullable():
|
||||
result = CGWrapper(result, pre="Nullable<", post=">")
|
||||
result = CGWrapper(result, pre="Option<", post=">")
|
||||
return result, False
|
||||
if returnType.isString():
|
||||
result = CGGeneric("DOMString")
|
||||
|
|
|
@ -32,6 +32,29 @@ impl TestBinding {
|
|||
pub fn SetFloatAttribute(&self, _: f32) {}
|
||||
pub fn DoubleAttribute(&self) -> f64 { 0. }
|
||||
pub fn SetDoubleAttribute(&self, _: f64) {}
|
||||
|
||||
pub fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) }
|
||||
pub fn SetBooleanAttributeNullable(&self, _: Option<bool>) {}
|
||||
pub fn GetByteAttributeNullable(&self) -> Option<i8> { Some(0) }
|
||||
pub fn SetByteAttributeNullable(&self, _: Option<i8>) {}
|
||||
pub fn GetOctetAttributeNullable(&self) -> Option<u8> { Some(0) }
|
||||
pub fn SetOctetAttributeNullable(&self, _: Option<u8>) {}
|
||||
pub fn GetShortAttributeNullable(&self) -> Option<i16> { Some(0) }
|
||||
pub fn SetShortAttributeNullable(&self, _: Option<i16>) {}
|
||||
pub fn GetUnsignedShortAttributeNullable(&self) -> Option<u16> { Some(0) }
|
||||
pub fn SetUnsignedShortAttributeNullable(&self, _: Option<u16>) {}
|
||||
pub fn GetLongAttributeNullable(&self) -> Option<i32> { Some(0) }
|
||||
pub fn SetLongAttributeNullable(&self, _: Option<i32>) {}
|
||||
pub fn GetUnsignedLongAttributeNullable(&self) -> Option<u32> { Some(0) }
|
||||
pub fn SetUnsignedLongAttributeNullable(&self, _: Option<u32>) {}
|
||||
pub fn GetLongLongAttributeNullable(&self) -> Option<i64> { Some(0) }
|
||||
pub fn SetLongLongAttributeNullable(&self, _: Option<i64>) {}
|
||||
pub fn GetUnsignedLongLongAttributeNullable(&self) -> Option<u64> { Some(0) }
|
||||
pub fn SetUnsignedLongLongAttributeNullable(&self, _: Option<u64>) {}
|
||||
pub fn GetFloatAttributeNullable(&self) -> Option<f32> { Some(0.) }
|
||||
pub fn SetFloatAttributeNullable(&self, _: Option<f32>) {}
|
||||
pub fn GetDoubleAttributeNullable(&self) -> Option<f64> { Some(0.) }
|
||||
pub fn SetDoubleAttributeNullable(&self, _: Option<f64>) {}
|
||||
}
|
||||
|
||||
impl Reflectable for TestBinding {
|
||||
|
|
|
@ -14,4 +14,16 @@ interface TestBinding {
|
|||
attribute unsigned long long unsignedLongLongAttribute;
|
||||
attribute float floatAttribute;
|
||||
attribute double doubleAttribute;
|
||||
|
||||
attribute boolean? booleanAttributeNullable;
|
||||
attribute byte? byteAttributeNullable;
|
||||
attribute octet? octetAttributeNullable;
|
||||
attribute short? shortAttributeNullable;
|
||||
attribute unsigned short? unsignedShortAttributeNullable;
|
||||
attribute long? longAttributeNullable;
|
||||
attribute unsigned long? unsignedLongAttributeNullable;
|
||||
attribute long long? longLongAttributeNullable;
|
||||
attribute unsigned long long? unsignedLongLongAttributeNullable;
|
||||
attribute float? floatAttributeNullable;
|
||||
attribute double? doubleAttributeNullable;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue