Bug 804319. Implement parsing of the "stringifier;" shorthand. r=khuey

This commit is contained in:
Boris Zbarsky 2012-11-05 14:40:32 -05:00
parent 972faa6f3c
commit 888a7ed3bc
6 changed files with 79 additions and 11 deletions

View File

@ -508,7 +508,8 @@ DOMInterfaces = {
'receiveWeakNullableCastableObjectNullableSequence' ],
'binaryNames': { 'methodRenamedFrom': 'methodRenamedTo',
'attributeGetterRenamedFrom': 'attributeGetterRenamedTo',
'attributeRenamedFrom': 'attributeRenamedTo' }
'attributeRenamedFrom': 'attributeRenamedTo',
'__stringifier' : 'Stringify' }
},
'TestNonCastableInterface' : {

View File

@ -600,8 +600,8 @@ class IDLInterface(IDLObjectWithScope):
ancestorConsequential.interfacesBasedOnSelf.add(self)
# Ensure that there's at most one of each {named,indexed}
# {getter,setter,creator,deleter}.
specialMembersSeen = set()
# {getter,setter,creator,deleter} and at most one stringifier.
specialMembersSeen = {}
for member in self.members:
if not member.isMethod():
continue
@ -614,21 +614,25 @@ class IDLInterface(IDLObjectWithScope):
memberType = "creators"
elif member.isDeleter():
memberType = "deleters"
elif member.isStringifier():
memberType = "stringifiers"
else:
continue
if member.isNamed():
memberType = "named " + memberType
elif member.isIndexed():
memberType = "indexed " + memberType
else:
continue
if memberType != "stringifiers":
if member.isNamed():
memberType = "named " + memberType
else:
assert member.isIndexed()
memberType = "indexed " + memberType
if memberType in specialMembersSeen:
raise WebIDLError("Multiple " + memberType + " on %s" % (self),
[self.location])
[self.location,
specialMembersSeen[memberType].location,
member.location])
specialMembersSeen.add(memberType)
specialMembersSeen[memberType] = member
def validate(self):
for member in self.members:
@ -3299,6 +3303,20 @@ class Parser(Tokenizer):
legacycaller=legacycaller, stringifier=stringifier)
p[0] = method
def p_Stringifier(self, p):
"""
Operation : STRINGIFIER SEMICOLON
"""
identifier = IDLUnresolvedIdentifier(BuiltinLocation("<auto-generated-identifier>"),
"__stringifier",
allowDoubleUnderscore=True)
method = IDLMethod(self.getLocation(p, 1),
identifier,
returnType=BuiltinTypes[IDLBuiltinType.Types.domstring],
arguments=[],
stringifier=True)
p[0] = method
def p_QualifierStatic(self, p):
"""
Qualifier : STATIC

View File

@ -0,0 +1,46 @@
import WebIDL
def WebIDLTest(parser, harness):
parser.parse("""
interface TestStringifier {
stringifier;
};
""")
results = parser.finish()
harness.ok(isinstance(results[0].members[0], WebIDL.IDLMethod),
"Stringifer should be method")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface TestStringifier {
stringifier;
stringifier;
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should not allow two 'stringifier;'")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface TestStringifier {
stringifier;
stringifier DOMString foo();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "Should not allow a 'stringifier;' and a 'stringifier()'")

View File

@ -438,6 +438,7 @@ public:
void SetAttrWithLenientThis(int32_t);
uint32_t UnforgeableAttr();
uint32_t UnforgeableAttr2();
void Stringify(nsString&);
void PassRenamedInterface(nsRenamedInterface&);
TestInterface* PutForwardsAttr();
TestInterface* PutForwardsAttr2();

View File

@ -342,6 +342,7 @@ interface TestInterface {
[LenientThis] attribute long attrWithLenientThis;
[Unforgeable] readonly attribute long unforgeableAttr;
[Unforgeable, ChromeOnly] readonly attribute long unforgeableAttr2;
stringifier;
void passRenamedInterface(TestRenamedInterface arg);
[PutForwards=writableByte] readonly attribute TestInterface putForwardsAttr;
[PutForwards=writableByte, LenientThis] readonly attribute TestInterface putForwardsAttr2;

View File

@ -309,6 +309,7 @@ interface TestExampleInterface {
[LenientThis] attribute long attrWithLenientThis;
[Unforgeable] readonly attribute long unforgeableAttr;
[Unforgeable, ChromeOnly] readonly attribute long unforgeableAttr2;
stringifier;
void passRenamedInterface(TestRenamedInterface arg);
[PutForwards=writableByte] readonly attribute TestExampleInterface putForwardsAttr;
[PutForwards=writableByte, LenientThis] readonly attribute TestExampleInterface putForwardsAttr2;