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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 | 101 |
102 def origin_trial_features(interface, constants, attributes, methods): | 102 def origin_trial_features(interface, constants, attributes, methods): |
103 """ Returns a list of the origin trial features used in this interface. | 103 """ Returns a list of the origin trial features used in this interface. |
104 | 104 |
105 Each element is a dictionary with keys 'name' and 'needs_instance'. | 105 Each element is a dictionary with keys 'name' and 'needs_instance'. |
106 'needs_instance' is true if any member associated with the interface needs | 106 'needs_instance' is true if any member associated with the interface needs |
107 to be installed on every instance of the interface. This list is the union | 107 to be installed on every instance of the interface. This list is the union |
108 of the sets of features used for constants, attributes and methods. | 108 of the sets of features used for constants, attributes and methods. |
109 """ | 109 """ |
| 110 KEY = 'origin_trial_feature_name' # pylint: disable=invalid-name |
| 111 |
| 112 def member_filter(members): |
| 113 return sorted([member for member in members if member.get(KEY) and not m
ember.get('exposed_test')]) |
| 114 |
| 115 def member_filter_by_name(members, name): |
| 116 return [member for member in members if member[KEY] == name] |
110 | 117 |
111 # Collect all members visible on this interface with a defined origin trial | 118 # Collect all members visible on this interface with a defined origin trial |
112 origin_trial_members = ( | 119 origin_trial_constants = member_filter(constants) |
113 [constant for constant in constants if constant['origin_trial_feature_na
me']] + | 120 origin_trial_attributes = member_filter(attributes) |
114 [attribute for attribute in attributes if attribute['origin_trial_featur
e_name']] + | 121 origin_trial_methods = member_filter([method for method in methods |
115 [method for method in methods if ( | 122 if v8_methods.method_is_visible(method
, interface.is_partial) and |
116 v8_methods.method_is_visible(method, interface.is_partial) and | 123 not v8_methods.conditionally_exposed(m
ethod) and |
117 method['origin_trial_feature_name'])] | 124 not v8_methods.custom_registration(met
hod)]) |
118 ) | 125 |
119 # Group members by origin_trial_feature_name | 126 feature_names = set([member[KEY] for member in origin_trial_constants + orig
in_trial_attributes + origin_trial_methods]) |
120 members_by_name = itertools.groupby(sorted(origin_trial_members, | 127 |
121 key=itemgetter('origin_trial_feat
ure_name')), | |
122 itemgetter('origin_trial_feature_name')) | |
123 # Construct the list of dictionaries. 'needs_instance' will be true if any | 128 # Construct the list of dictionaries. 'needs_instance' will be true if any |
124 # member for the feature has 'on_instance' defined as true. | 129 # member for the feature has 'on_instance' defined as true. |
125 features = [{'name': name, | 130 features = [{'name': name, |
126 'needs_instance': reduce(or_, (member.get('on_instance', False) | 131 'constants': member_filter_by_name(origin_trial_constants, name
), |
127 for member in members))} | 132 'attributes': member_filter_by_name(origin_trial_attributes, na
me), |
128 for name, members in members_by_name] | 133 'methods': member_filter_by_name(origin_trial_methods, name)} |
| 134 for name in feature_names] |
| 135 for feature in features: |
| 136 members = feature['constants'] + feature['attributes'] + feature['method
s'] |
| 137 feature['needs_instance'] = reduce(or_, (member.get('on_instance', False
) for member in members)) |
| 138 |
129 if features: | 139 if features: |
130 includes.add('bindings/core/v8/ScriptState.h') | 140 includes.add('bindings/core/v8/ScriptState.h') |
131 includes.add('core/origin_trials/OriginTrials.h') | 141 includes.add('core/origin_trials/OriginTrials.h') |
132 return sorted(features) | 142 return sorted(features) |
133 | 143 |
134 | 144 |
135 def interface_context(interface, interfaces): | 145 def interface_context(interface, interfaces): |
136 """Creates a Jinja template context for an interface. | 146 """Creates a Jinja template context for an interface. |
137 | 147 |
138 Args: | 148 Args: |
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 extended_attributes = deleter.extended_attributes | 1497 extended_attributes = deleter.extended_attributes |
1488 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') | 1498 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') |
1489 is_ce_reactions = 'CEReactions' in extended_attributes | 1499 is_ce_reactions = 'CEReactions' in extended_attributes |
1490 return { | 1500 return { |
1491 'is_call_with_script_state': is_call_with_script_state, | 1501 'is_call_with_script_state': is_call_with_script_state, |
1492 'is_ce_reactions': is_ce_reactions, | 1502 'is_ce_reactions': is_ce_reactions, |
1493 'is_custom': 'Custom' in extended_attributes, | 1503 'is_custom': 'Custom' in extended_attributes, |
1494 'is_raises_exception': 'RaisesException' in extended_attributes, | 1504 'is_raises_exception': 'RaisesException' in extended_attributes, |
1495 'name': cpp_name(deleter), | 1505 'name': cpp_name(deleter), |
1496 } | 1506 } |
OLD | NEW |