Bug 1359269 - Part 5: Add support for attributes on types in arguments; r=bzbarsky
authorManish Goregaokar <manishearth@gmail.com>
Sat, 02 Mar 2019 04:21:33 +0000
changeset 519958 f4ec249fc52a26c94b9d04cad859faf32689267c
parent 519957 3fccace0ea88508058cd36e13a9cff92ed7866a3
child 519959 a64f79c456c9350a9a0f5a305c56574a1deb8681
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 5: Add support for attributes on types in arguments; r=bzbarsky Depends on D19736 Differential Revision: https://phabricator.services.mozilla.com/D19737
dom/bindings/parser/WebIDL.py
dom/bindings/test/TestBindingHeader.h
dom/bindings/test/TestCodeGen.webidl
dom/webidl/WebSocket.webidl
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -6431,43 +6431,60 @@ class Parser(Tokenizer):
         p[0].extend(p[3])
 
     def p_ArgumentsEmpty(self, p):
         """
             Arguments :
         """
         p[0] = []
 
-    def p_Argument(self, p):
-        """
-            Argument : ExtendedAttributeList Optional Type Ellipsis ArgumentName Default
+    def p_ArgumentOptional(self, p):
+        """
+            Argument : ExtendedAttributeList OPTIONAL TypeWithExtendedAttributes Ellipsis ArgumentName Default
         """
         t = p[3]
         assert isinstance(t, IDLType)
         identifier = IDLUnresolvedIdentifier(self.getLocation(p, 5), p[5])
 
-        optional = p[2]
         variadic = p[4]
         defaultValue = p[6]
 
-        if not optional and defaultValue:
-            raise WebIDLError("Mandatory arguments can't have a default value.",
-                              [self.getLocation(p, 6)])
 
         # We can't test t.isAny() here and give it a default value as needed,
         # since at this point t is not a fully resolved type yet (e.g. it might
         # be a typedef).  We'll handle the 'any' case in IDLArgument.complete.
 
         if variadic:
-            if optional:
-                raise WebIDLError("Variadic arguments should not be marked optional.",
-                                  [self.getLocation(p, 2)])
-            optional = variadic
-
-        p[0] = IDLArgument(self.getLocation(p, 5), identifier, t, optional, defaultValue, variadic)
+            raise WebIDLError("Variadic arguments should not be marked optional.",
+                              [self.getLocation(p, 2)])
+
+        p[0] = IDLArgument(self.getLocation(p, 5), identifier, t, True, defaultValue, variadic)
+        p[0].addExtendedAttributes(p[1])
+
+    def p_Argument(self, p):
+        """
+            Argument : ExtendedAttributeList Type Ellipsis ArgumentName Default
+        """
+        t = p[2]
+        assert isinstance(t, IDLType)
+        identifier = IDLUnresolvedIdentifier(self.getLocation(p, 4), p[4])
+
+        variadic = p[3]
+        defaultValue = p[5]
+
+        if defaultValue:
+            raise WebIDLError("Mandatory arguments can't have a default value.",
+                              [self.getLocation(p, 5)])
+
+        # We can't test t.isAny() here and give it a default value as needed,
+        # since at this point t is not a fully resolved type yet (e.g. it might
+        # be a typedef).  We'll handle the 'any' case in IDLArgument.complete.
+
+        # variadic implies optional
+        p[0] = IDLArgument(self.getLocation(p, 4), identifier, t, variadic, defaultValue, variadic)
         p[0].addExtendedAttributes(p[1])
 
     def p_ArgumentName(self, p):
         """
             ArgumentName : IDENTIFIER
                          | ATTRIBUTE
                          | CALLBACK
                          | CONST
@@ -6497,28 +6514,16 @@ class Parser(Tokenizer):
 
     def p_AttributeName(self, p):
         """
             AttributeName : IDENTIFIER
                           | REQUIRED
         """
         p[0] = p[1]
 
-    def p_Optional(self, p):
-        """
-            Optional : OPTIONAL
-        """
-        p[0] = True
-
-    def p_OptionalEmpty(self, p):
-        """
-            Optional :
-        """
-        p[0] = False
-
     def p_Required(self, p):
         """
             Required : REQUIRED
         """
         p[0] = True
 
     def p_RequiredEmpty(self, p):
         """
--- a/dom/bindings/test/TestBindingHeader.h
+++ b/dom/bindings/test/TestBindingHeader.h
@@ -1588,14 +1588,15 @@ 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);
+  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
@@ -1319,9 +1319,12 @@ interface TestCEReactionsInterface {
 typedef [EnforceRange] octet OctetRange;
 typedef [Clamp] octet OctetClamp;
 typedef [TreatNullAs=EmptyString] DOMString NullEmptyString;
 
 interface TestAttributesOnTypes {
   void foo(OctetClamp thingy);
   void bar(OctetRange thingy);
   void baz(NullEmptyString thingy);
+  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
 };
--- a/dom/webidl/WebSocket.webidl
+++ b/dom/webidl/WebSocket.webidl
@@ -38,17 +38,17 @@ interface WebSocket : EventTarget {
 
   attribute EventHandler onclose;
 
   readonly attribute DOMString extensions;
 
   readonly attribute DOMString protocol;
 
   [Throws]
-  void close([Clamp] optional unsigned short code, optional DOMString reason);
+  void close(optional [Clamp] unsigned short code, optional DOMString reason);
 
   // messaging
 
   attribute EventHandler onmessage;
 
   attribute BinaryType binaryType;
 
   [Throws]