| 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 17 matching lines...) Expand all Loading... |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 # pylint: disable=relative-import | 30 # pylint: disable=relative-import |
| 31 | 31 |
| 32 """Generate template values for an interface. | 32 """Generate template values for an interface. |
| 33 | 33 |
| 34 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 34 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
| 35 """ | 35 """ |
| 36 from operator import or_ | 36 from operator import or_ |
| 37 | 37 |
| 38 from idl_definitions import IdlOperation, IdlArgument | 38 from idl_definitions import IdlAttribute, IdlOperation, IdlArgument |
| 39 from idl_types import IdlType, inherits_interface | 39 from idl_types import IdlType, inherits_interface |
| 40 from overload_set_algorithm import effective_overload_set_by_length | 40 from overload_set_algorithm import effective_overload_set_by_length |
| 41 from overload_set_algorithm import method_overloads_by_name | 41 from overload_set_algorithm import method_overloads_by_name |
| 42 | 42 |
| 43 import v8_attributes | 43 import v8_attributes |
| 44 from v8_globals import includes | 44 from v8_globals import includes |
| 45 import v8_methods | 45 import v8_methods |
| 46 import v8_types | 46 import v8_types |
| 47 import v8_utilities | 47 import v8_utilities |
| 48 from v8_utilities import (cpp_name_or_partial, cpp_name, has_extended_attribute_
value, | 48 from v8_utilities import (cpp_name_or_partial, cpp_name, has_extended_attribute_
value, |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 'unscopables': sorted(unscopables), | 343 'unscopables': sorted(unscopables), |
| 344 }) | 344 }) |
| 345 | 345 |
| 346 # Constants | 346 # Constants |
| 347 context.update({ | 347 context.update({ |
| 348 'constants': [constant_context(constant, interface) for constant in inte
rface.constants], | 348 'constants': [constant_context(constant, interface) for constant in inte
rface.constants], |
| 349 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, | 349 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, |
| 350 }) | 350 }) |
| 351 | 351 |
| 352 # Attributes | 352 # Attributes |
| 353 attributes = [v8_attributes.attribute_context(interface, attribute, interfac
es) | 353 attributes = attributes_context(interface, interfaces) |
| 354 for attribute in interface.attributes] | |
| 355 | |
| 356 has_conditional_attributes = any(attribute['exposed_test'] for attribute in
attributes) | |
| 357 if has_conditional_attributes and interface.is_partial: | |
| 358 raise Exception('Conditional attributes between partial interfaces in mo
dules and the original interfaces(%s) in core are not allowed.' % interface.name
) | |
| 359 | |
| 360 context.update({ | 354 context.update({ |
| 361 'attributes': attributes, | 355 'attributes': attributes, |
| 362 # Elements in attributes are broken in following members. | 356 # Elements in attributes are broken in following members. |
| 363 'accessors': v8_attributes.filter_accessors(attributes), | 357 'accessors': v8_attributes.filter_accessors(attributes), |
| 364 'data_attributes': v8_attributes.filter_data_attributes(attributes), | 358 'data_attributes': v8_attributes.filter_data_attributes(attributes), |
| 365 'lazy_data_attributes': v8_attributes.filter_lazy_data_attributes(attrib
utes), | 359 'lazy_data_attributes': v8_attributes.filter_lazy_data_attributes(attrib
utes), |
| 366 'origin_trial_attributes': v8_attributes.filter_origin_trial_enabled(att
ributes), | 360 'origin_trial_attributes': v8_attributes.filter_origin_trial_enabled(att
ributes), |
| 367 'runtime_enabled_attributes': v8_attributes.filter_runtime_enabled(attri
butes), | 361 'runtime_enabled_attributes': v8_attributes.filter_runtime_enabled(attri
butes), |
| 368 }) | 362 }) |
| 369 | 363 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 context.update({ | 449 context.update({ |
| 456 'has_cross_origin_named_getter': has_cross_origin_named_getter, | 450 'has_cross_origin_named_getter': has_cross_origin_named_getter, |
| 457 'has_cross_origin_named_setter': has_cross_origin_named_setter, | 451 'has_cross_origin_named_setter': has_cross_origin_named_setter, |
| 458 'has_cross_origin_named_enumerator': has_cross_origin_named_enumerator, | 452 'has_cross_origin_named_enumerator': has_cross_origin_named_enumerator, |
| 459 'has_cross_origin_indexed_getter': has_cross_origin_indexed_getter, | 453 'has_cross_origin_indexed_getter': has_cross_origin_indexed_getter, |
| 460 }) | 454 }) |
| 461 | 455 |
| 462 return context | 456 return context |
| 463 | 457 |
| 464 | 458 |
| 459 def attributes_context(interface, interfaces): |
| 460 """Creates a list of Jinja template contexts for attributes of an interface. |
| 461 |
| 462 Args: |
| 463 interface: An interface to create contexts for |
| 464 interfaces: A dict which maps an interface name to the definition |
| 465 which can be referred if needed |
| 466 |
| 467 Returns: |
| 468 A list of attribute contexts |
| 469 """ |
| 470 |
| 471 attributes = [v8_attributes.attribute_context(interface, attribute, interfac
es) |
| 472 for attribute in interface.attributes] |
| 473 |
| 474 has_conditional_attributes = any(attribute['exposed_test'] for attribute in
attributes) |
| 475 if has_conditional_attributes and interface.is_partial: |
| 476 raise Exception( |
| 477 'Conditional attributes between partial interfaces in modules ' |
| 478 'and the original interfaces(%s) in core are not allowed.' |
| 479 % interface.name) |
| 480 |
| 481 # See also comment in methods_context. |
| 482 if not interface.is_partial and (interface.maplike or interface.setlike): |
| 483 if any(attribute['name'] == 'size' for attribute in attributes): |
| 484 raise ValueError( |
| 485 'An interface cannot define an attribute called "size"; it is ' |
| 486 'implied by maplike/setlike in the IDL.') |
| 487 size_attribute = IdlAttribute() |
| 488 size_attribute.name = 'size' |
| 489 size_attribute.idl_type = IdlType('unsigned long') |
| 490 size_attribute.is_read_only = True |
| 491 size_attribute.extended_attributes['NotEnumerable'] = None |
| 492 attributes.append(v8_attributes.attribute_context( |
| 493 interface, size_attribute, interfaces)) |
| 494 |
| 495 return attributes |
| 496 |
| 497 |
| 465 def methods_context(interface): | 498 def methods_context(interface): |
| 466 """Creates a list of Jinja template contexts for methods of an interface. | 499 """Creates a list of Jinja template contexts for methods of an interface. |
| 467 | 500 |
| 468 Args: | 501 Args: |
| 469 interface: An interface to create contexts for | 502 interface: An interface to create contexts for |
| 470 | 503 |
| 471 Returns: | 504 Returns: |
| 472 A list of method contexts, and an iterator context if available or None | 505 A list of method contexts, and an iterator context if available or None |
| 473 """ | 506 """ |
| 474 | 507 |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 extended_attributes = deleter.extended_attributes | 1409 extended_attributes = deleter.extended_attributes |
| 1377 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') | 1410 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') |
| 1378 is_ce_reactions = 'CEReactions' in extended_attributes | 1411 is_ce_reactions = 'CEReactions' in extended_attributes |
| 1379 return { | 1412 return { |
| 1380 'is_call_with_script_state': is_call_with_script_state, | 1413 'is_call_with_script_state': is_call_with_script_state, |
| 1381 'is_ce_reactions': is_ce_reactions, | 1414 'is_ce_reactions': is_ce_reactions, |
| 1382 'is_custom': 'Custom' in extended_attributes, | 1415 'is_custom': 'Custom' in extended_attributes, |
| 1383 'is_raises_exception': 'RaisesException' in extended_attributes, | 1416 'is_raises_exception': 'RaisesException' in extended_attributes, |
| 1384 'name': cpp_name(deleter), | 1417 'name': cpp_name(deleter), |
| 1385 } | 1418 } |
| OLD | NEW |