Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: Source/bindings/scripts/v8_utilities.py

Issue 424163002: Enable the WebIDL [Exposed] annotation on an interface's members. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: missed renames Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/templates/interface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 233
225 # [DeprecateAs] 234 # [DeprecateAs]
226 def deprecate_as(member): 235 def deprecate_as(member):
227 extended_attributes = member.extended_attributes 236 extended_attributes = member.extended_attributes
228 if 'DeprecateAs' not in extended_attributes: 237 if 'DeprecateAs' not in extended_attributes:
229 return None 238 return None
230 includes.add('core/frame/UseCounter.h') 239 includes.add('core/frame/UseCounter.h')
231 return extended_attributes['DeprecateAs'] 240 return extended_attributes['DeprecateAs']
232 241
233 242
243 # [Exposed]
244 EXPOSED_EXECUTION_CONTEXT_METHOD = {
245 'DedicatedWorker': 'isDedicatedWorkerGlobalScope',
246 'ServiceWorker': 'isServiceWorkerGlobalScope',
247 'SharedWorker': 'isSharedWorkerGlobalScope',
248 'Window': 'isDocument',
249 'Worker': 'isWorkerGlobalScope',
250 }
251
252
253 def exposed(definition_or_member, interface):
254 exposure_set = sorted_extended_attribute_set(definition_or_member, 'Exposed' )
255 if not exposure_set:
256 return None
257
258 interface_exposure_set = expanded_exposure_set_for_interface(interface)
259
260 # Methods must not be exposed to a broader scope than their interface.
261 if not set(exposure_set).issubset(interface_exposure_set):
262 raise ValueError('Interface members\' exposure sets must be a subset of the interface\'s.')
263
264 exposure_checks = []
265 for environment in exposure_set:
266 # Methods must be exposed on one of the scopes known to Blink.
267 if environment not in EXPOSED_EXECUTION_CONTEXT_METHOD:
268 raise ValueError('Values for the [Exposed] annotation must reflect t o a valid exposure scope.')
269
270 exposure_checks.append('context->%s()' % EXPOSED_EXECUTION_CONTEXT_METHO D[environment])
271
272 return ' || '.join(exposure_checks)
273
274
275 def expanded_exposure_set_for_interface(interface):
276 exposure_set = sorted_extended_attribute_set(interface, 'Exposed')
277
278 # "Worker" is an aggregation for the different kinds of workers.
279 if 'Worker' in exposure_set:
280 exposure_set.extend(('DedicatedWorker', 'SharedWorker', 'ServiceWorker') )
281
282 return sorted(set(exposure_set))
283
284
234 # [GarbageCollected], [WillBeGarbageCollected] 285 # [GarbageCollected], [WillBeGarbageCollected]
235 def gc_type(definition): 286 def gc_type(definition):
236 extended_attributes = definition.extended_attributes 287 extended_attributes = definition.extended_attributes
237 if 'GarbageCollected' in extended_attributes: 288 if 'GarbageCollected' in extended_attributes:
238 return 'GarbageCollectedObject' 289 return 'GarbageCollectedObject'
239 elif 'WillBeGarbageCollected' in extended_attributes: 290 elif 'WillBeGarbageCollected' in extended_attributes:
240 return 'WillBeGarbageCollectedObject' 291 return 'WillBeGarbageCollectedObject'
241 return 'RefCountedObject' 292 return 'RefCountedObject'
242 293
243 294
(...skipping 29 matching lines...) Expand all
273 324
274 The returned function checks if a method/attribute is enabled. 325 The returned function checks if a method/attribute is enabled.
275 Given extended attribute RuntimeEnabled=FeatureName, return: 326 Given extended attribute RuntimeEnabled=FeatureName, return:
276 RuntimeEnabledFeatures::{featureName}Enabled 327 RuntimeEnabledFeatures::{featureName}Enabled
277 """ 328 """
278 extended_attributes = definition_or_member.extended_attributes 329 extended_attributes = definition_or_member.extended_attributes
279 if 'RuntimeEnabled' not in extended_attributes: 330 if 'RuntimeEnabled' not in extended_attributes:
280 return None 331 return None
281 feature_name = extended_attributes['RuntimeEnabled'] 332 feature_name = extended_attributes['RuntimeEnabled']
282 return 'RuntimeEnabledFeatures::%sEnabled' % uncapitalize(feature_name) 333 return 'RuntimeEnabledFeatures::%sEnabled' % uncapitalize(feature_name)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/templates/interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698