diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 9adc1c781e40..33537378d378 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -2962,7 +2962,6 @@ class IDLMethod(IDLInterfaceMember, IDLScope): for overload in self._overloads: inOptionalArguments = False variadicArgument = None - sawOptionalWithNoDefault = False arguments = overload.arguments for (idx, argument) in enumerate(arguments): @@ -3003,18 +3002,9 @@ class IDLMethod(IDLInterfaceMember, IDLScope): 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(): diff --git a/dom/bindings/parser/tests/test_optional_constraints.py b/dom/bindings/parser/tests/test_optional_constraints.py index 1dcdc7fb8a51..99fd07fe93f8 100644 --- a/dom/bindings/parser/tests/test_optional_constraints.py +++ b/dom/bindings/parser/tests/test_optional_constraints.py @@ -11,4 +11,20 @@ def WebIDLTest(parser, harness): 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") diff --git a/dom/bindings/test/TestBindingHeader.h b/dom/bindings/test/TestBindingHeader.h index 94410d079ba3..9872c62a8236 100644 --- a/dom/bindings/test/TestBindingHeader.h +++ b/dom/bindings/test/TestBindingHeader.h @@ -610,6 +610,9 @@ public: bool ThrowingSetterAttr() const; void SetThrowingSetterAttr(bool arg, ErrorResult& aRv); int16_t LegacyCall(JS::Value, uint32_t, TestInterface&); + void PassArgsWithDefaults(JSContext*, const Optional&, + TestInterface*, const Dict&, double, + const Optional&); // Methods and properties imported via "implements" bool ImplementedProperty(); diff --git a/dom/bindings/test/TestCodeGen.webidl b/dom/bindings/test/TestCodeGen.webidl index 3d66ac638942..c98a00dccb01 100644 --- a/dom/bindings/test/TestCodeGen.webidl +++ b/dom/bindings/test/TestCodeGen.webidl @@ -583,6 +583,10 @@ interface TestInterface { [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 }; diff --git a/dom/bindings/test/TestExampleGen.webidl b/dom/bindings/test/TestExampleGen.webidl index 3174440dc1dd..499ddd5ec356 100644 --- a/dom/bindings/test/TestExampleGen.webidl +++ b/dom/bindings/test/TestExampleGen.webidl @@ -480,6 +480,10 @@ interface TestExampleInterface { [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 }; diff --git a/dom/bindings/test/TestJSImplGen.webidl b/dom/bindings/test/TestJSImplGen.webidl index 1b575c38ad6f..a933af2d37fe 100644 --- a/dom/bindings/test/TestJSImplGen.webidl +++ b/dom/bindings/test/TestJSImplGen.webidl @@ -470,6 +470,11 @@ interface TestJSImplInterface { [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 };