4 def WebIDLTest(parser
, harness
):
7 interface TestNullableEquivalency1 {
12 interface TestNullableEquivalency2 {
13 attribute ArrayBuffer a;
14 attribute ArrayBuffer? b;
17 /* Can't have dictionary-valued attributes, so can't test that here */
19 enum TestNullableEquivalency4Enum {
24 interface TestNullableEquivalency4 {
25 attribute TestNullableEquivalency4Enum a;
26 attribute TestNullableEquivalency4Enum? b;
29 interface TestNullableEquivalency5 {
30 attribute TestNullableEquivalency4 a;
31 attribute TestNullableEquivalency4? b;
34 interface TestNullableEquivalency6 {
39 interface TestNullableEquivalency7 {
40 attribute DOMString a;
41 attribute DOMString? b;
44 interface TestNullableEquivalency8 {
49 interface TestNullableEquivalency9 {
54 interface TestNullableEquivalency10 {
61 for decl
in parser
.finish():
62 if decl
.isInterface():
63 checkEquivalent(decl
, harness
)
66 def checkEquivalent(iface
, harness
):
67 type1
= iface
.members
[0].type
68 type2
= iface
.members
[1].type
70 harness
.check(type1
.nullable(), False, "attr1 should not be nullable")
71 harness
.check(type2
.nullable(), True, "attr2 should be nullable")
73 # We don't know about type1, but type2, the nullable type, definitely
74 # shouldn't be builtin.
75 harness
.check(type2
.builtin
, False, "attr2 should not be builtin")
77 # Ensure that all attributes of type2 match those in type1, except for:
78 # - names on an ignore list,
79 # - names beginning with '_',
80 # - functions which throw when called with no args, and
81 # - class-level non-callables ("static variables").
83 # Yes, this is an ugly, fragile hack. But it finds bugs...
84 for attr
in dir(type1
):
99 or (hasattr(type(type1
), attr
) and not callable(getattr(type1
, attr
)))
103 a1
= getattr(type1
, attr
)
108 except AssertionError:
109 # Various methods assert that they're called on objects of
110 # the right type, skip them if the assert fails.
113 # a1 requires positional arguments, so skip this attribute.
117 a2
= getattr(type2
, attr
)
118 except WebIDL
.WebIDLError
:
121 "Missing %s attribute on type %s in %s" % (attr
, type2
, iface
),
128 "%s attribute on type %s in %s wasn't callable"
129 % (attr
, type2
, iface
),
134 harness
.check(v2
, v1
, "%s method return value" % attr
)
137 a2
= getattr(type2
, attr
)
138 except WebIDL
.WebIDLError
:
141 "Missing %s attribute on type %s in %s" % (attr
, type2
, iface
),
145 harness
.check(a2
, a1
, "%s attribute should match" % attr
)