Bug 1359269 - Part 6: Add support for attributes on types in dictionaries; r=bzbarsky

Depends on D19737

Differential Revision: https://phabricator.services.mozilla.com/D19738

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Manish Goregaokar 2019-03-02 04:21:41 +00:00
Родитель 2df29133e8
Коммит e7706facd8
3 изменённых файлов: 31 добавлений и 22 удалений

Просмотреть файл

@ -5915,23 +5915,32 @@ class Parser(Tokenizer):
p[0] = [p[2]]
p[0].extend(p[3])
def p_DictionaryMember(self, p):
def p_DictionaryMemberRequired(self, p):
"""
DictionaryMember : Required Type IDENTIFIER Default SEMICOLON
DictionaryMember : REQUIRED TypeWithExtendedAttributes IDENTIFIER SEMICOLON
"""
# These quack a lot like optional arguments, so just treat them that way.
# These quack a lot like required arguments, so just treat them that way.
t = p[2]
assert isinstance(t, IDLType)
identifier = IDLUnresolvedIdentifier(self.getLocation(p, 3), p[3])
defaultValue = p[4]
optional = not p[1]
if not optional and defaultValue:
raise WebIDLError("Required dictionary members can't have a default value.",
[self.getLocation(p, 4)])
p[0] = IDLArgument(self.getLocation(p, 3), identifier, t,
optional=optional,
optional=False,
defaultValue=None, variadic=False,
dictionaryMember=True)
def p_DictionaryMember(self, p):
"""
DictionaryMember : Type IDENTIFIER Default SEMICOLON
"""
# These quack a lot like optional arguments, so just treat them that way.
t = p[1]
assert isinstance(t, IDLType)
identifier = IDLUnresolvedIdentifier(self.getLocation(p, 2), p[2])
defaultValue = p[3]
p[0] = IDLArgument(self.getLocation(p, 2), identifier, t,
optional=True,
defaultValue=defaultValue, variadic=False,
dictionaryMember=True)
@ -6519,18 +6528,6 @@ class Parser(Tokenizer):
"""
p[0] = p[1]
def p_Required(self, p):
"""
Required : REQUIRED
"""
p[0] = True
def p_RequiredEmpty(self, p):
"""
Required :
"""
p[0] = False
def p_Ellipsis(self, p):
"""
Ellipsis : ELLIPSIS

Просмотреть файл

@ -1593,6 +1593,8 @@ class TestAttributesOnTypes : public nsISupports, public nsWrapperCache {
void Foo(uint8_t arg);
void Bar(uint8_t arg);
void Baz(const nsAString& arg);
uint8_t SomeAttr();
void SetSomeAttr(uint8_t);
void ArgWithAttr(uint8_t arg1, const Optional<uint8_t>& arg2);
};

Просмотреть файл

@ -1320,10 +1320,20 @@ typedef [EnforceRange] octet OctetRange;
typedef [Clamp] octet OctetClamp;
typedef [TreatNullAs=EmptyString] DOMString NullEmptyString;
dictionary TestAttributesOnDictionaryMembers {
[Clamp] octet a;
[ChromeOnly, Clamp] octet b;
required [Clamp] octet c;
[ChromeOnly] octet d;
// ChromeOnly doesn't mix with required, so we can't
// test [ChromeOnly] required [Clamp] octet e
};
interface TestAttributesOnTypes {
void foo(OctetClamp thingy);
void bar(OctetRange thingy);
void baz(NullEmptyString thingy);
attribute [Clamp] octet someAttr;
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