test_treatNonCallableAsNull.py (1845B)
1 import WebIDL 2 3 4 def WebIDLTest(parser, harness): 5 parser.parse( 6 """ 7 [TreatNonCallableAsNull] callback Function = any(any... arguments); 8 9 interface TestTreatNonCallableAsNull1 { 10 attribute Function? onfoo; 11 attribute Function onbar; 12 }; 13 """ 14 ) 15 16 results = parser.finish() 17 18 iface = results[1] 19 attr = iface.members[0] 20 harness.check(attr.type.treatNonCallableAsNull(), True, "Got the expected value") 21 attr = iface.members[1] 22 harness.check(attr.type.treatNonCallableAsNull(), False, "Got the expected value") 23 24 parser = parser.reset() 25 26 threw = False 27 try: 28 parser.parse( 29 """ 30 callback Function = any(any... arguments); 31 32 interface TestTreatNonCallableAsNull2 { 33 [TreatNonCallableAsNull] attribute Function onfoo; 34 }; 35 """ 36 ) 37 38 results = parser.finish() 39 except WebIDL.WebIDLError: 40 threw = True 41 42 harness.ok(threw, "Should have thrown.") 43 44 parser = parser.reset() 45 46 threw = False 47 try: 48 parser.parse( 49 """ 50 callback Function = any(any... arguments); 51 52 [TreatNonCallableAsNull] 53 interface TestTreatNonCallableAsNull3 { 54 attribute Function onfoo; 55 }; 56 """ 57 ) 58 59 results = parser.finish() 60 except WebIDL.WebIDLError: 61 threw = True 62 63 harness.ok(threw, "Should have thrown.") 64 65 parser = parser.reset() 66 67 threw = False 68 try: 69 parser.parse( 70 """ 71 [TreatNonCallableAsNull, LegacyTreatNonObjectAsNull] 72 callback Function = any(any... arguments); 73 """ 74 ) 75 76 results = parser.finish() 77 except WebIDL.WebIDLError: 78 threw = True 79 80 harness.ok(threw, "Should have thrown.")