mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-03 12:35:58 +00:00
Bug 884373. Align WebIDL handling of default parameters with ES6. r=khuey
This commit is contained in:
parent
82d227bc23
commit
577cd0be78
@ -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():
|
||||
|
@ -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")
|
||||
|
@ -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<int32_t>&,
|
||||
TestInterface*, const Dict&, double,
|
||||
const Optional<float>&);
|
||||
|
||||
// Methods and properties imported via "implements"
|
||||
bool ImplementedProperty();
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user