aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-03-06 22:56:10 +0100
committerMs2ger <ms2ger@gmail.com>2014-03-06 22:56:10 +0100
commit9fba4bcfbaa966b360159eb4d897276074caffcb (patch)
tree0bbf0d34e79e1e904fecc6ca86dc52fd69ed649e /src/components/script/dom
parent922d191948702509eb026edf8e86f853f9d004c2 (diff)
downloadservo-9fba4bcfbaa966b360159eb4d897276074caffcb.tar.gz
servo-9fba4bcfbaa966b360159eb4d897276074caffcb.zip
Simplify the code flow in the conversion to primitive types so that default values are handled together.
Diffstat (limited to 'src/components/script/dom')
-rw-r--r--src/components/script/dom/bindings/codegen/CodegenRust.py47
1 files changed, 22 insertions, 25 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py
index b08a209a879..25b92afcecc 100644
--- a/src/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/src/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1249,39 +1249,36 @@ for (uint32_t i = 0; i < length; ++i) {
"}" % (successVal, failureCode))
if type.nullable():
- if defaultValue is not None and isinstance(defaultValue, IDLNullValue):
+ declType = CGGeneric("Option<" + typeName + ">")
+ else:
+ declType = CGGeneric(typeName)
+
+ if defaultValue is not None:
+ if isinstance(defaultValue, IDLNullValue):
+ assert type.nullable()
template = CGWrapper(CGIndenter(CGGeneric(template)),
pre="if ${haveValue} {\n",
post=("\n"
"} else {\n"
" ${declName} = None;\n"
"}")).define()
-
- declType = CGGeneric("Option<" + typeName + ">")
- else:
- assert(defaultValue is None or
- not isinstance(defaultValue, IDLNullValue))
- declType = CGGeneric(typeName)
-
- if (defaultValue is not None and
- # We already handled IDLNullValue, so just deal with the other ones
- not isinstance(defaultValue, IDLNullValue)):
- tag = defaultValue.type.tag()
- if tag in numericTags:
- defaultStr = defaultValue.value
else:
- assert(tag == IDLType.Tags.bool)
- defaultStr = toStringBool(defaultValue.value)
+ tag = defaultValue.type.tag()
+ if tag in numericTags:
+ defaultStr = defaultValue.value
+ else:
+ assert(tag == IDLType.Tags.bool)
+ defaultStr = toStringBool(defaultValue.value)
- if type.nullable():
- defaultStr = "Some(%s)" % defaultStr
-
- template = CGWrapper(CGIndenter(CGGeneric(template)),
- pre="if ${haveValue} {\n",
- post=("\n"
- "} else {\n"
- " ${declName} = %s;\n"
- "}" % defaultStr)).define()
+ if type.nullable():
+ defaultStr = "Some(%s)" % defaultStr
+
+ template = CGWrapper(CGIndenter(CGGeneric(template)),
+ pre="if ${haveValue} {\n",
+ post=("\n"
+ "} else {\n"
+ " ${declName} = %s;\n"
+ "}" % defaultStr)).define()
initialVal = "false" if typeName == "bool" else ("0 as %s" % typeName)
if type.nullable():