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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 return any(extended_attribute in definition_or_member.extended_attributes | 67 return any(extended_attribute in definition_or_member.extended_attributes |
68 for extended_attribute in extended_attribute_list) | 68 for extended_attribute in extended_attribute_list) |
69 | 69 |
70 | 70 |
71 def has_extended_attribute_value(definition_or_member, name, value): | 71 def has_extended_attribute_value(definition_or_member, name, value): |
72 extended_attributes = definition_or_member.extended_attributes | 72 extended_attributes = definition_or_member.extended_attributes |
73 return (name in extended_attributes and | 73 return (name in extended_attributes and |
74 extended_attribute_value_contains(extended_attributes[name], value)) | 74 extended_attribute_value_contains(extended_attributes[name], value)) |
75 | 75 |
76 | 76 |
| 77 def sorted_extended_attribute_set(definition_or_member, name): |
| 78 extended_attributes = definition_or_member.extended_attributes |
| 79 if name not in extended_attributes: |
| 80 return [] |
| 81 |
| 82 attribute_values = re.split('[|&]', extended_attributes[name]) |
| 83 return sorted(attribute_values) |
| 84 |
| 85 |
77 ################################################################################ | 86 ################################################################################ |
78 # String handling | 87 # String handling |
79 ################################################################################ | 88 ################################################################################ |
80 | 89 |
81 def capitalize(name): | 90 def capitalize(name): |
82 """Capitalize first letter or initial acronym (used in setter names).""" | 91 """Capitalize first letter or initial acronym (used in setter names).""" |
83 for acronym in ACRONYMS: | 92 for acronym in ACRONYMS: |
84 if name.startswith(acronym.lower()): | 93 if name.startswith(acronym.lower()): |
85 return name.replace(acronym.lower(), acronym) | 94 return name.replace(acronym.lower(), acronym) |
86 return name[0].upper() + name[1:] | 95 return name[0].upper() + name[1:] |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 227 |
219 # [DeprecateAs] | 228 # [DeprecateAs] |
220 def deprecate_as(member): | 229 def deprecate_as(member): |
221 extended_attributes = member.extended_attributes | 230 extended_attributes = member.extended_attributes |
222 if 'DeprecateAs' not in extended_attributes: | 231 if 'DeprecateAs' not in extended_attributes: |
223 return None | 232 return None |
224 includes.add('core/frame/UseCounter.h') | 233 includes.add('core/frame/UseCounter.h') |
225 return extended_attributes['DeprecateAs'] | 234 return extended_attributes['DeprecateAs'] |
226 | 235 |
227 | 236 |
| 237 # [Exposed] |
| 238 EXPOSED_EXECUTION_CONTEXT_METHOD = { |
| 239 'DedicatedWorker': 'isDedicatedWorkerGlobalScope', |
| 240 'ServiceWorker': 'isServiceWorkerGlobalScope', |
| 241 'SharedWorker': 'isSharedWorkerGlobalScope', |
| 242 'Window': 'isDocument', |
| 243 'Worker': 'isWorkerGlobalScope', |
| 244 } |
| 245 |
| 246 |
| 247 def exposed(definition_or_member, interface): |
| 248 exposure_set = sorted_extended_attribute_set(definition_or_member, 'Exposed'
) |
| 249 if not exposure_set: |
| 250 return None |
| 251 |
| 252 interface_exposure_set = expanded_exposure_set_for_interface(interface) |
| 253 |
| 254 # Methods must not be exposed to a broader scope than their interface. |
| 255 if not set(exposure_set).issubset(interface_exposure_set): |
| 256 raise ValueError('Interface members\' exposure sets must be a subset of
the interface\'s.') |
| 257 |
| 258 exposure_checks = [] |
| 259 for environment in exposure_set: |
| 260 # Methods must be exposed on one of the scopes known to Blink. |
| 261 if environment not in EXPOSED_EXECUTION_CONTEXT_METHOD: |
| 262 raise ValueError('Values for the [Exposed] annotation must reflect t
o a valid exposure scope.') |
| 263 |
| 264 exposure_checks.append('context->%s()' % EXPOSED_EXECUTION_CONTEXT_METHO
D[environment]) |
| 265 |
| 266 return ' || '.join(exposure_checks) |
| 267 |
| 268 |
| 269 def expanded_exposure_set_for_interface(interface): |
| 270 exposure_set = sorted_extended_attribute_set(interface, 'Exposed') |
| 271 |
| 272 # "Worker" is an aggregation for the different kinds of workers. |
| 273 if 'Worker' in exposure_set: |
| 274 exposure_set.extend(('DedicatedWorker', 'SharedWorker', 'ServiceWorker')
) |
| 275 |
| 276 return sorted(set(exposure_set)) |
| 277 |
| 278 |
228 # [GarbageCollected], [WillBeGarbageCollected] | 279 # [GarbageCollected], [WillBeGarbageCollected] |
229 def gc_type(definition): | 280 def gc_type(definition): |
230 extended_attributes = definition.extended_attributes | 281 extended_attributes = definition.extended_attributes |
231 if 'GarbageCollected' in extended_attributes: | 282 if 'GarbageCollected' in extended_attributes: |
232 return 'GarbageCollectedObject' | 283 return 'GarbageCollectedObject' |
233 elif 'WillBeGarbageCollected' in extended_attributes: | 284 elif 'WillBeGarbageCollected' in extended_attributes: |
234 return 'WillBeGarbageCollectedObject' | 285 return 'WillBeGarbageCollectedObject' |
235 return 'RefCountedObject' | 286 return 'RefCountedObject' |
236 | 287 |
237 | 288 |
(...skipping 29 matching lines...) Expand all Loading... |
267 | 318 |
268 The returned function checks if a method/attribute is enabled. | 319 The returned function checks if a method/attribute is enabled. |
269 Given extended attribute RuntimeEnabled=FeatureName, return: | 320 Given extended attribute RuntimeEnabled=FeatureName, return: |
270 RuntimeEnabledFeatures::{featureName}Enabled | 321 RuntimeEnabledFeatures::{featureName}Enabled |
271 """ | 322 """ |
272 extended_attributes = definition_or_member.extended_attributes | 323 extended_attributes = definition_or_member.extended_attributes |
273 if 'RuntimeEnabled' not in extended_attributes: | 324 if 'RuntimeEnabled' not in extended_attributes: |
274 return None | 325 return None |
275 feature_name = extended_attributes['RuntimeEnabled'] | 326 feature_name = extended_attributes['RuntimeEnabled'] |
276 return 'RuntimeEnabledFeatures::%sEnabled' % uncapitalize(feature_name) | 327 return 'RuntimeEnabledFeatures::%sEnabled' % uncapitalize(feature_name) |
OLD | NEW |