mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Unify argument auto rooting in codegen
This commit is contained in:
parent
c42127b683
commit
2437a8472e
1 changed files with 8 additions and 11 deletions
|
@ -418,15 +418,12 @@ class CGMethodCall(CGThing):
|
||||||
template = info.template
|
template = info.template
|
||||||
declType = info.declType
|
declType = info.declType
|
||||||
|
|
||||||
argName = "arg%d" % distinguishingIndex
|
|
||||||
|
|
||||||
testCode = instantiateJSToNativeConversionTemplate(
|
testCode = instantiateJSToNativeConversionTemplate(
|
||||||
template,
|
template,
|
||||||
{"val": distinguishingArg},
|
{"val": distinguishingArg},
|
||||||
declType,
|
declType,
|
||||||
argName)
|
"arg%d" % distinguishingIndex,
|
||||||
if type_needs_auto_root(type):
|
needsAutoRoot=type_needs_auto_root(type))
|
||||||
testCode.append(CGGeneric("auto_root!(in(cx) let %s = %s);" % (argName, argName)))
|
|
||||||
|
|
||||||
# Indent by 4, since we need to indent further than our "do" statement
|
# Indent by 4, since we need to indent further than our "do" statement
|
||||||
caseBody.append(CGIndenter(testCode, 4))
|
caseBody.append(CGIndenter(testCode, 4))
|
||||||
|
@ -1215,7 +1212,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
|
|
||||||
|
|
||||||
def instantiateJSToNativeConversionTemplate(templateBody, replacements,
|
def instantiateJSToNativeConversionTemplate(templateBody, replacements,
|
||||||
declType, declName):
|
declType, declName,
|
||||||
|
needsAutoRoot=False):
|
||||||
"""
|
"""
|
||||||
Take the templateBody and declType as returned by
|
Take the templateBody and declType as returned by
|
||||||
getJSToNativeConversionInfo, a set of replacements as required by the
|
getJSToNativeConversionInfo, a set of replacements as required by the
|
||||||
|
@ -1240,6 +1238,8 @@ def instantiateJSToNativeConversionTemplate(templateBody, replacements,
|
||||||
else:
|
else:
|
||||||
result.append(conversion)
|
result.append(conversion)
|
||||||
|
|
||||||
|
if needsAutoRoot:
|
||||||
|
result.append(CGGeneric("auto_root!(in(cx) let %s = %s);" % (declName, declName)))
|
||||||
# Add an empty CGGeneric to get an extra newline after the argument
|
# Add an empty CGGeneric to get an extra newline after the argument
|
||||||
# conversion.
|
# conversion.
|
||||||
result.append(CGGeneric(""))
|
result.append(CGGeneric(""))
|
||||||
|
@ -1322,11 +1322,8 @@ class CGArgumentConverter(CGThing):
|
||||||
arg = "arg%d" % index
|
arg = "arg%d" % index
|
||||||
|
|
||||||
self.converter = instantiateJSToNativeConversionTemplate(
|
self.converter = instantiateJSToNativeConversionTemplate(
|
||||||
template, replacementVariables, declType, arg)
|
template, replacementVariables, declType, arg,
|
||||||
|
needsAutoRoot=type_needs_auto_root(argument.type))
|
||||||
# The auto rooting is done only after the conversion is performed
|
|
||||||
if type_needs_auto_root(argument.type):
|
|
||||||
self.converter.append(CGGeneric("auto_root!(in(cx) let %s = %s);" % (arg, arg)))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
assert argument.optional
|
assert argument.optional
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue