diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index e66bef653b60..05f895f1cd74 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -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)) diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 88c88a3afd04..a76827e85ce3 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -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]); diff --git a/dom/bindings/parser/tests/test_attr.py b/dom/bindings/parser/tests/test_attr.py index 698be3f309b4..fb0c91964609 100644 --- a/dom/bindings/parser/tests/test_attr.py +++ b/dom/bindings/parser/tests/test_attr.py @@ -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") diff --git a/dom/webidl/Element.webidl b/dom/webidl/Element.webidl index e837e867afc9..5115574849bc 100644 --- a/dom/webidl/Element.webidl +++ b/dom/webidl/Element.webidl @@ -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); diff --git a/dom/webidl/Node.webidl b/dom/webidl/Node.webidl index 2002d647a306..06f54afb0429 100644 --- a/dom/webidl/Node.webidl +++ b/dom/webidl/Node.webidl @@ -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;