"""Functions shared by various parts of the code generator.
-Extends IdlType and IdlUnion type with |enum_validation_expression| property.
+Extends IdlTypeBase type with |enum_validation_expression| property.
Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
"""
import re
-from idl_types import IdlType, IdlUnionType
+from idl_types import IdlTypeBase
import idl_types
from v8_globals import includes
import v8_types
def extended_attribute_value_contains(extended_attribute_value, value):
return (extended_attribute_value and
- value in re.split('[|&]', extended_attribute_value))
+ value in re.split('[|,]', extended_attribute_value))
def has_extended_attribute(definition_or_member, extended_attribute_list):
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
################################################################################
return None
return ' || '.join(['string == "%s"' % enum_value
for enum_value in idl_type.enum_values])
-IdlType.enum_validation_expression = property(enum_validation_expression)
+IdlTypeBase.enum_validation_expression = property(enum_validation_expression)
def scoped_name(interface, definition, base_name):
+ if 'ImplementedInPrivateScript' in definition.extended_attributes:
+ return '%s::PrivateScript::%s' % (v8_class_name(interface), base_name)
# partial interfaces are implemented as separate classes, with their members
# implemented as static member functions
partial_interface_implemented_as = definition.extended_attributes.get('PartialInterfaceImplementedAs')
if log_activity and not log_activity.startswith(access_type):
return set()
- includes.add('bindings/v8/V8DOMActivityLogger.h')
+ includes.add('bindings/core/v8/V8DOMActivityLogger.h')
if 'LogAllWorlds' in extended_attributes:
return set(['', 'ForMainWorld'])
return set(['']) # At minimum, include isolated worlds.
# [Conditional]
+DELIMITER_TO_OPERATOR = {
+ '|': '||',
+ ',': '&&',
+}
+
+
def conditional_string(definition_or_member):
extended_attributes = definition_or_member.extended_attributes
if 'Conditional' not in extended_attributes:
return None
conditional = extended_attributes['Conditional']
- for operator in '&|':
- if operator in conditional:
- conditions = conditional.split(operator)
- operator_separator = ' %s%s ' % (operator, operator)
+ for delimiter in ',|':
+ if delimiter in conditional:
+ conditions = conditional.split(delimiter)
+ operator_separator = ' %s ' % DELIMITER_TO_OPERATOR[delimiter]
return operator_separator.join('ENABLE(%s)' % expression for expression in sorted(conditions))
return 'ENABLE(%s)' % conditional
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