| OLD | NEW |
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 import idl_types | 39 import idl_types |
| 40 from v8_globals import includes | 40 from v8_globals import includes |
| 41 import v8_types | 41 import v8_types |
| 42 | 42 |
| 43 ACRONYMS = [ | 43 ACRONYMS = [ |
| 44 'CSSOM', # must come *before* CSS to match full acronym | 44 'CSSOM', # must come *before* CSS to match full acronym |
| 45 'CSS', | 45 'CSS', |
| 46 'HTML', | 46 'HTML', |
| 47 'IME', | 47 'IME', |
| 48 'JS', | 48 'JS', |
| 49 'SVG', | |
| 50 'URL', | 49 'URL', |
| 51 'WOFF', | 50 'WOFF', |
| 52 'XML', | 51 'XML', |
| 53 'XSLT', | |
| 54 ] | 52 ] |
| 55 | 53 |
| 56 | 54 |
| 57 ################################################################################ | 55 ################################################################################ |
| 58 # Extended attribute parsing | 56 # Extended attribute parsing |
| 59 ################################################################################ | 57 ################################################################################ |
| 60 | 58 |
| 61 def extended_attribute_value_contains(extended_attribute_value, key): | 59 def extended_attribute_value_contains(extended_attribute_value, key): |
| 62 return (extended_attribute_value == key or | 60 return (extended_attribute_value == key or |
| 63 (isinstance(extended_attribute_value, list) and | 61 (isinstance(extended_attribute_value, list) and |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 def enum_validation_expression(idl_type): | 119 def enum_validation_expression(idl_type): |
| 122 # FIXME: Add IdlEnumType, move property to derived type, and remove this che
ck | 120 # FIXME: Add IdlEnumType, move property to derived type, and remove this che
ck |
| 123 if not idl_type.is_enum: | 121 if not idl_type.is_enum: |
| 124 return None | 122 return None |
| 125 return ' || '.join(['string == "%s"' % enum_value | 123 return ' || '.join(['string == "%s"' % enum_value |
| 126 for enum_value in idl_type.enum_values]) | 124 for enum_value in idl_type.enum_values]) |
| 127 IdlTypeBase.enum_validation_expression = property(enum_validation_expression) | 125 IdlTypeBase.enum_validation_expression = property(enum_validation_expression) |
| 128 | 126 |
| 129 | 127 |
| 130 def scoped_name(interface, definition, base_name): | 128 def scoped_name(interface, definition, base_name): |
| 131 if 'ImplementedInPrivateScript' in definition.extended_attributes: | |
| 132 return '%s::PrivateScript::%s' % (v8_class_name(interface), base_name) | |
| 133 # partial interfaces are implemented as separate classes, with their members | 129 # partial interfaces are implemented as separate classes, with their members |
| 134 # implemented as static member functions | 130 # implemented as static member functions |
| 135 partial_interface_implemented_as = definition.extended_attributes.get('Parti
alInterfaceImplementedAs') | 131 partial_interface_implemented_as = definition.extended_attributes.get('Parti
alInterfaceImplementedAs') |
| 136 if partial_interface_implemented_as: | 132 if partial_interface_implemented_as: |
| 137 return '%s::%s' % (partial_interface_implemented_as, base_name) | 133 return '%s::%s' % (partial_interface_implemented_as, base_name) |
| 138 if (definition.is_static or | 134 if (definition.is_static or |
| 139 definition.name in ('Constructor', 'NamedConstructor')): | 135 definition.name in ('Constructor', 'NamedConstructor')): |
| 140 return '%s::%s' % (cpp_name(interface), base_name) | 136 return '%s::%s' % (cpp_name(interface), base_name) |
| 141 return 'impl->%s' % base_name | 137 return 'impl->%s' % base_name |
| 142 | 138 |
| 143 | 139 |
| 144 def v8_class_name(interface): | |
| 145 return v8_types.v8_type(interface.name) | |
| 146 | |
| 147 | |
| 148 ################################################################################ | 140 ################################################################################ |
| 149 # Specific extended attributes | 141 # Specific extended attributes |
| 150 ################################################################################ | 142 ################################################################################ |
| 151 | 143 |
| 152 # [ActivityLogging] | |
| 153 def activity_logging_world_list(member, access_type=''): | |
| 154 """Returns a set of world suffixes for which a definition member has activit
y logging, for specified access type. | |
| 155 | |
| 156 access_type can be 'Getter' or 'Setter' if only checking getting or setting. | |
| 157 """ | |
| 158 extended_attributes = member.extended_attributes | |
| 159 if 'LogActivity' not in extended_attributes: | |
| 160 return set() | |
| 161 log_activity = extended_attributes['LogActivity'] | |
| 162 if log_activity and not log_activity.startswith(access_type): | |
| 163 return set() | |
| 164 | |
| 165 includes.add('bindings/core/v8/V8DOMActivityLogger.h') | |
| 166 if 'LogAllWorlds' in extended_attributes: | |
| 167 return set(['', 'ForMainWorld']) | |
| 168 return set(['']) # At minimum, include isolated worlds. | |
| 169 | |
| 170 | |
| 171 # [ActivityLogging] | |
| 172 def activity_logging_world_check(member): | |
| 173 """Returns if an isolated world check is required when generating activity | |
| 174 logging code. | |
| 175 | |
| 176 The check is required when there is no per-world binding code and logging is | |
| 177 required only for isolated world. | |
| 178 """ | |
| 179 extended_attributes = member.extended_attributes | |
| 180 if 'LogActivity' not in extended_attributes: | |
| 181 return False | |
| 182 if ('PerWorldBindings' not in extended_attributes and | |
| 183 'LogAllWorlds' not in extended_attributes): | |
| 184 return True | |
| 185 return False | |
| 186 | |
| 187 | 144 |
| 188 # [CallWith] | 145 # [CallWith] |
| 189 CALL_WITH_ARGUMENTS = { | 146 CALL_WITH_ARGUMENTS = { |
| 190 'ScriptState': 'scriptState', | 147 'ScriptState': 'scriptState', |
| 191 'ExecutionContext': 'executionContext', | 148 'ExecutionContext': 'executionContext', |
| 192 'ScriptArguments': 'scriptArguments.release()', | 149 'ScriptArguments': 'scriptArguments.release()', |
| 193 'ActiveWindow': 'callingDOMWindow(info.GetIsolate())', | 150 'ActiveWindow': 'callingDOMWindow(info.GetIsolate())', |
| 194 'FirstWindow': 'enteredDOMWindow(info.GetIsolate())', | 151 'FirstWindow': 'enteredDOMWindow(info.GetIsolate())', |
| 195 'Document': 'document', | 152 'Document': 'document', |
| 196 } | 153 } |
| 197 # List because key order matters, as we want arguments in deterministic order | 154 # List because key order matters, as we want arguments in deterministic order |
| 198 CALL_WITH_VALUES = [ | 155 CALL_WITH_VALUES = [ |
| 199 'ScriptState', | 156 'ScriptState', |
| 200 'ExecutionContext', | 157 'ExecutionContext', |
| 201 'ScriptArguments', | 158 'ScriptArguments', |
| 202 'ActiveWindow', | 159 'ActiveWindow', |
| 203 'FirstWindow', | 160 'FirstWindow', |
| 204 'Document', | 161 'Document', |
| 205 ] | 162 ] |
| 206 | 163 |
| 207 | 164 |
| 208 def call_with_arguments(call_with_values): | 165 def call_with_arguments(call_with_values): |
| 209 if not call_with_values: | 166 if not call_with_values: |
| 210 return [] | 167 return [] |
| 211 return [CALL_WITH_ARGUMENTS[value] | 168 return [CALL_WITH_ARGUMENTS[value] |
| 212 for value in CALL_WITH_VALUES | 169 for value in CALL_WITH_VALUES |
| 213 if extended_attribute_value_contains(call_with_values, value)] | 170 if extended_attribute_value_contains(call_with_values, value)] |
| 214 | 171 |
| 215 | 172 |
| 216 # [Conditional] | |
| 217 DELIMITER_TO_OPERATOR = { | |
| 218 '|': '||', | |
| 219 ',': '&&', | |
| 220 } | |
| 221 | |
| 222 | |
| 223 def conditional_string(definition_or_member): | |
| 224 extended_attributes = definition_or_member.extended_attributes | |
| 225 if 'Conditional' not in extended_attributes: | |
| 226 return None | |
| 227 return 'ENABLE(%s)' % extended_attributes['Conditional'] | |
| 228 | |
| 229 | |
| 230 # [DeprecateAs] | |
| 231 def deprecate_as(member): | |
| 232 extended_attributes = member.extended_attributes | |
| 233 if 'DeprecateAs' not in extended_attributes: | |
| 234 return None | |
| 235 return extended_attributes['DeprecateAs'] | |
| 236 | |
| 237 | |
| 238 # [Exposed] | 173 # [Exposed] |
| 239 EXPOSED_EXECUTION_CONTEXT_METHOD = { | 174 EXPOSED_EXECUTION_CONTEXT_METHOD = { |
| 240 'Window': 'isDocument', | 175 'Window': 'isDocument', |
| 241 } | 176 } |
| 242 | 177 |
| 243 | 178 |
| 244 def exposed(definition_or_member, interface): | 179 def exposed(definition_or_member, interface): |
| 245 exposure_set = extended_attribute_value_as_list(definition_or_member, 'Expos
ed') | 180 exposure_set = extended_attribute_value_as_list(definition_or_member, 'Expos
ed') |
| 246 if not exposure_set: | 181 if not exposure_set: |
| 247 return None | 182 return None |
| (...skipping 19 matching lines...) Expand all Loading... |
| 267 exposure_set = extended_attribute_value_as_list(interface, 'Exposed') | 202 exposure_set = extended_attribute_value_as_list(interface, 'Exposed') |
| 268 return sorted(set(exposure_set)) | 203 return sorted(set(exposure_set)) |
| 269 | 204 |
| 270 | 205 |
| 271 # [ImplementedAs] | 206 # [ImplementedAs] |
| 272 def cpp_name(definition_or_member): | 207 def cpp_name(definition_or_member): |
| 273 extended_attributes = definition_or_member.extended_attributes | 208 extended_attributes = definition_or_member.extended_attributes |
| 274 if 'ImplementedAs' not in extended_attributes: | 209 if 'ImplementedAs' not in extended_attributes: |
| 275 return definition_or_member.name | 210 return definition_or_member.name |
| 276 return extended_attributes['ImplementedAs'] | 211 return extended_attributes['ImplementedAs'] |
| 277 | |
| 278 | |
| 279 # [MeasureAs] | |
| 280 def measure_as(definition_or_member): | |
| 281 extended_attributes = definition_or_member.extended_attributes | |
| 282 if 'MeasureAs' not in extended_attributes: | |
| 283 return None | |
| 284 return extended_attributes['MeasureAs'] | |
| 285 | |
| 286 | |
| 287 # [RuntimeEnabled] | |
| 288 def runtime_enabled_function_name(definition_or_member): | |
| 289 """Returns the name of the RuntimeEnabledFeatures function. | |
| 290 | |
| 291 The returned function checks if a method/attribute is enabled. | |
| 292 Given extended attribute RuntimeEnabled=FeatureName, return: | |
| 293 RuntimeEnabledFeatures::{featureName}Enabled | |
| 294 """ | |
| 295 extended_attributes = definition_or_member.extended_attributes | |
| 296 if 'RuntimeEnabled' not in extended_attributes: | |
| 297 return None | |
| 298 feature_name = extended_attributes['RuntimeEnabled'] | |
| 299 return 'RuntimeEnabledFeatures::%sEnabled' % uncapitalize(feature_name) | |
| OLD | NEW |