4 def WebIDLTest(parser
, harness
):
7 dictionary Dict2 : Dict1 {
17 results
= parser
.finish()
22 harness
.check(len(dict1
.members
), 2, "Dict1 has two members")
23 harness
.check(len(dict2
.members
), 2, "Dict2 has four members")
26 dict1
.members
[0].identifier
.name
, "otherParent", "'o' comes before 'p'"
29 dict1
.members
[1].identifier
.name
, "parent", "'o' really comes before 'p'"
32 dict2
.members
[0].identifier
.name
, "aaandAnother", "'a' comes before 'c'"
35 dict2
.members
[1].identifier
.name
, "child", "'a' really comes before 'c'"
38 # Test partial dictionary.
39 parser
= parser
.reset()
46 partial dictionary A {
52 results
= parser
.finish()
55 harness
.check(len(dict1
.members
), 4, "Dict1 has four members")
56 harness
.check(dict1
.members
[0].identifier
.name
, "c", "c should be first")
57 harness
.check(dict1
.members
[1].identifier
.name
, "d", "d should come after c")
58 harness
.check(dict1
.members
[2].identifier
.name
, "g", "g should come after d")
59 harness
.check(dict1
.members
[3].identifier
.name
, "h", "h should be last")
61 # Now reset our parser
62 parser
= parser
.reset()
74 except WebIDL
.WebIDLError
:
77 harness
.ok(threw
, "Should not allow name duplication in a dictionary")
79 # Test no name duplication across normal and partial dictionary.
80 parser
= parser
.reset()
88 partial dictionary A {
94 except WebIDL
.WebIDLError
:
98 threw
, "Should not allow name duplication across normal and partial dictionary"
101 # Now reset our parser again
102 parser
= parser
.reset()
107 dictionary Dict1 : Dict2 {
110 dictionary Dict2 : Dict3 {
119 except WebIDL
.WebIDLError
:
123 threw
, "Should not allow name duplication in a dictionary and " "its ancestor"
127 parser
= parser
.reset()
133 dictionary Dict : Iface {
139 except WebIDL
.WebIDLError
:
142 harness
.ok(threw
, "Should not allow non-dictionary parents for dictionaries")
145 parser
= parser
.reset()
155 except WebIDL
.WebIDLError
:
158 harness
.ok(threw
, "Should not allow cycles in dictionary inheritance chains")
160 parser
= parser
.reset()
166 [LegacyNullToEmptyString] DOMString foo;
171 except WebIDL
.WebIDLError
:
175 threw
, "Should not allow [LegacyNullToEmptyString] on dictionary members"
178 parser
= parser
.reset()
186 undefined doFoo(A arg);
191 except WebIDL
.WebIDLError
:
194 harness
.ok(threw
, "Trailing dictionary arg must be optional")
196 parser
= parser
.reset()
204 undefined doFoo(optional A arg);
209 except WebIDL
.WebIDLError
:
212 harness
.ok(threw
, "Trailing dictionary arg must have a default value")
214 parser
= parser
.reset()
222 undefined doFoo((A or DOMString) arg);
227 except WebIDL
.WebIDLError
:
230 harness
.ok(threw
, "Trailing union arg containing a dictionary must be optional")
232 parser
= parser
.reset()
240 undefined doFoo(optional (A or DOMString) arg);
245 except WebIDL
.WebIDLError
:
249 threw
, "Trailing union arg containing a dictionary must have a default value"
252 parser
= parser
.reset()
260 undefined doFoo(A arg1, optional long arg2);
265 except WebIDL
.WebIDLError
:
268 harness
.ok(threw
, "Dictionary arg followed by optional arg must be optional")
270 parser
= parser
.reset()
278 undefined doFoo(optional A arg1, optional long arg2);
283 except WebIDL
.WebIDLError
:
286 harness
.ok(threw
, "Dictionary arg followed by optional arg must have default value")
288 parser
= parser
.reset()
296 undefined doFoo(A arg1, optional long arg2, long arg3);
301 except WebIDL
.WebIDLError
:
306 "Dictionary arg followed by non-optional arg doesn't have to be optional",
309 parser
= parser
.reset()
317 undefined doFoo((A or DOMString) arg1, optional long arg2);
322 except WebIDL
.WebIDLError
:
327 "Union arg containing dictionary followed by optional arg must " "be optional",
330 parser
= parser
.reset()
338 undefined doFoo(optional (A or DOMString) arg1, optional long arg2);
343 except WebIDL
.WebIDLError
:
348 "Union arg containing dictionary followed by optional arg must "
349 "have a default value",
352 parser
= parser
.reset()
358 undefined doFoo(A arg1, long arg2);
363 harness
.ok(True, "Dictionary arg followed by required arg can be required")
365 parser
= parser
.reset()
373 undefined doFoo(optional A? arg1 = {});
378 except Exception as x
:
381 harness
.ok(threw
, "Optional dictionary arg must not be nullable")
383 "nullable" in str(threw
),
384 "Must have the expected exception for optional nullable dictionary arg",
387 parser
= parser
.reset()
396 undefined doFoo(A? arg1);
401 except Exception as x
:
404 harness
.ok(threw
, "Required dictionary arg must not be nullable")
406 "nullable" in str(threw
),
407 "Must have the expected exception for required nullable " "dictionary arg",
410 parser
= parser
.reset()
418 undefined doFoo(optional (A or long)? arg1 = {});
423 except Exception as x
:
426 harness
.ok(threw
, "Dictionary arg must not be in an optional nullable union")
428 "nullable" in str(threw
),
429 "Must have the expected exception for optional nullable union "
430 "arg containing dictionary",
433 parser
= parser
.reset()
442 undefined doFoo((A or long)? arg1);
447 except Exception as x
:
450 harness
.ok(threw
, "Dictionary arg must not be in a required nullable union")
452 "nullable" in str(threw
),
453 "Must have the expected exception for required nullable union "
454 "arg containing dictionary",
457 parser
= parser
.reset()
465 undefined doFoo(sequence<A?> arg1);
470 except WebIDL
.WebIDLError
:
473 harness
.ok(not threw
, "Nullable union should be allowed in a sequence argument")
475 parser
= parser
.reset()
483 undefined doFoo(optional (A or long?) arg1);
488 except WebIDL
.WebIDLError
:
490 harness
.ok(threw
, "Dictionary must not be in a union with a nullable type")
492 parser
= parser
.reset()
500 undefined doFoo(optional (long? or A) arg1);
505 except WebIDL
.WebIDLError
:
507 harness
.ok(threw
, "A nullable type must not be in a union with a dictionary")
509 parser
= parser
.reset()
520 harness
.ok(True, "Dictionary return value can be nullable")
522 parser
= parser
.reset()
528 undefined doFoo(optional A arg = {});
533 harness
.ok(True, "Dictionary arg should actually parse")
535 parser
= parser
.reset()
541 undefined doFoo(optional (A or DOMString) arg = {});
546 harness
.ok(True, "Union arg containing a dictionary should actually parse")
548 parser
= parser
.reset()
554 undefined doFoo(optional (A or DOMString) arg = "abc");
561 "Union arg containing a dictionary with string default should actually parse",
564 parser
= parser
.reset()
575 except WebIDL
.WebIDLError
:
578 harness
.ok(threw
, "Member type must not be its Dictionary.")
580 parser
= parser
.reset()
585 dictionary Foo3 : Foo {
589 dictionary Foo2 : Foo3 {
593 dictionary Foo1 : Foo2 {
603 except WebIDL
.WebIDLError
:
608 "Member type must not be a Dictionary that " "inherits from its Dictionary.",
611 parser
= parser
.reset()
617 (Foo or DOMString)[]? b;
622 except WebIDL
.WebIDLError
:
627 "Member type must not be a Nullable type "
628 "whose inner type includes its Dictionary.",
631 parser
= parser
.reset()
637 (DOMString or Foo) b;
642 except WebIDL
.WebIDLError
:
647 "Member type must not be a Union type, one of "
648 "whose member types includes its Dictionary.",
651 parser
= parser
.reset()
657 sequence<sequence<sequence<Foo>>> c;
662 except WebIDL
.WebIDLError
:
667 "Member type must not be a Sequence type "
668 "whose element type includes its Dictionary.",
671 parser
= parser
.reset()
677 (DOMString or Foo)[] d;
682 except WebIDL
.WebIDLError
:
687 "Member type must not be an Array type "
688 "whose element type includes its Dictionary.",
691 parser
= parser
.reset()
704 dictionary Foo2 : Foo3 {
708 dictionary Foo1 : Foo2 {
714 except WebIDL
.WebIDLError
:
719 "Member type must not be a Dictionary, one of whose "
720 "members or inherited members has a type that includes "
724 parser
= parser
.reset()
738 except WebIDL
.WebIDLError
:
741 harness
.ok(threw
, "Member type must not be a nullable dictionary")
743 parser
= parser
.reset()
747 unrestricted float urFloat = 0;
748 unrestricted float urFloat2 = 1.1;
749 unrestricted float urFloat3 = -1.1;
750 unrestricted float? urFloat4 = null;
751 unrestricted float infUrFloat = Infinity;
752 unrestricted float negativeInfUrFloat = -Infinity;
753 unrestricted float nanUrFloat = NaN;
755 unrestricted double urDouble = 0;
756 unrestricted double urDouble2 = 1.1;
757 unrestricted double urDouble3 = -1.1;
758 unrestricted double? urDouble4 = null;
759 unrestricted double infUrDouble = Infinity;
760 unrestricted double negativeInfUrDouble = -Infinity;
761 unrestricted double nanUrDouble = NaN;
766 harness
.ok(True, "Parsing default values for unrestricted types succeeded.")
768 parser
= parser
.reset()
779 except WebIDL
.WebIDLError
:
782 harness
.ok(threw
, "Only unrestricted values can be initialized to Infinity")
784 parser
= parser
.reset()
790 double f = -Infinity;
795 except WebIDL
.WebIDLError
:
798 harness
.ok(threw
, "Only unrestricted values can be initialized to -Infinity")
800 parser
= parser
.reset()
811 except WebIDL
.WebIDLError
:
814 harness
.ok(threw
, "Only unrestricted values can be initialized to NaN")
816 parser
= parser
.reset()
827 except WebIDL
.WebIDLError
:
830 harness
.ok(threw
, "Only unrestricted values can be initialized to Infinity")
832 parser
= parser
.reset()
843 except WebIDL
.WebIDLError
:
846 harness
.ok(threw
, "Only unrestricted values can be initialized to -Infinity")
848 parser
= parser
.reset()
859 except WebIDL
.WebIDLError
:
862 harness
.ok(threw
, "Only unrestricted values can be initialized to NaN")
864 parser
= parser
.reset()
875 except WebIDL
.WebIDLError
:
878 harness
.ok(not threw
, "Should be able to use 'module' as a dictionary member name")