Bug 1359269 - Part 6: Add support for attributes on types in dictionaries; r=bzbarsky
authorManish Goregaokar <manishearth@gmail.com>
Sat, 02 Mar 2019 04:21:41 +0000
changeset 519959 a64f79c456c9350a9a0f5a305c56574a1deb8681
parent 519958 f4ec249fc52a26c94b9d04cad859faf32689267c
child 519960 b267c4012f94ac4fcea4252bc3d61e39a31f401e
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1359269
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1359269 - Part 6: Add support for attributes on types in dictionaries; r=bzbarsky Depends on D19737 Differential Revision: https://phabricator.services.mozilla.com/D19738
dom/bindings/parser/WebIDL.py
dom/bindings/test/TestBindingHeader.h
dom/bindings/test/TestCodeGen.webidl
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -5910,33 +5910,42 @@ class Parser(Tokenizer):
         if len(p) == 1:
             # We're at the end of the list
             p[0] = []
             return
         p[2].addExtendedAttributes(p[1])
         p[0] = [p[2]]
         p[0].extend(p[3])
 
-    def p_DictionaryMember(self, p):
-        """
-            DictionaryMember : Required Type IDENTIFIER Default SEMICOLON
-        """
-        # These quack a lot like optional arguments, so just treat them that way.
+    def p_DictionaryMemberRequired(self, p):
+        """
+            DictionaryMember : REQUIRED TypeWithExtendedAttributes IDENTIFIER SEMICOLON
+        """
+        # These quack a lot like required arguments, so just treat them that way.
         t = p[2]
         assert isinstance(t, IDLType)
         identifier = IDLUnresolvedIdentifier(self.getLocation(p, 3), p[3])
-        defaultValue = p[4]
-        optional = not p[1]
-
-        if not optional and defaultValue:
-            raise WebIDLError("Required dictionary members can't have a default value.",
-                              [self.getLocation(p, 4)])
 
         p[0] = IDLArgument(self.getLocation(p, 3), identifier, t,
-                           optional=optional,
+                           optional=False,
+                           defaultValue=None, variadic=False,
+                           dictionaryMember=True)
+
+    def p_DictionaryMember(self, p):
+        """
+            DictionaryMember : Type IDENTIFIER Default SEMICOLON
+        """
+        # These quack a lot like optional arguments, so just treat them that way.
+        t = p[1]
+        assert isinstance(t, IDLType)
+        identifier = IDLUnresolvedIdentifier(self.getLocation(p, 2), p[2])
+        defaultValue = p[3]
+
+        p[0] = IDLArgument(self.getLocation(p, 2), identifier, t,
+                           optional=True,
                            defaultValue=defaultValue, variadic=False,
                            dictionaryMember=True)
 
     def p_Default(self, p):
         """
             Default : EQUALS DefaultValue
                     |
         """
@@ -6514,28 +6523,16 @@ class Parser(Tokenizer):
 
     def p_AttributeName(self, p):
         """
             AttributeName : IDENTIFIER
                           | REQUIRED
         """
         p[0] = p[1]
 
-    def p_Required(self, p):
-        """
-            Required : REQUIRED
-        """
-        p[0] = True
-
-    def p_RequiredEmpty(self, p):
-        """
-            Required :
-        """
-        p[0] = False
-
     def p_Ellipsis(self, p):
         """
             Ellipsis : ELLIPSIS
         """
         p[0] = True
 
     def p_EllipsisEmpty(self, p):
         """
--- a/dom/bindings/test/TestBindingHeader.h
+++ b/dom/bindings/test/TestBindingHeader.h
@@ -1588,15 +1588,17 @@ class TestAttributesOnTypes : public nsI
   NS_DECL_ISUPPORTS
 
   // We need a GetParentObject and GetDocGroup to make binding codegen happy
   virtual nsISupports* GetParentObject();
 
   void Foo(uint8_t arg);
   void Bar(uint8_t arg);
   void Baz(const nsAString& arg);
+  uint8_t SomeAttr();
+  void SetSomeAttr(uint8_t);
   void ArgWithAttr(uint8_t arg1, const Optional<uint8_t>& arg2);
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif /* TestBindingHeader_h */
--- a/dom/bindings/test/TestCodeGen.webidl
+++ b/dom/bindings/test/TestCodeGen.webidl
@@ -1315,16 +1315,26 @@ interface TestCEReactionsInterface {
   getter DOMString (DOMString name);
   readonly attribute unsigned long length;
 };
 
 typedef [EnforceRange] octet OctetRange;
 typedef [Clamp] octet OctetClamp;
 typedef [TreatNullAs=EmptyString] DOMString NullEmptyString;
 
+dictionary TestAttributesOnDictionaryMembers {
+  [Clamp] octet a;
+  [ChromeOnly, Clamp] octet b;
+  required [Clamp] octet c;
+  [ChromeOnly] octet d;
+  // ChromeOnly doesn't mix with required, so we can't
+  // test [ChromeOnly] required [Clamp] octet e
+};
+
 interface TestAttributesOnTypes {
   void foo(OctetClamp thingy);
   void bar(OctetRange thingy);
   void baz(NullEmptyString thingy);
+  attribute [Clamp] octet someAttr;
   void argWithAttr([Clamp] octet arg0, optional [Clamp] octet arg1);
   // There aren't any argument-only attributes that we can test here,
   // TreatNonCallableAsNull isn't compatible with Clamp-able types
 };