test_newobject.py (1959B)
1 import WebIDL 2 3 4 # Import the WebIDL module, so we can do isinstance checks and whatnot 5 def WebIDLTest(parser, harness): 6 # Basic functionality 7 parser.parse( 8 """ 9 interface Iface { 10 [NewObject] readonly attribute Iface attr; 11 [NewObject] Iface method(); 12 }; 13 """ 14 ) 15 results = parser.finish() 16 harness.ok(results, "Should not have thrown on basic [NewObject] usage") 17 18 parser = parser.reset() 19 threw = False 20 try: 21 parser.parse( 22 """ 23 interface Iface { 24 [Pure, NewObject] readonly attribute Iface attr; 25 }; 26 """ 27 ) 28 parser.finish() 29 except WebIDL.WebIDLError: 30 threw = True 31 harness.ok(threw, "[NewObject] attributes must depend on something") 32 33 parser = parser.reset() 34 threw = False 35 try: 36 parser.parse( 37 """ 38 interface Iface { 39 [Pure, NewObject] Iface method(); 40 }; 41 """ 42 ) 43 parser.finish() 44 except WebIDL.WebIDLError: 45 threw = True 46 harness.ok(threw, "[NewObject] methods must depend on something") 47 48 parser = parser.reset() 49 threw = False 50 try: 51 parser.parse( 52 """ 53 interface Iface { 54 [Cached, NewObject, Affects=Nothing] readonly attribute Iface attr; 55 }; 56 """ 57 ) 58 parser.finish() 59 except WebIDL.WebIDLError: 60 threw = True 61 harness.ok(threw, "[NewObject] attributes must not be [Cached]") 62 63 parser = parser.reset() 64 threw = False 65 try: 66 parser.parse( 67 """ 68 interface Iface { 69 [StoreInSlot, NewObject, Affects=Nothing] readonly attribute Iface attr; 70 }; 71 """ 72 ) 73 parser.finish() 74 except WebIDL.WebIDLError: 75 threw = True 76 harness.ok(threw, "[NewObject] attributes must not be [StoreInSlot]")