Bug 828532 - Removed 'prototype' as a reserved identifier in WebIDL. r=bz

This commit is contained in:
William Chen 2013-01-10 11:54:13 -08:00
parent 7531e9d499
commit 382d12416e
3 changed files with 94 additions and 1 deletions

View File

@ -279,7 +279,7 @@ class IDLUnresolvedIdentifier(IDLObject):
[location])
if name[0] == '_' and not allowDoubleUnderscore:
name = name[1:]
if name in ["prototype", "constructor", "toString"] and not allowForbidden:
if name in ["constructor", "toString"] and not allowForbidden:
raise WebIDLError("Cannot use reserved identifier '%s'" % (name),
[location])
@ -2078,6 +2078,10 @@ class IDLConst(IDLInterfaceMember):
self.type = type
self.value = value
if identifier.name == "prototype":
raise WebIDLError("The identifier of a constant must not be 'prototype'",
[location])
def __str__(self):
return "'%s' const '%s'" % (self.type, self.identifier)
@ -2117,6 +2121,10 @@ class IDLAttribute(IDLInterfaceMember):
self._unforgeable = False
self.stringifier = stringifier
if static and identifier.name == "prototype":
raise WebIDLError("The identifier of a static attribute must not be 'prototype'",
[location])
if readonly and inherit:
raise WebIDLError("An attribute cannot be both 'readonly' and 'inherit'",
[self.location])
@ -2449,6 +2457,10 @@ class IDLMethod(IDLInterfaceMember, IDLScope):
self._stringifier = stringifier
self._specialType = specialType
if static and identifier.name == "prototype":
raise WebIDLError("The identifier of a static operation must not be 'prototype'",
[location])
self.assertSignatureConstraints()
def __str__(self):

View File

@ -0,0 +1,80 @@
def WebIDLTest(parser, harness):
threw = False
try:
parser.parse("""
interface TestIface {
static attribute boolean prototype;
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "The identifier of a static attribute must not be 'prototype'")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface TestIface {
static boolean prototype();
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "The identifier of a static operation must not be 'prototype'")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface TestIface {
const boolean prototype = true;
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw, "The identifier of a constant must not be 'prototype'")
# Make sure that we can parse non-static attributes with 'prototype' as identifier.
parser = parser.reset()
parser.parse("""
interface TestIface {
attribute boolean prototype;
};
""")
results = parser.finish()
testIface = results[0];
harness.check(testIface.members[0].isStatic(), False, "Attribute should not be static")
harness.check(testIface.members[0].identifier.name, "prototype", "Attribute identifier should be 'prototype'")
# Make sure that we can parse non-static operations with 'prototype' as identifier.
parser = parser.reset()
parser.parse("""
interface TestIface {
boolean prototype();
};
""")
results = parser.finish()
testIface = results[0];
harness.check(testIface.members[0].isStatic(), False, "Operation should not be static")
harness.check(testIface.members[0].identifier.name, "prototype", "Operation identifier should be 'prototype'")
# Make sure that we can parse dictionary members with 'prototype' as identifier.
parser = parser.reset()
parser.parse("""
dictionary TestDict {
boolean prototype;
};
""")
results = parser.finish()
testDict = results[0];
harness.check(testDict.members[0].identifier.name, "prototype", "Dictionary member should be 'prototype'")

View File

@ -523,6 +523,7 @@ dictionary Dict : ParentDict {
DOMString? yetAnotherStr = null;
DOMString template;
object someObj;
boolean prototype;
object? anotherObj = null;
TestCallback? someCallback = null;
};