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

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: address comments 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
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_list(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
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 def exposed(definition_or_member, interface):
247 extended_attributes = definition_or_member.extended_attributes
Jens Widell 2014/07/30 16:48:45 This local is only used once, on the line below, a
Peter Beverloo 2014/07/31 19:02:21 Done.
248 if 'Exposed' not in extended_attributes:
249 return None
250
251 exposure_list = sorted_extended_attribute_list(definition_or_member, 'Expose d')
Jens Widell 2014/07/30 16:48:45 I think you could have stuck with 'exposure_set' h
Peter Beverloo 2014/07/31 19:02:21 I'm in dubio. It would indeed describe the content
252 interface_exposure_list = expanded_exposure_list_for_interface(interface)
253
254 # Methods must not be exposed to a broader scope than their interface.
255 if not set(exposure_list).issubset(interface_exposure_list):
256 raise Exception('Interface members\' exposure sets must be a subset of t he interface\'s.')
haraken 2014/07/30 16:32:03 Nit: We normally use ValueError instead of Excepti
Peter Beverloo 2014/07/31 19:02:22 Done.
257
258 exposure_checks = []
259 for environment in exposure_list:
260 # Methods must be exposed on one of the scopes known to Blink.
261 if environment not in EXPOSED_EXECUTION_CONTEXT_METHOD:
262 raise Exception('Values for the [Exposed] annotation must reflect to a valid exposure scope.')
haraken 2014/07/30 16:32:03 Ditto.
Peter Beverloo 2014/07/31 19:02:22 Done.
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_list_for_interface(interface):
270 exposure_list = sorted_extended_attribute_list(interface, 'Exposed')
271
272 # "Worker" is an aggregation for the different kinds of workers.
273 if 'Worker' in exposure_list:
274 exposure_list.extend(('DedicatedWorker', 'SharedWorker', 'ServiceWorker' ))
275
276 return sorted(set(exposure_list))
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
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)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698