From 080775af23cbb3f64ee0fe3dc90bd7b207392c27 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 25 Apr 2013 19:03:06 -0400 Subject: [PATCH] Bug 766583 part 5. Stop declaring optional arguments as const on the stack in bindings code. r=smaug --- dom/bindings/Codegen.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 4bd4f1cb5d3..4e01dd4b6dd 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -2913,15 +2913,15 @@ for (uint32_t i = 0; i < length; ++i) { constructInternal = "ref" if type.nullable(): if isOptional: - declType = "const Optional<" + name + "*>" + declType = "Optional<" + name + "*>" else: declType = name + "*" else: if isOptional: - declType = "const Optional<" + name + ">" + declType = "Optional<" + name + ">" # We don't need a holder in this case holderType = None - constructLoc = "(const_cast& >(${declName}))" + constructLoc = "${declName}" constructMethod = "Construct" constructInternal = "Value" else: @@ -2936,9 +2936,8 @@ for (uint32_t i = 0; i < length; ++i) { nullableTarget = "" if type.nullable(): if isOptional: - mutableDecl = "(const_cast& >(${declName}))" - template += "%s.Construct();\n" % mutableDecl - nullableTarget = "%s.Value()" % mutableDecl + template += "${declName}.Construct();\n" + nullableTarget = "${declName}.Value()" else: nullableTarget = "${declName}" template += "%s = ${holderName}.addr();" % nullableTarget @@ -3331,11 +3330,8 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements, originalHolderName = replacements["holderName"] if holderType is not None: if dealWithOptional: - replacements["holderName"] = ( - "const_cast< %s & >(%s.Value())" % - (holderType.define(), originalHolderName)) - mutableHolderType = CGTemplatedType("Optional", holderType) - holderType = CGWrapper(mutableHolderType, pre="const ") + replacements["holderName"] = "%s.Value()" % originalHolderName + holderType = CGTemplatedType("Optional", holderType) result.append( CGList([holderType, CGGeneric(" "), CGGeneric(originalHolderName), @@ -3344,11 +3340,8 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements, originalDeclName = replacements["declName"] if declType is not None: if dealWithOptional: - replacements["declName"] = ( - "const_cast< %s & >(%s.Value())" % - (declType.define(), originalDeclName)) - mutableDeclType = CGTemplatedType("Optional", declType) - declType = CGWrapper(mutableDeclType, pre="const ") + replacements["declName"] = "%s.Value()" % originalDeclName + declType = CGTemplatedType("Optional", declType) result.append( CGList([declType, CGGeneric(" "), CGGeneric(originalDeclName), @@ -3361,12 +3354,10 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements, if argcAndIndex is not None: if dealWithOptional: declConstruct = CGIndenter( - CGGeneric("const_cast< %s &>(%s).Construct();" % - (mutableDeclType.define(), originalDeclName))) + CGGeneric("%s.Construct();" % originalDeclName)) if holderType is not None: holderConstruct = CGIndenter( - CGGeneric("const_cast< %s &>(%s).Construct();" % - (mutableHolderType.define(), originalHolderName))) + CGGeneric("%s.Construct();" % originalHolderName)) else: holderConstruct = None else: @@ -3985,6 +3976,10 @@ class CGCallGenerator(CGThing): return True if a.type.isString(): return True + if a.optional and not a.defaultValue: + # If a.defaultValue, then it's not going to use an Optional, + # so doesn't need to be const just due to being optional. + return True return False if needsConst(a): arg = CGWrapper(arg, pre="Constify(", post=")")