mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
auto merge of #2143 : Ms2ger/servo/optional-primitives, r=jdm
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.
This commit is contained in:
commit
3478105da9
1 changed files with 9 additions and 7 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue