aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-04-17 16:23:04 +0200
committerMs2ger <ms2ger@gmail.com>2014-04-17 16:23:09 +0200
commitc9c96d475877ce38ffcc92cdeff76bc93b361dd3 (patch)
tree0f095947302f199f52f638bbbe31dc65558abf0b /src/components/script/dom/bindings
parent28baa1f4d1402584399abf07869b6bbfdb7c36eb (diff)
downloadservo-c9c96d475877ce38ffcc92cdeff76bc93b361dd3.tar.gz
servo-c9c96d475877ce38ffcc92cdeff76bc93b361dd3.zip
Ensure that optional primitive arguments aren't treated as nullable.
By forgetting the Some(), we caused type inference to convert to Option<T> for optional non-nullable primitive arguments, and to Option<Option<T>> for optional nullable primitive arguments (essentially the same thing). This change brings the primitive codegen in line with the DOMString codegen. Using distinct types for optionality and nullability would have prevented this issue.
Diffstat (limited to 'src/components/script/dom/bindings')
-rw-r--r--src/components/script/dom/bindings/codegen/CodegenRust.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py
index 61efa579241..9470b61fab2 100644
--- a/src/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/src/components/script/dom/bindings/codegen/CodegenRust.py
@@ -855,20 +855,22 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
if failureCode is None:
failureCode = 'return 0'
- #XXXjdm support conversionBehavior here
- template = (
- "match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
- " Ok(v) => ${declName} = v,\n"
- " Err(_) => { %s }\n"
- "}" % exceptionCode)
-
+ value = "v"
declType = CGGeneric(builtinNames[type.tag()])
if type.nullable():
declType = CGWrapper(declType, pre="Option<", post=">")
if isOptional:
+ value = "Some(%s)" % value
declType = CGWrapper(declType, pre="Option<", post=">")
+ #XXXjdm support conversionBehavior here
+ template = (
+ "match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
+ " Ok(v) => ${declName} = %s,\n"
+ " Err(_) => { %s }\n"
+ "}" % (value, exceptionCode))
+
if defaultValue is not None:
if isinstance(defaultValue, IDLNullValue):
assert type.nullable()