From 16db1fc4c05d3f863abeb1bc54f94077576f41ed Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 5 Sep 2014 14:28:43 -0400 Subject: [PATCH] Bug 1057541 part 2. Add a way to ask an IDLArgument whether it guarantees that it will always have a value. r=khuey --- dom/bindings/Codegen.py | 26 +++++++++++++------------- dom/bindings/parser/WebIDL.py | 3 +++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 7bf5e5388ab8..f368b858e0a5 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -5287,7 +5287,7 @@ class CGArgumentConverter(CGThing): "args.hasDefined(${index})").substitute(replacer) self.replacementVariables["haveValue"] = haveValueCheck self.descriptorProvider = descriptorProvider - if self.argument.optional and not self.argument.defaultValue: + if self.argument.canHaveMissingValue(): self.argcAndIndex = replacer else: self.argcAndIndex = None @@ -6130,10 +6130,9 @@ 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. - # This also covers variadic arguments. + if a.canHaveMissingValue(): + # This will need an Optional or it's a variadic; + # in both cases it should be const. return True if a.type.isUnion(): return True @@ -6350,7 +6349,7 @@ def wrapArgIntoCurrentCompartment(arg, value, isMember=True): As wrapTypeIntoCurrentCompartment but handles things being optional """ origValue = value - isOptional = arg.optional and not arg.defaultValue + isOptional = arg.canHaveMissingValue() if isOptional: value = value + ".Value()" wrap = wrapTypeIntoCurrentCompartment(arg.type, value, isMember) @@ -6857,8 +6856,7 @@ class CGMethodCall(CGThing): # enough that we can examine this argument. But note that we # still want to claim that optional arguments are optional, in # case undefined was passed in. - argIsOptional = (distinguishingArgument(signature).optional and - not distinguishingArgument(signature).defaultValue) + argIsOptional = distinguishingArgument(signature).canHaveMissingValue() testCode = instantiateJSToNativeConversion( getJSToNativeConversionInfo(type, descriptor, failureCode=failureCode, @@ -7144,6 +7142,9 @@ class FakeArgument(): def allowTreatNonCallableAsNull(self): return self._allowTreatNonCallableAsNull + def canHaveMissingValue(self): + return False + class CGSetterCall(CGPerSignatureCall): """ @@ -12526,8 +12527,7 @@ class CGNativeMember(ClassMethod): """ Get the full argument declaration for an argument """ - decl, ref = self.getArgType(arg.type, - arg.optional and not arg.defaultValue, + decl, ref = self.getArgType(arg.type, arg.canHaveMissingValue(), "Variadic" if arg.variadic else False) if ref: decl = CGWrapper(decl, pre="const ", post="&") @@ -13606,7 +13606,7 @@ class CallbackMember(CGNativeMember): jsvalIndex = "%d + idx" % i else: jsvalIndex = "%d" % i - if arg.optional and not arg.defaultValue: + if arg.canHaveMissingValue(): argval += ".Value()" if arg.type.isDOMString(): # XPConnect string-to-JS conversion wants to mutate the string. So @@ -13649,7 +13649,7 @@ class CallbackMember(CGNativeMember): """, arg=arg.identifier.name, conversion=conversion) - elif arg.optional and not arg.defaultValue: + elif arg.canHaveMissingValue(): conversion = fill( """ if (${argName}.WasPassed()) { @@ -14383,7 +14383,7 @@ class CGEventMethod(CGNativeMember): def getArg(self, arg): decl, ref = self.getArgType(arg.type, - arg.optional and not arg.defaultValue, + arg.canHaveMissingValue(), "Variadic" if arg.variadic else False) if ref: decl = CGWrapper(decl, pre="const ", post="&") diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 77169683d249..4e16de86de0d 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -3474,6 +3474,9 @@ class IDLArgument(IDLObjectWithIdentifier): deps.add(self.defaultValue) return deps + def canHaveMissingValue(self): + return self.optional and not self.defaultValue + class IDLCallbackType(IDLType, IDLObjectWithScope): def __init__(self, location, parentScope, identifier, returnType, arguments): assert isinstance(returnType, IDLType)