Bug 766853. The two sides of an implements statement must both be non-callback interfaces. r=jlebar

This commit is contained in:
Boris Zbarsky 2012-06-22 16:18:51 -04:00
Родитель ad2e1bf8fb
Коммит b2bd288bc9
2 изменённых файлов: 100 добавлений и 9 удалений

Просмотреть файл

@ -442,14 +442,6 @@ class IDLInterface(IDLObjectWithScope):
self.parent.identifier.name),
self.location,
extraLocations=[self.parent.location])
if len(self.parent.getConsequentialInterfaces()) != 0:
raise WebIDLError("Callback interface %s inheriting from "
"interface %s which has consequential "
"interfaces" %
(self.identifier.name,
self.parent.identifier.name),
self.location,
extraLocations=[self.parent.location])
elif self.parent.isCallback():
raise WebIDLError("Non-callback interface %s inheriting from "
"callback interface %s" %
@ -468,6 +460,13 @@ class IDLInterface(IDLObjectWithScope):
self.location,
extraLocations=[cycleInGraph.location])
if self.isCallback():
# "implements" should have made sure we have no
# consequential interfaces.
assert len(self.getConsequentialInterfaces()) == 0
# And that we're not consequential.
assert not self.isConsequential()
# Now resolve() and finish() our members before importing the
# ones from our implemented interfaces.
@ -2107,6 +2106,25 @@ class IDLImplementsStatement(IDLObject):
assert(isinstance(self.implementee, IDLIdentifierPlaceholder))
implementor = self.implementor.finish(scope)
implementee = self.implementee.finish(scope)
# NOTE: we depend on not setting self.implementor and
# self.implementor here to keep track of the original
# locations.
if not isinstance(implementor, IDLInterface):
raise WebIDLError("Left-hand side of 'implements' is not an "
"interface",
self.implementor.location)
if implementor.isCallback():
raise WebIDLError("Left-hand side of 'implements' is a callback "
"interface",
self.implementor.location)
if not isinstance(implementee, IDLInterface):
raise WebIDLError("Right-hand side of 'implements' is not an "
"interface",
self.implementee.location)
if implementee.isCallback():
raise WebIDLError("Right-hand side of 'implements' is a callback "
"interface",
self.implementee.location)
implementor.addImplementedInterface(implementee)
def validate(self):

Просмотреть файл

@ -115,7 +115,7 @@ def WebIDLTest(parser, harness):
# Reset the parser so we can actually find things where we expect
# them in the list
parser = WebIDL.Parser()
parser = parser.reset()
# Diamonds should be allowed
threw = False
@ -141,3 +141,76 @@ def WebIDLTest(parser, harness):
harness.check(len(results[6].members), 1, "S should have one member")
harness.check(results[6].members[0].identifier.name, "x",
"S's member should be 'x'")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface TestInterface {
};
callback interface TestCallbackInterface {
};
TestInterface implements TestCallbackInterface;
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Should not allow callback interfaces on the right-hand side "
"of 'implements'")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface TestInterface {
};
callback interface TestCallbackInterface {
};
TestCallbackInterface implements TestInterface;
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Should not allow callback interfaces on the left-hand side of "
"'implements'")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface TestInterface {
};
dictionary Dict {
};
Dict implements TestInterface;
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Should not allow non-interfaces on the left-hand side "
"of 'implements'")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface TestInterface {
};
dictionary Dict {
};
TestInterface implements Dict;
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Should not allow non-interfaces on the right-hand side "
"of 'implements'")