Bug 1323274. Disallow nullable Promise types. r=qdot

This commit is contained in:
Boris Zbarsky 2016-12-16 14:06:54 -05:00
parent a4f102118b
commit f74b8c3888
6 changed files with 36 additions and 22 deletions

View File

@ -6398,17 +6398,17 @@ class Parser(Tokenizer):
type = IDLSequenceType(self.getLocation(p, 1), innerType)
p[0] = self.handleNullable(type, p[5])
# Note: Promise<void> is allowed, so we want to parametrize on
# ReturnType, not Type. Also, we want this to end up picking up
# the Promise interface for now, hence the games with IDLUnresolvedType.
# Note: Promise<void> is allowed, so we want to parametrize on ReturnType,
# not Type. Also, we want this to end up picking up the Promise interface
# for now, hence the games with IDLUnresolvedType. Promise types can't be
# null, hence no "Null" in there.
def p_NonAnyTypePromiseType(self, p):
"""
NonAnyType : PROMISE LT ReturnType GT Null
NonAnyType : PROMISE LT ReturnType GT
"""
innerType = p[3]
promiseIdent = IDLUnresolvedIdentifier(self.getLocation(p, 1), "Promise")
type = IDLUnresolvedType(self.getLocation(p, 1), promiseIdent, p[3])
p[0] = self.handleNullable(type, p[5])
p[0] = IDLUnresolvedType(self.getLocation(p, 1), promiseIdent, p[3])
def p_NonAnyTypeMozMapType(self, p):
"""

View File

@ -48,6 +48,36 @@ def WebIDLTest(parser, harness):
"Should not allow overloads which have both Promise and "
"non-Promise return types.")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface _Promise {};
interface A {
Promise<any>? foo();
};
""")
results = parser.finish();
except:
threw = True
harness.ok(threw,
"Should not allow nullable Promise return values.")
parser = parser.reset()
threw = False
try:
parser.parse("""
interface _Promise {};
interface A {
void foo(Promise<any>? arg);
};
""")
results = parser.finish();
except:
threw = True
harness.ok(threw,
"Should not allow nullable Promise arguments.")
parser = parser.reset()
parser.parse("""
interface _Promise {};

View File

@ -753,13 +753,9 @@ public:
// Promise types
void PassPromise(Promise&);
void PassNullablePromise(Promise*);
void PassOptionalPromise(const Optional<OwningNonNull<Promise>>&);
void PassOptionalNullablePromise(const Optional<RefPtr<Promise>>&);
void PassOptionalNullablePromiseWithDefaultValue(Promise*);
void PassPromiseSequence(const Sequence<OwningNonNull<Promise>>&);
void PassPromiseMozMap(const MozMap<RefPtr<Promise>>&);
void PassNullablePromiseSequence(const Sequence<RefPtr<Promise>> &);
Promise* ReceivePromise();
already_AddRefed<Promise> ReceiveAddrefedPromise();

View File

@ -731,12 +731,8 @@ interface TestInterface {
// Promise types
void passPromise(Promise<any> arg);
void passNullablePromise(Promise<any>? arg);
void passOptionalPromise(optional Promise<any> arg);
void passOptionalNullablePromise(optional Promise<any>? arg);
void passOptionalNullablePromiseWithDefaultValue(optional Promise<any>? arg = null);
void passPromiseSequence(sequence<Promise<any>> arg);
void passNullablePromiseSequence(sequence<Promise<any>?> arg);
Promise<any> receivePromise();
Promise<any> receiveAddrefedPromise();

View File

@ -566,12 +566,8 @@ interface TestExampleInterface {
// Promise types
void passPromise(Promise<any> arg);
void passNullablePromise(Promise<any>? arg);
void passOptionalPromise(optional Promise<any> arg);
void passOptionalNullablePromise(optional Promise<any>? arg);
void passOptionalNullablePromiseWithDefaultValue(optional Promise<any>? arg = null);
void passPromiseSequence(sequence<Promise<any>> arg);
void passNullablePromiseSequence(sequence<Promise<any>?> arg);
Promise<any> receivePromise();
Promise<any> receiveAddrefedPromise();

View File

@ -578,12 +578,8 @@ interface TestJSImplInterface {
// Promise types
void passPromise(Promise<any> arg);
void passNullablePromise(Promise<any>? arg);
void passOptionalPromise(optional Promise<any> arg);
void passOptionalNullablePromise(optional Promise<any>? arg);
void passOptionalNullablePromiseWithDefaultValue(optional Promise<any>? arg = null);
void passPromiseSequence(sequence<Promise<any>> arg);
void passNullablePromiseSequence(sequence<Promise<any>?> arg);
Promise<any> receivePromise();
Promise<any> receiveAddrefedPromise();