test_stringifier.py (4943B)
1 import WebIDL 2 3 4 def WebIDLTest(parser, harness): 5 parser.parse( 6 """ 7 interface TestStringifier { 8 stringifier; 9 }; 10 """ 11 ) 12 13 results = parser.finish() 14 15 harness.ok( 16 isinstance(results[0].members[0], WebIDL.IDLMethod), 17 "Stringifer should be method", 18 ) 19 20 parser = parser.reset() 21 22 threw = False 23 try: 24 parser.parse( 25 """ 26 interface TestStringifier { 27 stringifier; 28 stringifier; 29 }; 30 """ 31 ) 32 results = parser.finish() 33 except WebIDL.WebIDLError: 34 threw = True 35 36 harness.ok(threw, "Should not allow two 'stringifier;'") 37 38 parser = parser.reset() 39 40 threw = False 41 try: 42 parser.parse( 43 """ 44 interface TestStringifier { 45 stringifier; 46 stringifier DOMString foo(); 47 }; 48 """ 49 ) 50 results = parser.finish() 51 except WebIDL.WebIDLError: 52 threw = True 53 54 harness.ok(threw, "Should not allow a 'stringifier;' and a 'stringifier()'") 55 56 parser = parser.reset() 57 parser.parse( 58 """ 59 interface TestStringifier { 60 stringifier attribute DOMString foo; 61 }; 62 """ 63 ) 64 results = parser.finish() 65 harness.ok( 66 isinstance(results[0].members[0], WebIDL.IDLAttribute), 67 "Stringifier attribute should be an attribute", 68 ) 69 stringifier = results[0].members[1] 70 harness.ok( 71 isinstance(stringifier, WebIDL.IDLMethod), 72 "Stringifier attribute should insert a method", 73 ) 74 harness.ok(stringifier.isStringifier(), "Inserted method should be a stringifier") 75 76 parser = parser.reset() 77 parser.parse( 78 """ 79 interface TestStringifier {}; 80 interface mixin TestStringifierMixin { 81 stringifier attribute DOMString foo; 82 }; 83 TestStringifier includes TestStringifierMixin; 84 """ 85 ) 86 results = parser.finish() 87 harness.ok( 88 isinstance(results[0].members[0], WebIDL.IDLAttribute), 89 "Stringifier attribute should be an attribute", 90 ) 91 stringifier = results[0].members[1] 92 harness.ok( 93 isinstance(stringifier, WebIDL.IDLMethod), 94 "Stringifier attribute should insert a method", 95 ) 96 harness.ok(stringifier.isStringifier(), "Inserted method should be a stringifier") 97 98 parser = parser.reset() 99 parser.parse( 100 """ 101 interface TestStringifier { 102 stringifier attribute USVString foo; 103 }; 104 """ 105 ) 106 results = parser.finish() 107 stringifier = results[0].members[1] 108 harness.ok( 109 stringifier.signatures()[0][0].isUSVString(), 110 "Stringifier attributes should allow USVString", 111 ) 112 113 parser = parser.reset() 114 parser.parse( 115 """ 116 interface TestStringifier { 117 [Throws, NeedsSubjectPrincipal] 118 stringifier attribute USVString foo; 119 }; 120 """ 121 ) 122 results = parser.finish() 123 stringifier = results[0].members[1] 124 harness.ok( 125 stringifier.getExtendedAttribute("Throws"), 126 "Stringifier attributes should support [Throws]", 127 ) 128 harness.ok( 129 stringifier.getExtendedAttribute("NeedsSubjectPrincipal"), 130 "Stringifier attributes should support [NeedsSubjectPrincipal]", 131 ) 132 133 parser = parser.reset() 134 parser.parse( 135 """ 136 interface TestStringifier { 137 stringifier attribute UTF8String foo; 138 }; 139 """ 140 ) 141 results = parser.finish() 142 stringifier = results[0].members[1] 143 harness.ok( 144 stringifier.signatures()[0][0].isUTF8String(), 145 "Stringifier attributes should allow UTF8String", 146 ) 147 148 parser = parser.reset() 149 threw = False 150 try: 151 parser.parse( 152 """ 153 interface TestStringifier { 154 stringifier attribute ByteString foo; 155 }; 156 """ 157 ) 158 results = parser.finish() 159 except WebIDL.WebIDLError: 160 threw = True 161 162 harness.ok(threw, "Should not allow ByteString") 163 164 parser = parser.reset() 165 threw = False 166 try: 167 parser.parse( 168 """ 169 interface TestStringifier { 170 stringifier; 171 stringifier attribute DOMString foo; 172 }; 173 """ 174 ) 175 results = parser.finish() 176 except WebIDL.WebIDLError: 177 threw = True 178 179 harness.ok(threw, "Should not allow a 'stringifier;' and a stringifier attribute") 180 181 parser = parser.reset() 182 threw = False 183 try: 184 parser.parse( 185 """ 186 interface TestStringifier { 187 stringifier attribute DOMString foo; 188 stringifier attribute DOMString bar; 189 }; 190 """ 191 ) 192 results = parser.finish() 193 except WebIDL.WebIDLError: 194 threw = True 195 196 harness.ok(threw, "Should not allow multiple stringifier attributes")