aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen
diff options
context:
space:
mode:
authorIgor Matuszewski <Xanewok@gmail.com>2018-03-23 18:06:55 +0100
committerIgor Matuszewski <Xanewok@gmail.com>2018-03-23 19:25:20 +0100
commit2437a8472e3c2f9201fa4fc3fca06537ebf52d62 (patch)
tree49f3cfe0d61a065b85dd08fb2b16ad3d5075f98d /components/script/dom/bindings/codegen
parentc42127b683ccf2aa81858da77f56c993189e0bc1 (diff)
downloadservo-2437a8472e3c2f9201fa4fc3fca06537ebf52d62.tar.gz
servo-2437a8472e3c2f9201fa4fc3fca06537ebf52d62.zip
Unify argument auto rooting in codegen
Diffstat (limited to 'components/script/dom/bindings/codegen')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 6e0632fe97d..de991f35ed9 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -418,15 +418,12 @@ class CGMethodCall(CGThing):
template = info.template
declType = info.declType
- argName = "arg%d" % distinguishingIndex
-
testCode = instantiateJSToNativeConversionTemplate(
template,
{"val": distinguishingArg},
declType,
- argName)
- if type_needs_auto_root(type):
- testCode.append(CGGeneric("auto_root!(in(cx) let %s = %s);" % (argName, argName)))
+ "arg%d" % distinguishingIndex,
+ needsAutoRoot=type_needs_auto_root(type))
# Indent by 4, since we need to indent further than our "do" statement
caseBody.append(CGIndenter(testCode, 4))
@@ -1215,7 +1212,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
def instantiateJSToNativeConversionTemplate(templateBody, replacements,
- declType, declName):
+ declType, declName,
+ needsAutoRoot=False):
"""
Take the templateBody and declType as returned by
getJSToNativeConversionInfo, a set of replacements as required by the
@@ -1240,6 +1238,8 @@ def instantiateJSToNativeConversionTemplate(templateBody, replacements,
else:
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
# conversion.
result.append(CGGeneric(""))
@@ -1322,11 +1322,8 @@ class CGArgumentConverter(CGThing):
arg = "arg%d" % index
self.converter = instantiateJSToNativeConversionTemplate(
- template, replacementVariables, declType, arg)
-
- # 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)))
+ template, replacementVariables, declType, arg,
+ needsAutoRoot=type_needs_auto_root(argument.type))
else:
assert argument.optional