test_conditional_dictionary_member.py (3229B)
1 def WebIDLTest(parser, harness): 2 parser.parse( 3 """ 4 dictionary Dict { 5 any foo; 6 [ChromeOnly] any bar; 7 }; 8 """ 9 ) 10 results = parser.finish() 11 harness.check(len(results), 1, "Should have a dictionary") 12 members = results[0].members 13 harness.check(len(members), 2, "Should have two members") 14 # Note that members are ordered lexicographically, so "bar" comes 15 # before "foo". 16 harness.ok( 17 members[0].getExtendedAttribute("ChromeOnly"), "First member is not ChromeOnly" 18 ) 19 harness.ok( 20 not members[1].getExtendedAttribute("ChromeOnly"), "Second member is ChromeOnly" 21 ) 22 23 parser = parser.reset() 24 parser.parse( 25 """ 26 dictionary Dict { 27 any foo; 28 any bar; 29 }; 30 31 interface Iface { 32 [Constant, Cached] readonly attribute Dict dict; 33 }; 34 """ 35 ) 36 results = parser.finish() 37 harness.check(len(results), 2, "Should have a dictionary and an interface") 38 39 parser = parser.reset() 40 exception = None 41 try: 42 parser.parse( 43 """ 44 dictionary Dict { 45 any foo; 46 [ChromeOnly] any bar; 47 }; 48 49 interface Iface { 50 [Constant, Cached] readonly attribute Dict dict; 51 }; 52 """ 53 ) 54 results = parser.finish() 55 except Exception as e: 56 exception = e 57 58 harness.ok(exception, "Should have thrown.") 59 harness.check( 60 exception.message, 61 "[Cached] and [StoreInSlot] must not be used on an attribute " 62 "whose type contains a [ChromeOnly] dictionary member", 63 "Should have thrown the right exception", 64 ) 65 66 parser = parser.reset() 67 exception = None 68 try: 69 parser.parse( 70 """ 71 dictionary ParentDict { 72 [ChromeOnly] any bar; 73 }; 74 75 dictionary Dict : ParentDict { 76 any foo; 77 }; 78 79 interface Iface { 80 [Constant, Cached] readonly attribute Dict dict; 81 }; 82 """ 83 ) 84 results = parser.finish() 85 except Exception as e: 86 exception = e 87 88 harness.ok(exception, "Should have thrown (2).") 89 harness.check( 90 exception.message, 91 "[Cached] and [StoreInSlot] must not be used on an attribute " 92 "whose type contains a [ChromeOnly] dictionary member", 93 "Should have thrown the right exception (2)", 94 ) 95 96 parser = parser.reset() 97 exception = None 98 try: 99 parser.parse( 100 """ 101 dictionary GrandParentDict { 102 [ChromeOnly] any baz; 103 }; 104 105 dictionary ParentDict : GrandParentDict { 106 any bar; 107 }; 108 109 dictionary Dict : ParentDict { 110 any foo; 111 }; 112 113 interface Iface { 114 [Constant, Cached] readonly attribute Dict dict; 115 }; 116 """ 117 ) 118 results = parser.finish() 119 except Exception as e: 120 exception = e 121 122 harness.ok(exception, "Should have thrown (3).") 123 harness.check( 124 exception.message, 125 "[Cached] and [StoreInSlot] must not be used on an attribute " 126 "whose type contains a [ChromeOnly] dictionary member", 127 "Should have thrown the right exception (3)", 128 )