Update WebIDL

This commit is contained in:
sagudev
2023-02-19 13:36:13 +01:00
parent 6f563830d1
commit 4d393612b4
77 changed files with 9035 additions and 4668 deletions

View File

@@ -3,12 +3,15 @@ import itertools
import string
# We'd like to use itertools.chain but it's 2.6 or higher.
def chain(*iterables):
# chain('ABC', 'DEF') --> A B C D E F
for it in iterables:
for element in it:
yield element
# We'd like to use itertools.combinations but it's 2.6 or higher.
def combinations(iterable, r):
# combinations('ABCD', 2) --> AB AC AD BC BD CD
@@ -26,10 +29,11 @@ def combinations(iterable, r):
else:
return
indices[i] += 1
for j in range(i+1, r):
indices[j] = indices[j-1] + 1
for j in range(i + 1, r):
indices[j] = indices[j - 1] + 1
yield tuple(pool[i] for i in indices)
# We'd like to use itertools.combinations_with_replacement but it's 2.7 or
# higher.
def combinations_with_replacement(iterable, r):
@@ -49,27 +53,30 @@ def combinations_with_replacement(iterable, r):
indices[i:] = [indices[i] + 1] * (r - i)
yield tuple(pool[i] for i in indices)
def WebIDLTest(parser, harness):
types = ["float",
"double",
"short",
"unsigned short",
"long",
"unsigned long",
"long long",
"unsigned long long",
"boolean",
"byte",
"octet",
"DOMString",
"ByteString",
"USVString",
#"sequence<float>",
"object",
"ArrayBuffer",
#"Date",
"TestInterface1",
"TestInterface2"]
types = [
"float",
"double",
"short",
"unsigned short",
"long",
"unsigned long",
"long long",
"unsigned long long",
"boolean",
"byte",
"octet",
"DOMString",
"ByteString",
"USVString",
# "sequence<float>",
"object",
"ArrayBuffer",
# "Date",
"TestInterface1",
"TestInterface2",
]
testPre = """
interface TestInterface1 {
@@ -78,13 +85,18 @@ def WebIDLTest(parser, harness):
};
"""
interface = testPre + """
interface = (
testPre
+ """
interface PrepareForTest {
"""
)
for (i, type) in enumerate(types):
interface += string.Template("""
interface += string.Template(
"""
readonly attribute ${type} attr${i};
""").substitute(i=i, type=type)
"""
).substitute(i=i, type=type)
interface += """
};
"""
@@ -98,8 +110,10 @@ def WebIDLTest(parser, harness):
def typesAreDistinguishable(t):
return all(u[0].isDistinguishableFrom(u[1]) for u in combinations(t, 2))
def typesAreNotDistinguishable(t):
return any(not u[0].isDistinguishableFrom(u[1]) for u in combinations(t, 2))
def unionTypeName(t):
if len(t) > 2:
t[0:2] = [unionTypeName(t[0:2])]
@@ -118,29 +132,40 @@ def WebIDLTest(parser, harness):
# as a string and the parsed IDL type.
def invalidUnionWithUnion(typeCombinations):
for c in typeCombinations:
if (typesAreNotDistinguishable((c[0][1], c[1][1])) and
typesAreDistinguishable((c[1][1], c[2][1])) and
typesAreDistinguishable((c[0][1], c[2][1]))):
if (
typesAreNotDistinguishable((c[0][1], c[1][1]))
and typesAreDistinguishable((c[1][1], c[2][1]))
and typesAreDistinguishable((c[0][1], c[2][1]))
):
yield unionTypeName([t[0] for t in c])
# Create a list of tuples containing the name of the type as a string and
# the parsed IDL type.
types = zip(types, (a.type for a in iface.members))
validUnionTypes = chain(unionTypes(combinations(types, 2), typesAreDistinguishable),
unionTypes(combinations(types, 3), typesAreDistinguishable))
invalidUnionTypes = chain(unionTypes(combinations_with_replacement(types, 2), typesAreNotDistinguishable),
invalidUnionWithUnion(combinations(types, 3)))
interface = testPre + """
validUnionTypes = chain(
unionTypes(combinations(types, 2), typesAreDistinguishable),
unionTypes(combinations(types, 3), typesAreDistinguishable),
)
invalidUnionTypes = chain(
unionTypes(combinations_with_replacement(types, 2), typesAreNotDistinguishable),
invalidUnionWithUnion(combinations(types, 3)),
)
interface = (
testPre
+ """
interface TestUnion {
"""
)
for (i, type) in enumerate(validUnionTypes):
interface += string.Template("""
interface += string.Template(
"""
undefined method${i}(${type} arg);
${type} returnMethod${i}();
attribute ${type} attr${i};
undefined optionalMethod${i}(${type}? arg);
""").substitute(i=i, type=type)
"""
).substitute(i=i, type=type)
interface += """
};
"""
@@ -150,11 +175,16 @@ def WebIDLTest(parser, harness):
parser = parser.reset()
for invalid in invalidUnionTypes:
interface = testPre + string.Template("""
interface = (
testPre
+ string.Template(
"""
interface TestUnion {
undefined method(${type} arg);
};
""").substitute(type=invalid)
"""
).substitute(type=invalid)
)
threw = False
try: