mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Use handleOptional for the DOMString conversion.
This commit is contained in:
parent
b73a87e955
commit
13e26e0fe0
1 changed files with 4 additions and 13 deletions
|
@ -658,16 +658,12 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
else:
|
else:
|
||||||
nullBehavior = treatAs[treatNullAs]
|
nullBehavior = treatAs[treatNullAs]
|
||||||
|
|
||||||
def getConversionCode(isOptional=False):
|
def getConversionCode():
|
||||||
strval = "strval"
|
|
||||||
if isOptional:
|
|
||||||
strval = "Some(%s)" % strval
|
|
||||||
|
|
||||||
conversionCode = (
|
conversionCode = (
|
||||||
"match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
|
"match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
|
||||||
" Ok(strval) => %s,\n"
|
" Ok(strval) => strval,\n"
|
||||||
" Err(_) => { %s },\n"
|
" Err(_) => { %s },\n"
|
||||||
"}" % (nullBehavior, strval, exceptionCode))
|
"}" % (nullBehavior, exceptionCode))
|
||||||
|
|
||||||
if defaultValue is None:
|
if defaultValue is None:
|
||||||
return conversionCode
|
return conversionCode
|
||||||
|
@ -690,15 +686,10 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
return handleDefault(conversionCode, default)
|
return handleDefault(conversionCode, default)
|
||||||
|
|
||||||
declType = "DOMString"
|
declType = "DOMString"
|
||||||
initialValue = None
|
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
declType = "Option<%s>" % declType
|
declType = "Option<%s>" % declType
|
||||||
|
|
||||||
if isOptional:
|
return handleOptional(getConversionCode(), CGGeneric(declType), isOptional)
|
||||||
declType = "Option<%s>" % declType
|
|
||||||
initialValue = "None"
|
|
||||||
|
|
||||||
return (getConversionCode(isOptional), CGGeneric(declType), False, initialValue)
|
|
||||||
|
|
||||||
if type.isEnum():
|
if type.isEnum():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue