test_callback_constructor.py (2620B)
1 import WebIDL 2 3 4 def WebIDLTest(parser, harness): 5 parser.parse( 6 """ 7 interface TestCallbackConstructor { 8 attribute CallbackConstructorType? constructorAttribute; 9 }; 10 11 callback constructor CallbackConstructorType = TestCallbackConstructor (unsigned long arg); 12 """ 13 ) 14 15 results = parser.finish() 16 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", 25 ) 26 harness.check( 27 iface.identifier.name, "TestCallbackConstructor", "Interface has the right name" 28 ) 29 harness.check(len(iface.members), 1, "Expect %s members" % 1) 30 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", 40 ) 41 harness.check( 42 attr.identifier.name, "constructorAttribute", "Attr has the right name" 43 ) 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") 48 49 callback = results[1] 50 harness.ok(callback.isConstructor(), "Callback is constructor") 51 52 parser.reset() 53 threw = False 54 try: 55 parser.parse( 56 """ 57 [LegacyTreatNonObjectAsNull] 58 callback constructor CallbackConstructorType = object (); 59 """ 60 ) 61 results = parser.finish() 62 except WebIDL.WebIDLError: 63 threw = True 64 65 harness.ok( 66 threw, "Should throw on LegacyTreatNonObjectAsNull callback constructors" 67 ) 68 69 parser.reset() 70 threw = False 71 try: 72 parser.parse( 73 """ 74 [MOZ_CAN_RUN_SCRIPT_BOUNDARY] 75 callback constructor CallbackConstructorType = object (); 76 """ 77 ) 78 results = parser.finish() 79 except WebIDL.WebIDLError: 80 threw = True 81 82 harness.ok( 83 threw, "Should not permit MOZ_CAN_RUN_SCRIPT_BOUNDARY callback constructors" 84 )