OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # coding=utf-8 | 2 # coding=utf-8 |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 method['is_check_security_for_frame'] and not method['is_read_only'] | 456 method['is_check_security_for_frame'] and not method['is_read_only'] |
457 for method in methods), | 457 for method in methods), |
458 'has_private_script': any(attribute['is_implemented_in_private_script']
for attribute in attributes) or | 458 'has_private_script': any(attribute['is_implemented_in_private_script']
for attribute in attributes) or |
459 any(method['is_implemented_in_private_script'] for method in methods
), | 459 any(method['is_implemented_in_private_script'] for method in methods
), |
460 'iterator_method': iterator_method, | 460 'iterator_method': iterator_method, |
461 'method_configuration_methods': method_configuration_methods, | 461 'method_configuration_methods': method_configuration_methods, |
462 'methods': methods, | 462 'methods': methods, |
463 }) | 463 }) |
464 | 464 |
465 context.update({ | 465 context.update({ |
466 'indexed_property_getter': indexed_property_getter(interface), | 466 'indexed_property_getter': property_getter(interface.indexed_property_ge
tter, ['index']), |
467 'indexed_property_setter': indexed_property_setter(interface), | 467 'indexed_property_setter': property_setter(interface.indexed_property_se
tter, interface), |
468 'indexed_property_deleter': indexed_property_deleter(interface), | 468 'indexed_property_deleter': property_deleter(interface.indexed_property_
deleter), |
469 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, | 469 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, |
470 'named_property_getter': named_property_getter(interface), | 470 'named_property_getter': property_getter(interface.named_property_getter
, ['propertyName']), |
471 'named_property_setter': named_property_setter(interface), | 471 'named_property_setter': property_setter(interface.named_property_setter
, interface), |
472 'named_property_deleter': named_property_deleter(interface), | 472 'named_property_deleter': property_deleter(interface.named_property_dele
ter), |
473 }) | 473 }) |
474 | 474 |
475 return context | 475 return context |
476 | 476 |
477 | 477 |
478 # [DeprecateAs], [Reflect], [RuntimeEnabled] | 478 # [DeprecateAs], [Reflect], [RuntimeEnabled] |
479 def constant_context(constant): | 479 def constant_context(constant): |
480 extended_attributes = constant.extended_attributes | 480 extended_attributes = constant.extended_attributes |
481 return { | 481 return { |
482 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), | 482 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 return min(constructor['number_of_required_arguments'] | 1124 return min(constructor['number_of_required_arguments'] |
1125 for constructor in constructors) | 1125 for constructor in constructors) |
1126 | 1126 |
1127 | 1127 |
1128 ################################################################################ | 1128 ################################################################################ |
1129 # Special operations (methods) | 1129 # Special operations (methods) |
1130 # http://heycam.github.io/webidl/#idl-special-operations | 1130 # http://heycam.github.io/webidl/#idl-special-operations |
1131 ################################################################################ | 1131 ################################################################################ |
1132 | 1132 |
1133 def property_getter(getter, cpp_arguments): | 1133 def property_getter(getter, cpp_arguments): |
| 1134 if not getter: |
| 1135 return None |
| 1136 |
1134 def is_null_expression(idl_type): | 1137 def is_null_expression(idl_type): |
1135 if idl_type.use_output_parameter_for_result: | 1138 if idl_type.use_output_parameter_for_result: |
1136 return 'result.isNull()' | 1139 return 'result.isNull()' |
1137 if idl_type.is_string_type: | 1140 if idl_type.is_string_type: |
1138 return 'result.isNull()' | 1141 return 'result.isNull()' |
1139 if idl_type.is_interface_type: | 1142 if idl_type.is_interface_type: |
1140 return '!result' | 1143 return '!result' |
1141 return '' | 1144 return '' |
1142 | 1145 |
1143 idl_type = getter.idl_type | 1146 idl_type = getter.idl_type |
(...skipping 24 matching lines...) Expand all Loading... |
1168 getter, 'Custom', 'PropertyQuery'), | 1171 getter, 'Custom', 'PropertyQuery'), |
1169 'is_enumerable': 'NotEnumerable' not in extended_attributes, | 1172 'is_enumerable': 'NotEnumerable' not in extended_attributes, |
1170 'is_null_expression': is_null_expression(idl_type), | 1173 'is_null_expression': is_null_expression(idl_type), |
1171 'is_raises_exception': is_raises_exception, | 1174 'is_raises_exception': is_raises_exception, |
1172 'name': cpp_name(getter), | 1175 'name': cpp_name(getter), |
1173 'use_output_parameter_for_result': use_output_parameter_for_result, | 1176 'use_output_parameter_for_result': use_output_parameter_for_result, |
1174 'v8_set_return_value': idl_type.v8_set_return_value('result', extended_a
ttributes=extended_attributes, script_wrappable='impl', release=idl_type.release
), | 1177 'v8_set_return_value': idl_type.v8_set_return_value('result', extended_a
ttributes=extended_attributes, script_wrappable='impl', release=idl_type.release
), |
1175 } | 1178 } |
1176 | 1179 |
1177 | 1180 |
1178 def property_setter(interface, setter): | 1181 def property_setter(setter, interface): |
| 1182 if not setter: |
| 1183 return None |
| 1184 |
1179 idl_type = setter.arguments[1].idl_type | 1185 idl_type = setter.arguments[1].idl_type |
1180 extended_attributes = setter.extended_attributes | 1186 extended_attributes = setter.extended_attributes |
1181 is_raises_exception = 'RaisesException' in extended_attributes | 1187 is_raises_exception = 'RaisesException' in extended_attributes |
1182 restricted_float = ( | 1188 restricted_float = ( |
1183 has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted')
or | 1189 has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted')
or |
1184 has_extended_attribute_value(setter, 'TypeChecking', 'Unrestricted')) | 1190 has_extended_attribute_value(setter, 'TypeChecking', 'Unrestricted')) |
1185 return { | 1191 return { |
1186 'has_exception_state': (is_raises_exception or | 1192 'has_exception_state': (is_raises_exception or |
1187 idl_type.v8_conversion_needs_exception_state), | 1193 idl_type.v8_conversion_needs_exception_state), |
1188 'has_type_checking_interface': | 1194 'has_type_checking_interface': |
1189 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface'
) or | 1195 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface'
) or |
1190 has_extended_attribute_value(setter, 'TypeChecking', 'Interface'))
and | 1196 has_extended_attribute_value(setter, 'TypeChecking', 'Interface'))
and |
1191 idl_type.is_wrapper_type, | 1197 idl_type.is_wrapper_type, |
1192 'idl_type': idl_type.base_type, | 1198 'idl_type': idl_type.base_type, |
1193 'is_custom': 'Custom' in extended_attributes, | 1199 'is_custom': 'Custom' in extended_attributes, |
1194 'is_nullable': idl_type.is_nullable, | 1200 'is_nullable': idl_type.is_nullable, |
1195 'is_raises_exception': is_raises_exception, | 1201 'is_raises_exception': is_raises_exception, |
1196 'name': cpp_name(setter), | 1202 'name': cpp_name(setter), |
1197 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( | 1203 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( |
1198 extended_attributes, 'v8Value', 'propertyValue', restricted_float), | 1204 extended_attributes, 'v8Value', 'propertyValue', restricted_float), |
1199 } | 1205 } |
1200 | 1206 |
1201 | 1207 |
1202 def property_deleter(deleter): | 1208 def property_deleter(deleter): |
| 1209 if not deleter: |
| 1210 return None |
| 1211 |
1203 idl_type = deleter.idl_type | 1212 idl_type = deleter.idl_type |
1204 if str(idl_type) != 'boolean': | 1213 if str(idl_type) != 'boolean': |
1205 raise Exception( | 1214 raise Exception( |
1206 'Only deleters with boolean type are allowed, but type is "%s"' % | 1215 'Only deleters with boolean type are allowed, but type is "%s"' % |
1207 idl_type) | 1216 idl_type) |
1208 extended_attributes = deleter.extended_attributes | 1217 extended_attributes = deleter.extended_attributes |
1209 return { | 1218 return { |
1210 'is_custom': 'Custom' in extended_attributes, | 1219 'is_custom': 'Custom' in extended_attributes, |
1211 'is_raises_exception': 'RaisesException' in extended_attributes, | 1220 'is_raises_exception': 'RaisesException' in extended_attributes, |
1212 'name': cpp_name(deleter), | 1221 'name': cpp_name(deleter), |
1213 } | 1222 } |
1214 | |
1215 | |
1216 ################################################################################ | |
1217 # Indexed properties | |
1218 # http://heycam.github.io/webidl/#idl-indexed-properties | |
1219 ################################################################################ | |
1220 | |
1221 def indexed_property_getter(interface): | |
1222 try: | |
1223 # Find indexed property getter, if present; has form: | |
1224 # getter TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1) | |
1225 getter = next( | |
1226 method | |
1227 for method in interface.operations | |
1228 if ('getter' in method.specials and | |
1229 len(method.arguments) == 1 and | |
1230 str(method.arguments[0].idl_type) == 'unsigned long')) | |
1231 except StopIteration: | |
1232 return None | |
1233 | |
1234 return property_getter(getter, ['index']) | |
1235 | |
1236 | |
1237 def indexed_property_setter(interface): | |
1238 try: | |
1239 # Find indexed property setter, if present; has form: | |
1240 # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG1, ARG_TYPE
ARG2) | |
1241 setter = next( | |
1242 method | |
1243 for method in interface.operations | |
1244 if ('setter' in method.specials and | |
1245 len(method.arguments) == 2 and | |
1246 str(method.arguments[0].idl_type) == 'unsigned long')) | |
1247 except StopIteration: | |
1248 return None | |
1249 | |
1250 return property_setter(interface, setter) | |
1251 | |
1252 | |
1253 def indexed_property_deleter(interface): | |
1254 try: | |
1255 # Find indexed property deleter, if present; has form: | |
1256 # deleter TYPE [OPTIONAL_IDENTIFIER](unsigned long ARG) | |
1257 deleter = next( | |
1258 method | |
1259 for method in interface.operations | |
1260 if ('deleter' in method.specials and | |
1261 len(method.arguments) == 1 and | |
1262 str(method.arguments[0].idl_type) == 'unsigned long')) | |
1263 except StopIteration: | |
1264 return None | |
1265 | |
1266 return property_deleter(deleter) | |
1267 | |
1268 | |
1269 ################################################################################ | |
1270 # Named properties | |
1271 # http://heycam.github.io/webidl/#idl-named-properties | |
1272 ################################################################################ | |
1273 | |
1274 def named_property_getter(interface): | |
1275 try: | |
1276 # Find named property getter, if present; has form: | |
1277 # getter TYPE [OPTIONAL_IDENTIFIER](DOMString ARG1) | |
1278 getter = next( | |
1279 method | |
1280 for method in interface.operations | |
1281 if ('getter' in method.specials and | |
1282 len(method.arguments) == 1 and | |
1283 str(method.arguments[0].idl_type) == 'DOMString')) | |
1284 except StopIteration: | |
1285 return None | |
1286 | |
1287 getter.name = getter.name or 'anonymousNamedGetter' | |
1288 return property_getter(getter, ['propertyName']) | |
1289 | |
1290 | |
1291 def named_property_setter(interface): | |
1292 try: | |
1293 # Find named property setter, if present; has form: | |
1294 # setter RETURN_TYPE [OPTIONAL_IDENTIFIER](DOMString ARG1, ARG_TYPE ARG2
) | |
1295 setter = next( | |
1296 method | |
1297 for method in interface.operations | |
1298 if ('setter' in method.specials and | |
1299 len(method.arguments) == 2 and | |
1300 str(method.arguments[0].idl_type) == 'DOMString')) | |
1301 except StopIteration: | |
1302 return None | |
1303 | |
1304 return property_setter(interface, setter) | |
1305 | |
1306 | |
1307 def named_property_deleter(interface): | |
1308 try: | |
1309 # Find named property deleter, if present; has form: | |
1310 # deleter TYPE [OPTIONAL_IDENTIFIER](DOMString ARG) | |
1311 deleter = next( | |
1312 method | |
1313 for method in interface.operations | |
1314 if ('deleter' in method.specials and | |
1315 len(method.arguments) == 1 and | |
1316 str(method.arguments[0].idl_type) == 'DOMString')) | |
1317 except StopIteration: | |
1318 return None | |
1319 | |
1320 return property_deleter(deleter) | |
OLD | NEW |