Make MemberCondition a function returning a plain string

This commit is contained in:
Anthony Ramine 2016-05-20 21:48:52 +02:00
parent 7040e2a5f7
commit b094932d57

View file

@ -1322,31 +1322,20 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
returnType) returnType)
class MemberCondition: def MemberCondition(pref, func):
""" """
An object representing the condition for a member to actually be A string representing the condition for a member to actually be exposed.
exposed. Any of the arguments can be None. If not Any of the arguments can be None. If not None, they should have the
None, they should have the following types: following types:
pref: The name of the preference. pref: The name of the preference.
func: The name of the function. func: The name of the function.
""" """
def __init__(self, pref=None, func=None): assert pref is None or isinstance(pref, str)
assert pref is None or isinstance(pref, str) assert func is None or isinstance(func, str)
assert func is None or isinstance(func, str) if pref:
self.pref = pref return 'Some("%s")' % pref
return "None"
def toFuncPtr(val):
if val is None:
return "None"
return "Some(%s)" % val
self.func = toFuncPtr(func)
def __eq__(self, other):
return (self.pref == other.pref and self.func == other.func)
def __ne__(self, other):
return not self.__eq__(other)
class PropertyDefiner: class PropertyDefiner:
@ -1427,7 +1416,7 @@ class PropertyDefiner:
def switchToCondition(props, condition): def switchToCondition(props, condition):
prefableSpecs.append(prefableTemplate % prefableSpecs.append(prefableTemplate %
('Some("%s")' % condition.pref if condition.pref else 'None', (condition,
name + "_specs", name + "_specs",
len(specs), len(specs),
'true' if specTerminator else 'false')) 'true' if specTerminator else 'false'))
@ -1500,7 +1489,7 @@ class MethodDefiner(PropertyDefiner):
"methodInfo": False, "methodInfo": False,
"selfHostedName": "ArrayValues", "selfHostedName": "ArrayValues",
"length": 0, "length": 0,
"condition": MemberCondition()}) "condition": "None"})
isUnforgeableInterface = bool(descriptor.interface.getExtendedAttribute("Unforgeable")) isUnforgeableInterface = bool(descriptor.interface.getExtendedAttribute("Unforgeable"))
if not static and unforgeable == isUnforgeableInterface: if not static and unforgeable == isUnforgeableInterface: