Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / bindings / parser / tests / test_callback_constructor.py
blob67ea8ff755a4baca0ce5f066a245afe845aff215
1 import WebIDL
4 def WebIDLTest(parser, harness):
5 parser.parse(
6 """
7 interface TestCallbackConstructor {
8 attribute CallbackConstructorType? constructorAttribute;
9 };
11 callback constructor CallbackConstructorType = TestCallbackConstructor (unsigned long arg);
12 """
15 results = parser.finish()
17 harness.ok(True, "TestCallbackConstructor interface parsed without error.")
18 harness.check(len(results), 2, "Should be two productions.")
19 iface = results[0]
20 harness.ok(isinstance(iface, WebIDL.IDLInterface), "Should be an IDLInterface")
21 harness.check(
22 iface.identifier.QName(),
23 "::TestCallbackConstructor",
24 "Interface has the right QName",
26 harness.check(
27 iface.identifier.name, "TestCallbackConstructor", "Interface has the right name"
29 harness.check(len(iface.members), 1, "Expect %s members" % 1)
31 attr = iface.members[0]
32 harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute")
33 harness.ok(attr.isAttr(), "Should be an attribute")
34 harness.ok(not attr.isMethod(), "Attr is not an method")
35 harness.ok(not attr.isConst(), "Attr is not a const")
36 harness.check(
37 attr.identifier.QName(),
38 "::TestCallbackConstructor::constructorAttribute",
39 "Attr has the right QName",
41 harness.check(
42 attr.identifier.name, "constructorAttribute", "Attr has the right name"
44 t = attr.type
45 harness.ok(not isinstance(t, WebIDL.IDLWrapperType), "Attr has the right type")
46 harness.ok(isinstance(t, WebIDL.IDLNullableType), "Attr has the right type")
47 harness.ok(t.isCallback(), "Attr has the right type")
49 callback = results[1]
50 harness.ok(callback.isConstructor(), "Callback is constructor")
52 parser.reset()
53 threw = False
54 try:
55 parser.parse(
56 """
57 [LegacyTreatNonObjectAsNull]
58 callback constructor CallbackConstructorType = object ();
59 """
61 results = parser.finish()
62 except WebIDL.WebIDLError:
63 threw = True
65 harness.ok(
66 threw, "Should throw on LegacyTreatNonObjectAsNull callback constructors"
69 parser.reset()
70 threw = False
71 try:
72 parser.parse(
73 """
74 [MOZ_CAN_RUN_SCRIPT_BOUNDARY]
75 callback constructor CallbackConstructorType = object ();
76 """
78 results = parser.finish()
79 except WebIDL.WebIDLError:
80 threw = True
82 harness.ok(
83 threw, "Should not permit MOZ_CAN_RUN_SCRIPT_BOUNDARY callback constructors"