Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 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 | 36 |
| 37 from collections import defaultdict | 37 from collections import defaultdict |
| 38 import itertools | 38 import itertools |
| 39 from operator import itemgetter | 39 from operator import itemgetter, or_ |
| 40 | 40 |
| 41 from idl_definitions import IdlOperation, IdlArgument | 41 from idl_definitions import IdlOperation, IdlArgument |
| 42 from idl_types import IdlType, inherits_interface | 42 from idl_types import IdlType, inherits_interface |
| 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, |
| 49 runtime_enabled_function_name, is_legacy_interface_typ e_checking) | 49 runtime_enabled_function_name, is_legacy_interface_typ e_checking) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 constant['origin_trial_feature_name']] | 91 constant['origin_trial_feature_name']] |
| 92 | 92 |
| 93 | 93 |
| 94 def constant_filters(): | 94 def constant_filters(): |
| 95 return {'has_constant_configuration': filter_has_constant_configuration, | 95 return {'has_constant_configuration': filter_has_constant_configuration, |
| 96 'has_special_getter': filter_has_special_getter, | 96 'has_special_getter': filter_has_special_getter, |
| 97 'runtime_enabled_constants': filter_runtime_enabled, | 97 'runtime_enabled_constants': filter_runtime_enabled, |
| 98 'origin_trial_enabled_constants': filter_origin_trial_enabled} | 98 'origin_trial_enabled_constants': filter_origin_trial_enabled} |
| 99 | 99 |
| 100 | 100 |
| 101 def origin_trial_feature_names(interface, constants, attributes, methods): | 101 def origin_trial_features(interface, constants, attributes, methods): |
| 102 """ Returns a list of the names of each origin trial feature used in this in terface. | 102 """ Returns a list of the origin trial features used in this interface. |
| 103 | 103 |
| 104 This list is the union of the sets of names used for constants, attributes a nd methods. | 104 Each element is a dictionary with keys 'name' and 'needs_instance'. |
| 105 'needs_instance' is true if any member associated with the interface needs | |
| 106 to be installed on every instance of the interface. This list is the union | |
| 107 of the sets of features used for constants, attributes and methods. | |
| 105 """ | 108 """ |
| 106 | 109 |
| 107 feature_names = set( | 110 # Collect all members visible on this interface with a defined origin trial |
| 108 [constant['origin_trial_feature_name'] for constant in constants if cons tant['origin_trial_feature_name']] + | 111 origin_trial_members = ( |
| 109 [attribute['origin_trial_feature_name'] for attribute in attributes if a ttribute['origin_trial_feature_name']] + | 112 [constant for constant in constants if constant['origin_trial_feature_na me']] + |
| 110 [method['origin_trial_feature_name'] for method in methods if ( | 113 [attribute for attribute in attributes if attribute['origin_trial_featur e_name']] + |
| 114 [method for method in methods if ( | |
| 111 v8_methods.method_is_visible(method, interface.is_partial) and | 115 v8_methods.method_is_visible(method, interface.is_partial) and |
| 112 method['origin_trial_feature_name'])] | 116 method['origin_trial_feature_name'])] |
| 113 ) | 117 ) |
| 114 if feature_names: | 118 # Group members by origin_trial_feature_name |
| 119 members_by_name = itertools.groupby(origin_trial_members, itemgetter('origin _trial_feature_name')) | |
|
Marijn Kruisselbrink
2016/07/08 19:44:09
itertools.groupby requires the passed in iterable
| |
| 120 # Construct the list of dictionaries. 'needs_instance' will be true if any | |
| 121 # member for the feature has 'on_instance' defined as true. | |
| 122 features = [{'name': name, | |
| 123 'needs_instance': reduce(or_, (member.get('on_instance', False) | |
| 124 for member in members))} | |
| 125 for name, members in members_by_name] | |
| 126 if features: | |
| 115 includes.add('bindings/core/v8/ScriptState.h') | 127 includes.add('bindings/core/v8/ScriptState.h') |
| 116 includes.add('core/origin_trials/OriginTrials.h') | 128 includes.add('core/origin_trials/OriginTrials.h') |
| 117 return sorted(feature_names) | 129 return sorted(features) |
| 118 | 130 |
| 119 | 131 |
| 120 def interface_context(interface): | 132 def interface_context(interface): |
| 121 includes.clear() | 133 includes.clear() |
| 122 includes.update(INTERFACE_CPP_INCLUDES) | 134 includes.update(INTERFACE_CPP_INCLUDES) |
| 123 header_includes = set(INTERFACE_H_INCLUDES) | 135 header_includes = set(INTERFACE_H_INCLUDES) |
| 124 | 136 |
| 125 if interface.is_partial: | 137 if interface.is_partial: |
| 126 # A partial interface definition cannot specify that the interface | 138 # A partial interface definition cannot specify that the interface |
| 127 # inherits from another interface. Inheritance must be specified on | 139 # inherits from another interface. Inheritance must be specified on |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 'named_property_getter': property_getter(interface.named_property_getter , ['propertyName']), | 575 'named_property_getter': property_getter(interface.named_property_getter , ['propertyName']), |
| 564 'named_property_setter': property_setter(interface.named_property_setter , interface), | 576 'named_property_setter': property_setter(interface.named_property_setter , interface), |
| 565 'named_property_deleter': property_deleter(interface.named_property_dele ter), | 577 'named_property_deleter': property_deleter(interface.named_property_dele ter), |
| 566 }) | 578 }) |
| 567 context.update({ | 579 context.update({ |
| 568 'has_named_properties_object': is_global and context['named_property_get ter'], | 580 'has_named_properties_object': is_global and context['named_property_get ter'], |
| 569 }) | 581 }) |
| 570 | 582 |
| 571 # Origin Trials | 583 # Origin Trials |
| 572 context.update({ | 584 context.update({ |
| 573 'origin_trial_feature_names': origin_trial_feature_names(interface, cont ext['constants'], context['attributes'], context['methods']), | 585 'origin_trial_features': origin_trial_features(interface, context['const ants'], context['attributes'], context['methods']), |
| 574 }) | 586 }) |
| 575 return context | 587 return context |
| 576 | 588 |
| 577 | 589 |
| 578 # [DeprecateAs], [OriginTrialEnabled], [Reflect], [RuntimeEnabled] | 590 # [DeprecateAs], [OriginTrialEnabled], [Reflect], [RuntimeEnabled] |
| 579 def constant_context(constant, interface): | 591 def constant_context(constant, interface): |
| 580 extended_attributes = constant.extended_attributes | 592 extended_attributes = constant.extended_attributes |
| 581 | 593 |
| 582 return { | 594 return { |
| 583 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), | 595 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1372 extended_attributes = deleter.extended_attributes | 1384 extended_attributes = deleter.extended_attributes |
| 1373 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState') | 1385 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState') |
| 1374 is_ce_reactions = 'CEReactions' in extended_attributes | 1386 is_ce_reactions = 'CEReactions' in extended_attributes |
| 1375 return { | 1387 return { |
| 1376 'is_call_with_script_state': is_call_with_script_state, | 1388 'is_call_with_script_state': is_call_with_script_state, |
| 1377 'is_ce_reactions': is_ce_reactions, | 1389 'is_ce_reactions': is_ce_reactions, |
| 1378 'is_custom': 'Custom' in extended_attributes, | 1390 'is_custom': 'Custom' in extended_attributes, |
| 1379 'is_raises_exception': 'RaisesException' in extended_attributes, | 1391 'is_raises_exception': 'RaisesException' in extended_attributes, |
| 1380 'name': cpp_name(deleter), | 1392 'name': cpp_name(deleter), |
| 1381 } | 1393 } |
| OLD | NEW |