4 def WebIDLTest(parser
, harness
):
15 except WebIDL
.WebIDLError
:
17 harness
.ok(not threw
, "Should allow a toJSON method.")
19 parser
= parser
.reset()
25 object toJSON(object arg);
26 object toJSON(long arg);
31 except WebIDL
.WebIDLError
:
33 harness
.ok(threw
, "Should not allow overloads of a toJSON method.")
35 parser
= parser
.reset()
41 object toJSON(object arg);
46 except WebIDL
.WebIDLError
:
48 harness
.ok(threw
, "Should not allow a toJSON method with arguments.")
50 parser
= parser
.reset()
61 except WebIDL
.WebIDLError
:
63 harness
.ok(not threw
, "Should allow a toJSON method with 'long' as return type.")
65 parser
= parser
.reset()
71 [Default] object toJSON();
76 except WebIDL
.WebIDLError
:
79 not threw
, "Should allow a default toJSON method with 'object' as return type."
82 parser
= parser
.reset()
88 [Default] long toJSON();
93 except WebIDL
.WebIDLError
:
97 "Should not allow a default toJSON method with non-'object' as return type.",
108 "unsigned long long",
110 "unrestricted float",
112 "unrestricted double",
119 "InterfaceWithToJSON",
124 "InterfaceWithoutToJSON",
138 def doTest(testIDL
, shouldThrow
, description
):
145 enum Enum { "a", "b", "c" };
146 interface InterfaceWithToJSON { long toJSON(); };
147 interface InterfaceWithoutToJSON {};
151 except Exception as x
:
153 harness
.ok(x
.message
== "toJSON method has non-JSON return type", x
)
154 harness
.check(threw
, shouldThrow
, description
)
156 for type in JsonTypes
:
158 "interface Test { %s toJSON(); };" % type,
160 "%s should be a JSON type" % type,
164 "interface Test { sequence<%s> toJSON(); };" % type,
166 "sequence<%s> should be a JSON type" % type,
170 "dictionary Foo { %s foo; }; " "interface Test { Foo toJSON(); }; " % type,
172 "dictionary containing only JSON type (%s) should be a JSON type" % type,
176 "dictionary Foo { %s foo; }; dictionary Bar : Foo { }; "
177 "interface Test { Bar toJSON(); }; " % type,
179 "dictionary whose ancestors only contain JSON types should be a JSON type",
183 "dictionary Foo { any foo; }; dictionary Bar : Foo { %s bar; };"
184 "interface Test { Bar toJSON(); };" % type,
186 "dictionary whose ancestors contain non-JSON types should not be a JSON type",
190 "interface Test { record<DOMString, %s> toJSON(); };" % type,
192 "record<DOMString, %s> should be a JSON type" % type,
196 "interface Test { record<ByteString, %s> toJSON(); };" % type,
198 "record<ByteString, %s> should be a JSON type" % type,
202 "interface Test { record<UTF8String, %s> toJSON(); };" % type,
204 "record<UTF8String, %s> should be a JSON type" % type,
208 "interface Test { record<USVString, %s> toJSON(); };" % type,
210 "record<USVString, %s> should be a JSON type" % type,
213 otherUnionType
= "Foo" if type != "object" else "long"
215 "interface Foo { object toJSON(); };"
216 "interface Test { (%s or %s) toJSON(); };" % (otherUnionType
, type),
218 "union containing only JSON types (%s or %s) should be a JSON type"
219 % (otherUnionType
, type),
223 "interface test { %s? toJSON(); };" % type,
225 "Nullable type (%s) should be a JSON type" % type,
229 "interface Foo : InterfaceWithoutToJSON { %s toJSON(); };"
230 "interface Test { Foo toJSON(); };" % type,
232 "interface with toJSON should be a JSON type",
236 "interface Foo : InterfaceWithToJSON { };" "interface Test { Foo toJSON(); };",
238 "inherited interface with toJSON should be a JSON type",
241 for type in nonJsonTypes
:
243 "interface Test { %s toJSON(); };" % type,
245 "%s should not be a JSON type" % type,
249 "interface Test { sequence<%s> toJSON(); };" % type,
251 "sequence<%s> should not be a JSON type" % type,
255 "dictionary Foo { %s foo; }; " "interface Test { Foo toJSON(); }; " % type,
257 "Dictionary containing a non-JSON type (%s) should not be a JSON type"
262 "dictionary Foo { %s foo; }; dictionary Bar : Foo { }; "
263 "interface Test { Bar toJSON(); }; " % type,
265 "dictionary whose ancestors only contain non-JSON types should not be a JSON type",
269 "interface Test { record<DOMString, %s> toJSON(); };" % type,
271 "record<DOMString, %s> should not be a JSON type" % type,
275 "interface Test { record<ByteString, %s> toJSON(); };" % type,
277 "record<ByteString, %s> should not be a JSON type" % type,
281 "interface Test { record<USVString, %s> toJSON(); };" % type,
283 "record<USVString, %s> should not be a JSON type" % type,
288 "interface Foo { object toJSON(); }; "
289 "interface Test { (Foo or %s) toJSON(); };" % type,
291 "union containing a non-JSON type (%s) should not be a JSON type"
296 "interface test { %s? toJSON(); };" % type,
298 "Nullable type (%s) should not be a JSON type" % type,
302 "dictionary Foo { long foo; any bar; };" "interface Test { Foo toJSON(); };",
304 "dictionary containing a non-JSON type should not be a JSON type",
308 "interface Foo : InterfaceWithoutToJSON { }; "
309 "interface Test { Foo toJSON(); };",
311 "interface without toJSON should not be a JSON type",