mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Remove the holderType return value of getJSToNativeConversionTemplate.
It is always None.
This commit is contained in:
parent
691d82a92f
commit
06df422718
1 changed files with 15 additions and 46 deletions
|
@ -469,10 +469,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
2) A CGThing representing the native C++ type we're converting to
|
2) A CGThing representing the native C++ type we're converting to
|
||||||
(declType). This is allowed to be None if the conversion code is
|
(declType). This is allowed to be None if the conversion code is
|
||||||
supposed to be used as-is.
|
supposed to be used as-is.
|
||||||
3) A CGThing representing the type of a "holder" (holderType) which will
|
3) A boolean indicating whether the caller has to do optional-argument handling.
|
||||||
hold a possible reference to the C++ thing whose type we returned in #1,
|
|
||||||
or None if no such holder is needed.
|
|
||||||
4) A boolean indicating whether the caller has to do optional-argument handling.
|
|
||||||
This will only be true if isOptional is true and if the returned template
|
This will only be true if isOptional is true and if the returned template
|
||||||
expects both declType and holderType to be wrapped in Optional<>, with
|
expects both declType and holderType to be wrapped in Optional<>, with
|
||||||
${declName} and ${holderName} adjusted to point to the Value() of the
|
${declName} and ${holderName} adjusted to point to the Value() of the
|
||||||
|
@ -598,7 +595,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
templateBody = handleDefaultNull(templateBody.define(),
|
templateBody = handleDefaultNull(templateBody.define(),
|
||||||
"None")
|
"None")
|
||||||
|
|
||||||
return (templateBody, declType, None, isOptional, "None" if isOptional else None)
|
return (templateBody, declType, isOptional, "None" if isOptional else None)
|
||||||
|
|
||||||
if type.isGeckoInterface():
|
if type.isGeckoInterface():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
@ -613,7 +610,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
|
|
||||||
template = wrapObjectTemplate(conversion, isDefinitelyObject, type,
|
template = wrapObjectTemplate(conversion, isDefinitelyObject, type,
|
||||||
failureCode)
|
failureCode)
|
||||||
return (template, declType, None, isOptional, None)
|
return (template, declType, isOptional, None)
|
||||||
|
|
||||||
templateBody = ""
|
templateBody = ""
|
||||||
if descriptor.interface.isConsequential():
|
if descriptor.interface.isConsequential():
|
||||||
|
@ -640,7 +637,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
if type.nullable() or isOptional:
|
if type.nullable() or isOptional:
|
||||||
declType = CGWrapper(declType, pre="Option<", post=">")
|
declType = CGWrapper(declType, pre="Option<", post=">")
|
||||||
|
|
||||||
return (templateBody, declType, None, isOptional, "None" if isOptional else None)
|
return (templateBody, declType, isOptional, "None" if isOptional else None)
|
||||||
|
|
||||||
if type.isSpiderMonkeyInterface():
|
if type.isSpiderMonkeyInterface():
|
||||||
raise TypeError("Can't handle SpiderMonkey interface arguments yet")
|
raise TypeError("Can't handle SpiderMonkey interface arguments yet")
|
||||||
|
@ -699,11 +696,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
declType = "Option<%s>" % declType
|
declType = "Option<%s>" % declType
|
||||||
initialValue = "None"
|
initialValue = "None"
|
||||||
|
|
||||||
return (
|
return (getConversionCode(isOptional), CGGeneric(declType), False, initialValue)
|
||||||
getConversionCode(isOptional),
|
|
||||||
CGGeneric(declType), None, #CGGeneric("FakeDependentString"),
|
|
||||||
False,
|
|
||||||
initialValue)
|
|
||||||
|
|
||||||
if type.isEnum():
|
if type.isEnum():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
@ -736,7 +729,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
(enum,
|
(enum,
|
||||||
getEnumValueName(defaultValue.value))))
|
getEnumValueName(defaultValue.value))))
|
||||||
|
|
||||||
return (template, CGGeneric(enum), None, isOptional, None)
|
return (template, CGGeneric(enum), isOptional, None)
|
||||||
|
|
||||||
if type.isCallback():
|
if type.isCallback():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
@ -756,7 +749,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
"} else {\n"
|
"} else {\n"
|
||||||
" ${declName} = NULL;\n"
|
" ${declName} = NULL;\n"
|
||||||
"}" % haveCallable,
|
"}" % haveCallable,
|
||||||
CGGeneric("JSObject*"), None, isOptional, None)
|
CGGeneric("JSObject*"), isOptional, None)
|
||||||
|
|
||||||
if type.isAny():
|
if type.isAny():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
@ -768,7 +761,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
value = CGWrapper(value, pre="Some(", post=")")
|
value = CGWrapper(value, pre="Some(", post=")")
|
||||||
|
|
||||||
templateBody = handleDefaultNull(value.define(), "NullValue()")
|
templateBody = handleDefaultNull(value.define(), "NullValue()")
|
||||||
return (templateBody, declType, None, isOptional, "None" if isOptional else None)
|
return (templateBody, declType, isOptional, "None" if isOptional else None)
|
||||||
|
|
||||||
if type.isObject():
|
if type.isObject():
|
||||||
raise TypeError("Can't handle object arguments yet")
|
raise TypeError("Can't handle object arguments yet")
|
||||||
|
@ -799,13 +792,13 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
" Err(_) => return 0,\n"
|
" Err(_) => return 0,\n"
|
||||||
"}" % (typeName, val))
|
"}" % (typeName, val))
|
||||||
|
|
||||||
return (template, declType, None, False, None)
|
return (template, declType, False, None)
|
||||||
|
|
||||||
if type.isVoid():
|
if type.isVoid():
|
||||||
assert not isOptional
|
assert not isOptional
|
||||||
# This one only happens for return values, and its easy: Just
|
# This one only happens for return values, and its easy: Just
|
||||||
# ignore the jsval.
|
# ignore the jsval.
|
||||||
return ("", None, None, False, None)
|
return ("", None, False, None)
|
||||||
|
|
||||||
if not type.isPrimitive():
|
if not type.isPrimitive():
|
||||||
raise TypeError("Need conversion for argument type '%s'" % str(type))
|
raise TypeError("Need conversion for argument type '%s'" % str(type))
|
||||||
|
@ -850,7 +843,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
CGGeneric(template),
|
CGGeneric(template),
|
||||||
CGGeneric(defaultStr)).define()
|
CGGeneric(defaultStr)).define()
|
||||||
|
|
||||||
return (template, declType, None, isOptional, "None" if isOptional else None)
|
return (template, declType, isOptional, "None" if isOptional else None)
|
||||||
|
|
||||||
def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
|
def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
|
||||||
argcAndIndex=None):
|
argcAndIndex=None):
|
||||||
|
@ -863,7 +856,7 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
|
||||||
replace ${argc} and ${index}, where ${index} is the index of this
|
replace ${argc} and ${index}, where ${index} is the index of this
|
||||||
argument (0-based) and ${argc} is the total number of arguments.
|
argument (0-based) and ${argc} is the total number of arguments.
|
||||||
"""
|
"""
|
||||||
(templateBody, declType, holderType, dealWithOptional, initialValue) = templateTuple
|
(templateBody, declType, dealWithOptional, initialValue) = templateTuple
|
||||||
|
|
||||||
if dealWithOptional and argcAndIndex is None:
|
if dealWithOptional and argcAndIndex is None:
|
||||||
raise TypeError("Have to deal with optional things, but don't know how")
|
raise TypeError("Have to deal with optional things, but don't know how")
|
||||||
|
@ -872,25 +865,6 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
|
||||||
"outside the check for big enough arg count!");
|
"outside the check for big enough arg count!");
|
||||||
|
|
||||||
result = CGList([], "\n")
|
result = CGList([], "\n")
|
||||||
# Make a copy of "replacements" since we may be about to start modifying it
|
|
||||||
replacements = dict(replacements)
|
|
||||||
originalHolderName = replacements["holderName"]
|
|
||||||
if holderType is not None:
|
|
||||||
if dealWithOptional:
|
|
||||||
replacements["holderName"] = (
|
|
||||||
"const_cast< %s & >(%s.Value())" %
|
|
||||||
(holderType.define(), originalHolderName))
|
|
||||||
mutableHolderType = CGWrapper(holderType, pre="Optional< ", post=" >")
|
|
||||||
holderType = CGWrapper(mutableHolderType, pre="const ")
|
|
||||||
tmpresult = [CGGeneric("let "),
|
|
||||||
CGGeneric(originalHolderName),
|
|
||||||
CGGeneric(": "),
|
|
||||||
holderType]
|
|
||||||
if initialValue:
|
|
||||||
tmpresult += [CGGeneric(" = "),
|
|
||||||
initialValue]
|
|
||||||
tmpresult += [CGGeneric(";")]
|
|
||||||
result.append(CGList(tmpresult))
|
|
||||||
|
|
||||||
conversion = CGGeneric(
|
conversion = CGGeneric(
|
||||||
string.Template(templateBody).substitute(replacements)
|
string.Template(templateBody).substitute(replacements)
|
||||||
|
@ -2825,8 +2799,7 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
|
||||||
name = type.name
|
name = type.name
|
||||||
typeName = "/*" + type.name + "*/"
|
typeName = "/*" + type.name + "*/"
|
||||||
|
|
||||||
(template, _, holderType,
|
(template, _, _, _) = getJSToNativeConversionTemplate(
|
||||||
dealWithOptional, initialValue) = getJSToNativeConversionTemplate(
|
|
||||||
type, descriptorProvider, failureCode="return Ok(None);",
|
type, descriptorProvider, failureCode="return Ok(None);",
|
||||||
exceptionCode='return Err(());',
|
exceptionCode='return Err(());',
|
||||||
isDefinitelyObject=True, isOptional=False)
|
isDefinitelyObject=True, isOptional=False)
|
||||||
|
@ -4177,19 +4150,15 @@ class CGDictionary(CGThing):
|
||||||
|
|
||||||
def getMemberType(self, memberInfo):
|
def getMemberType(self, memberInfo):
|
||||||
(member, (templateBody, declType,
|
(member, (templateBody, declType,
|
||||||
holderType, dealWithOptional, initialValue)) = memberInfo
|
dealWithOptional, initialValue)) = memberInfo
|
||||||
# We can't handle having a holderType here
|
|
||||||
assert holderType is None
|
|
||||||
if dealWithOptional:
|
if dealWithOptional:
|
||||||
declType = CGWrapper(declType, pre="Optional< ", post=" >")
|
declType = CGWrapper(declType, pre="Optional< ", post=" >")
|
||||||
return declType.define()
|
return declType.define()
|
||||||
|
|
||||||
def getMemberConversion(self, memberInfo):
|
def getMemberConversion(self, memberInfo):
|
||||||
(member, (templateBody, declType,
|
(member, (templateBody, declType,
|
||||||
holderType, dealWithOptional, initialValue)) = memberInfo
|
dealWithOptional, initialValue)) = memberInfo
|
||||||
replacements = { "val": "value.unwrap()" }
|
replacements = { "val": "value.unwrap()" }
|
||||||
# We can't handle having a holderType here
|
|
||||||
assert holderType is None
|
|
||||||
if member.defaultValue:
|
if member.defaultValue:
|
||||||
replacements["haveValue"] = "value.is_some()"
|
replacements["haveValue"] = "value.is_some()"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue