Bug 909863. Add support for the [SameObject] extended attribute in WebIDL. r=khuey

This commit is contained in:
Boris Zbarsky 2013-08-29 00:30:05 -04:00
Родитель 2cb7f1d590
Коммит 68ca6691d8
5 изменённых файлов: 46 добавлений и 6 удалений

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

@ -5801,7 +5801,8 @@ class CGMemberJITInfo(CGThing):
# while we have the right type.
getter = ("(JSJitGetterOp)get_%s" % self.member.identifier.name)
getterinfal = "infallible" in self.descriptor.getExtendedAttributes(self.member, getter=True)
getterconst = self.member.getExtendedAttribute("Constant")
getterconst = (self.member.getExtendedAttribute("SameObject") or
self.member.getExtendedAttribute("Constant"))
getterpure = getterconst or self.member.getExtendedAttribute("Pure")
assert (getterinfal or (not getterconst and not getterpure))

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

@ -2601,6 +2601,10 @@ class IDLAttribute(IDLInterfaceMember):
raise WebIDLError("An attribute with [PutForwards] must have an "
"interface type as its type", [self.location])
if not self.type.isInterface() and self.getExtendedAttribute("SameObject"):
raise WebIDLError("An attribute with [SameObject] must have an "
"interface type as its type", [self.location])
def validate(self):
pass
@ -2615,12 +2619,14 @@ class IDLAttribute(IDLInterfaceMember):
[self.location])
elif (((identifier == "Throws" or identifier == "GetterThrows") and
(self.getExtendedAttribute("Pure") or
self.getExtendedAttribute("SameObject") or
self.getExtendedAttribute("Constant"))) or
((identifier == "Pure" or identifier == "Constant") and
((identifier == "Pure" or identifier == "SameObject" or
identifier == "Constant") and
(self.getExtendedAttribute("Throws") or
self.getExtendedAttribute("GetterThrows")))):
raise WebIDLError("Throwing things can't be [Pure] or [Constant]",
[attr.location])
raise WebIDLError("Throwing things can't be [Pure] or [Constant] "
"or [SameObject]", [attr.location])
elif identifier == "LenientThis":
if not attr.noArguments():
raise WebIDLError("[LenientThis] must take no arguments",
@ -2637,6 +2643,9 @@ class IDLAttribute(IDLInterfaceMember):
raise WebIDLError("[Unforgeable] is only allowed on non-static "
"attributes", [attr.location, self.location])
self._unforgeable = True
elif identifier == "SameObject" and not self.readonly:
raise WebIDLError("[SameObject] only allowed on readonly attributes",
[attr.location, self.location])
elif identifier == "Constant" and not self.readonly:
raise WebIDLError("[Constant] only allowed on readonly attributes",
[attr.location, self.location])
@ -2673,6 +2682,7 @@ class IDLAttribute(IDLInterfaceMember):
identifier == "Throws" or
identifier == "GetterThrows" or
identifier == "ChromeOnly" or
identifier == "SameObject" or
identifier == "Constant" or
identifier == "Func" or
identifier == "Creator"):
@ -3196,6 +3206,9 @@ class IDLMethod(IDLInterfaceMember, IDLScope):
raise WebIDLError("Methods must not be flagged as "
"[Unforgeable]",
[attr.location, self.location])
elif identifier == "SameObject":
raise WebIDLError("Methods must not be flagged as [SameObject]",
[attr.location, self.location]);
elif identifier == "Constant":
raise WebIDLError("Methods must not be flagged as [Constant]",
[attr.location, self.location]);

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

@ -313,3 +313,29 @@ def WebIDLTest(parser, harness):
except Exception, x:
threw = True
harness.ok(threw, "Should spell [Throws] correctly")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface A {
[SameObject] readonly attribute boolean foo;
};
""")
results = parser.finish()
except Exception, x:
threw = True
harness.ok(threw, "Should not allow [SameObject] on attributes not of interface type")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface A {
[SameObject] readonly attribute A foo;
};
""")
results = parser.finish()
except Exception, x:
threw = True
harness.ok(not threw, "Should allow [SameObject] on attributes of interface type")

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

@ -35,7 +35,7 @@ interface Element : Node {
[Constant]
readonly attribute DOMTokenList? classList;
[Constant]
[SameObject]
readonly attribute MozNamedAttrMap attributes;
DOMString? getAttribute(DOMString name);
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);

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

@ -42,7 +42,7 @@ interface Node : EventTarget {
[Pure]
readonly attribute Element? parentElement;
boolean hasChildNodes();
[Constant]
[SameObject]
readonly attribute NodeList childNodes;
[Pure]
readonly attribute Node? firstChild;