Bug 884373. Align WebIDL handling of default parameters with ES6. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 26 Jun 2013 10:59:46 -0400
changeset 136538 7f527b34f4606e559419e91e6a74585ae5d0ac91
parent 136537 9961cd549e9ff0c71342c628e3a83d86130a2cf6
child 136539 53e925dc3bda9bdfd9a2044deee068d186d20276
push id30150
push userbzbarsky@mozilla.com
push dateWed, 26 Jun 2013 15:01:40 +0000
treeherdermozilla-inbound@7f527b34f460 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs884373
milestone25.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 884373. Align WebIDL handling of default parameters with ES6. r=khuey
dom/bindings/parser/WebIDL.py
dom/bindings/parser/tests/test_optional_constraints.py
dom/bindings/test/TestBindingHeader.h
dom/bindings/test/TestCodeGen.webidl
dom/bindings/test/TestExampleGen.webidl
dom/bindings/test/TestJSImplGen.webidl
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -2957,17 +2957,16 @@ class IDLMethod(IDLInterfaceMember, IDLS
     def signatures(self):
         return [(overload.returnType, overload.arguments) for overload in
                 self._overloads]
 
     def finish(self, scope):
         for overload in self._overloads:
             inOptionalArguments = False
             variadicArgument = None
-            sawOptionalWithNoDefault = False
 
             arguments = overload.arguments
             for (idx, argument) in enumerate(arguments):
                 if argument.isComplete():
                     continue
 
                 argument.complete(scope)
                 assert argument.type.isComplete()
@@ -2998,28 +2997,19 @@ class IDLMethod(IDLInterfaceMember, IDLS
                     raise WebIDLError("Variadic argument is not last argument",
                                       [variadicArgument.location])
                 # Once we see an optional argument, there can't be any non-optional
                 # arguments.
                 if inOptionalArguments and not argument.optional:
                     raise WebIDLError("Non-optional argument after optional "
                                       "arguments",
                                       [argument.location])
-                # Once we see an argument with no default value, there can
-                # be no more default values.
-                if sawOptionalWithNoDefault and argument.defaultValue:
-                    raise WebIDLError("Argument with default value after "
-                                      "optional arguments with no default "
-                                      "values",
-                                      [argument.location])
                 inOptionalArguments = argument.optional
                 if argument.variadic:
                     variadicArgument = argument
-                sawOptionalWithNoDefault = (argument.optional and
-                                            not argument.defaultValue)
 
             returnType = overload.returnType
             if returnType.isComplete():
                 continue
 
             type = returnType.complete(scope)
 
             assert not isinstance(type, IDLUnresolvedType)
--- a/dom/bindings/parser/tests/test_optional_constraints.py
+++ b/dom/bindings/parser/tests/test_optional_constraints.py
@@ -6,9 +6,25 @@ def WebIDLTest(parser, harness):
               void foo(optional byte arg1, byte arg2);
             };
         """)
 
         results = parser.finish()
     except:
         threw = True
 
-    harness.ok(threw, "Should have thrown.")
+    harness.ok(threw,
+               "Should have thrown on non-optional argument following optional "
+               "argument.")
+
+    parser = parser.reset()
+    parser.parse("""
+        interface OptionalConstraints2 {
+          void foo(optional byte arg1 = 1, optional byte arg2 = 2,
+                   optional byte arg3, optional byte arg4 = 4,
+                   optional byte arg5, optional byte arg6 = 9);
+        };
+    """)
+    results = parser.finish()
+    args = results[0].members[0].signatures()[0][1]
+    harness.check(len(args), 6, "Should have 6 arguments")
+    harness.check(args[5].defaultValue.value, 9,
+                  "Should have correct default value")
--- a/dom/bindings/test/TestBindingHeader.h
+++ b/dom/bindings/test/TestBindingHeader.h
@@ -605,16 +605,19 @@ public:
   void ThrowingMethod(ErrorResult& aRv);
   bool GetThrowingAttr(ErrorResult& aRv) const;
   void SetThrowingAttr(bool arg, ErrorResult& aRv);
   bool GetThrowingGetterAttr(ErrorResult& aRv) const;
   void SetThrowingGetterAttr(bool arg);
   bool ThrowingSetterAttr() const;
   void SetThrowingSetterAttr(bool arg, ErrorResult& aRv);
   int16_t LegacyCall(JS::Value, uint32_t, TestInterface&);
+  void PassArgsWithDefaults(JSContext*, const Optional<int32_t>&,
+                            TestInterface*, const Dict&, double,
+                            const Optional<float>&);
 
   // Methods and properties imported via "implements"
   bool ImplementedProperty();
   void SetImplementedProperty(bool);
   void ImplementedMethod();
   bool ImplementedParentProperty();
   void SetImplementedParentProperty(bool);
   void ImplementedParentMethod();
--- a/dom/bindings/test/TestCodeGen.webidl
+++ b/dom/bindings/test/TestCodeGen.webidl
@@ -578,16 +578,20 @@ interface TestInterface {
   [PutForwards=writableByte] readonly attribute TestInterface putForwardsAttr;
   [PutForwards=writableByte, LenientThis] readonly attribute TestInterface putForwardsAttr2;
   [PutForwards=writableByte, ChromeOnly] readonly attribute TestInterface putForwardsAttr3;
   [Throws] void throwingMethod();
   [Throws] attribute boolean throwingAttr;
   [GetterThrows] attribute boolean throwingGetterAttr;
   [SetterThrows] attribute boolean throwingSetterAttr;
   legacycaller short(unsigned long arg1, TestInterface arg2);
+  void passArgsWithDefaults(optional long arg1,
+                            optional TestInterface? arg2 = null,
+                            optional Dict arg3, optional double arg4 = 5.0,
+                            optional float arg5);
 
   // If you add things here, add them to TestExampleGen and TestJSImplGen as well
 };
 
 interface TestParentInterface {
 };
 
 interface TestChildInterface : TestParentInterface {
--- a/dom/bindings/test/TestExampleGen.webidl
+++ b/dom/bindings/test/TestExampleGen.webidl
@@ -475,16 +475,20 @@ interface TestExampleInterface {
   [PutForwards=writableByte] readonly attribute TestExampleInterface putForwardsAttr;
   [PutForwards=writableByte, LenientThis] readonly attribute TestExampleInterface putForwardsAttr2;
   [PutForwards=writableByte, ChromeOnly] readonly attribute TestExampleInterface putForwardsAttr3;
   [Throws] void throwingMethod();
   [Throws] attribute boolean throwingAttr;
   [GetterThrows] attribute boolean throwingGetterAttr;
   [SetterThrows] attribute boolean throwingSetterAttr;
   legacycaller short(unsigned long arg1, TestInterface arg2);
+  void passArgsWithDefaults(optional long arg1,
+                            optional TestInterface? arg2 = null,
+                            optional Dict arg3, optional double arg4 = 5.0,
+                            optional float arg5);
 
   // If you add things here, add them to TestCodeGen and TestJSImplGen as well
 };
 
 interface TestExampleProxyInterface {
   getter long longIndexedGetter(unsigned long ix);
   deleter void (unsigned long ix);
   setter creator void longIndexedSetter(unsigned long y, long z);
--- a/dom/bindings/test/TestJSImplGen.webidl
+++ b/dom/bindings/test/TestJSImplGen.webidl
@@ -465,16 +465,21 @@ interface TestJSImplInterface {
   void passRenamedInterface(TestRenamedInterface arg);
   [PutForwards=writableByte] readonly attribute TestJSImplInterface putForwardsAttr;
   [PutForwards=writableByte, LenientThis] readonly attribute TestJSImplInterface putForwardsAttr2;
   [PutForwards=writableByte, ChromeOnly] readonly attribute TestJSImplInterface putForwardsAttr3;
   [Throws] void throwingMethod();
   [Throws] attribute boolean throwingAttr;
   [GetterThrows] attribute boolean throwingGetterAttr;
   [SetterThrows] attribute boolean throwingSetterAttr;
+  // legacycaller short(unsigned long arg1, TestInterface arg2);
+  void passArgsWithDefaults(optional long arg1,
+                            optional TestInterface? arg2 = null,
+                            optional Dict arg3, optional double arg4 = 5.0,
+                            optional float arg5);
 
   // If you add things here, add them to TestCodeGen as well
 };
 
 [NavigatorProperty="TestNavigator", JSImplementation="@mozilla.org/test;1"]
 interface TestNavigator {
 };