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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/templates/interface.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/v8_utilities.py
diff --git a/Source/bindings/scripts/v8_utilities.py b/Source/bindings/scripts/v8_utilities.py
index e76983fd37e60cc33ebb13615b2d5a517db72f6e..f401a0b8339f27da11a5cccb0e81a3d3e0675b45 100644
--- a/Source/bindings/scripts/v8_utilities.py
+++ b/Source/bindings/scripts/v8_utilities.py
@@ -74,6 +74,15 @@ def has_extended_attribute_value(definition_or_member, name, value):
extended_attribute_value_contains(extended_attributes[name], value))
+def sorted_extended_attribute_set(definition_or_member, name):
+ extended_attributes = definition_or_member.extended_attributes
+ if name not in extended_attributes:
+ return []
+
+ attribute_values = re.split('[|,]', extended_attributes[name])
+ return sorted(attribute_values)
+
+
################################################################################
# String handling
################################################################################
@@ -231,6 +240,48 @@ def deprecate_as(member):
return extended_attributes['DeprecateAs']
+# [Exposed]
+EXPOSED_EXECUTION_CONTEXT_METHOD = {
+ 'DedicatedWorker': 'isDedicatedWorkerGlobalScope',
+ 'ServiceWorker': 'isServiceWorkerGlobalScope',
+ 'SharedWorker': 'isSharedWorkerGlobalScope',
+ 'Window': 'isDocument',
+ 'Worker': 'isWorkerGlobalScope',
+}
+
+
+def exposed(definition_or_member, interface):
+ exposure_set = sorted_extended_attribute_set(definition_or_member, 'Exposed')
+ if not exposure_set:
+ return None
+
+ interface_exposure_set = expanded_exposure_set_for_interface(interface)
+
+ # Methods must not be exposed to a broader scope than their interface.
+ if not set(exposure_set).issubset(interface_exposure_set):
+ raise ValueError('Interface members\' exposure sets must be a subset of the interface\'s.')
+
+ exposure_checks = []
+ for environment in exposure_set:
+ # Methods must be exposed on one of the scopes known to Blink.
+ if environment not in EXPOSED_EXECUTION_CONTEXT_METHOD:
+ raise ValueError('Values for the [Exposed] annotation must reflect to a valid exposure scope.')
+
+ exposure_checks.append('context->%s()' % EXPOSED_EXECUTION_CONTEXT_METHOD[environment])
+
+ return ' || '.join(exposure_checks)
+
+
+def expanded_exposure_set_for_interface(interface):
+ exposure_set = sorted_extended_attribute_set(interface, 'Exposed')
+
+ # "Worker" is an aggregation for the different kinds of workers.
+ if 'Worker' in exposure_set:
+ exposure_set.extend(('DedicatedWorker', 'SharedWorker', 'ServiceWorker'))
+
+ return sorted(set(exposure_set))
+
+
# [GarbageCollected], [WillBeGarbageCollected]
def gc_type(definition):
extended_attributes = definition.extended_attributes
« 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