| 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 26 matching lines...) Expand all Loading... |
| 37 ################################################################################ | 37 ################################################################################ |
| 38 # Utility function exposed for Dart CodeGenerator. Only 6 methods are special | 38 # Utility function exposed for Dart CodeGenerator. Only 6 methods are special |
| 39 # to Dart the rest delegate to the v8_utilities functions. | 39 # to Dart the rest delegate to the v8_utilities functions. |
| 40 ################################################################################ | 40 ################################################################################ |
| 41 | 41 |
| 42 | 42 |
| 43 import v8_types # Required | 43 import v8_types # Required |
| 44 import v8_utilities | 44 import v8_utilities |
| 45 | 45 |
| 46 | 46 |
| 47 def _enum_validation_expression(idl_type): |
| 48 # FIXME: Add IdlEnumType, move property to derived type, and remove this che
ck |
| 49 if not idl_type.is_enum: |
| 50 return None |
| 51 return ' || '.join(['((String){param_name}) == "%s"' % enum_value |
| 52 for enum_value in idl_type.enum_values]) |
| 53 |
| 54 |
| 47 def _scoped_name(interface, definition, base_name): | 55 def _scoped_name(interface, definition, base_name): |
| 48 # partial interfaces are implemented as separate classes, with their members | 56 # partial interfaces are implemented as separate classes, with their members |
| 49 # implemented as static member functions | 57 # implemented as static member functions |
| 50 partial_interface_implemented_as = definition.extended_attributes.get('Parti
alInterfaceImplementedAs') | 58 partial_interface_implemented_as = definition.extended_attributes.get('Parti
alInterfaceImplementedAs') |
| 51 if partial_interface_implemented_as: | 59 if partial_interface_implemented_as: |
| 52 return '%s::%s' % (partial_interface_implemented_as, base_name) | 60 return '%s::%s' % (partial_interface_implemented_as, base_name) |
| 53 if (definition.is_static or | 61 if (definition.is_static or |
| 54 definition.name in ('Constructor', 'NamedConstructor')): | 62 definition.name in ('Constructor', 'NamedConstructor')): |
| 55 return '%s::%s' % (v8_utilities.cpp_name(interface), base_name) | 63 return '%s::%s' % (v8_utilities.cpp_name(interface), base_name) |
| 56 return 'receiver->%s' % base_name | 64 return 'receiver->%s' % base_name |
| (...skipping 26 matching lines...) Expand all Loading... |
| 83 return set(['', 'ForMainWorld']) # endswith('ForAllWorlds') | 91 return set(['', 'ForMainWorld']) # endswith('ForAllWorlds') |
| 84 | 92 |
| 85 | 93 |
| 86 # [CallWith] | 94 # [CallWith] |
| 87 _CALL_WITH_ARGUMENTS = { | 95 _CALL_WITH_ARGUMENTS = { |
| 88 'ScriptState': 'state', | 96 'ScriptState': 'state', |
| 89 'ExecutionContext': 'context', | 97 'ExecutionContext': 'context', |
| 90 'ScriptArguments': 'scriptArguments.release()', | 98 'ScriptArguments': 'scriptArguments.release()', |
| 91 'ActiveWindow': 'DartUtilities::callingDomWindowForCurrentIsolate()', | 99 'ActiveWindow': 'DartUtilities::callingDomWindowForCurrentIsolate()', |
| 92 'FirstWindow': 'DartUtilities::enteredDomWindowForCurrentIsolate()', | 100 'FirstWindow': 'DartUtilities::enteredDomWindowForCurrentIsolate()', |
| 101 'Document': 'document', |
| 93 } | 102 } |
| 94 | 103 |
| 95 # List because key order matters, as we want arguments in deterministic order | 104 # List because key order matters, as we want arguments in deterministic order |
| 96 _CALL_WITH_VALUES = [ | 105 _CALL_WITH_VALUES = [ |
| 97 'ScriptState', | 106 'ScriptState', |
| 98 'ExecutionContext', | 107 'ExecutionContext', |
| 99 'ScriptArguments', | 108 'ScriptArguments', |
| 100 'ActiveWindow', | 109 'ActiveWindow', |
| 101 'FirstWindow', | 110 'FirstWindow', |
| 111 'Document', |
| 102 ] | 112 ] |
| 103 | 113 |
| 104 | 114 |
| 105 def _call_with_arguments(member, call_with_values=None): | 115 def _call_with_arguments(call_with_values): |
| 106 # Optional parameter so setter can override with [SetterCallWith] | |
| 107 call_with_values = call_with_values or member.extended_attributes.get('CallW
ith') | |
| 108 if not call_with_values: | 116 if not call_with_values: |
| 109 return [] | 117 return [] |
| 110 return [_CALL_WITH_ARGUMENTS[value] | 118 return [_CALL_WITH_ARGUMENTS[value] |
| 111 for value in _CALL_WITH_VALUES | 119 for value in _CALL_WITH_VALUES |
| 112 if v8_utilities.extended_attribute_value_contains(call_with_values,
value)] | 120 if v8_utilities.extended_attribute_value_contains(call_with_values,
value)] |
| 113 | 121 |
| 114 | 122 |
| 115 # [DeprecateAs] | 123 # [DeprecateAs] |
| 116 def _deprecate_as(member): | 124 def _deprecate_as(member): |
| 117 extended_attributes = member.extended_attributes | 125 extended_attributes = member.extended_attributes |
| 118 if 'DeprecateAs' not in extended_attributes: | 126 if 'DeprecateAs' not in extended_attributes: |
| 119 return None | 127 return None |
| 120 # TODO(terry): Remove me? | 128 # TODO(terry): Remove me? |
| 121 # includes.add('core/frame/UseCounter.h') | 129 # includes.add('core/frame/UseCounter.h') |
| 122 return extended_attributes['DeprecateAs'] | 130 return extended_attributes['DeprecateAs'] |
| 123 | 131 |
| 124 | 132 |
| 125 # [MeasureAs] | 133 # [MeasureAs] |
| 126 def _measure_as(definition_or_member): | 134 def _measure_as(definition_or_member): |
| 127 extended_attributes = definition_or_member.extended_attributes | 135 extended_attributes = definition_or_member.extended_attributes |
| 128 if 'MeasureAs' not in extended_attributes: | 136 if 'MeasureAs' not in extended_attributes: |
| 129 return None | 137 return None |
| 130 # TODO(terry): Remove Me? | 138 # TODO(terry): Remove Me? |
| 131 # includes.add('core/frame/UseCounter.h') | 139 # includes.add('core/frame/UseCounter.h') |
| 132 return extended_attributes['MeasureAs'] | 140 return extended_attributes['MeasureAs'] |
| 133 | 141 |
| 134 | 142 |
| 135 def _generate_native_entry(interface_name, thing, name, kind, | 143 def _generate_native_entry(interface_name, name, kind, is_static, arity): |
| 136 optional_index, args, types): | 144 |
| 137 index = thing.get('overload_index') or optional_index | 145 def mkPublic(s): |
| 138 is_static = bool(thing.get('is_static')) | 146 if s.startswith("_") or s.startswith("$"): |
| 139 tag = "" | 147 return "$" + s |
| 148 return s |
| 149 |
| 150 arity_str = "" |
| 140 if kind == 'Getter': | 151 if kind == 'Getter': |
| 141 tag = "%s_Getter" % name | 152 suffix = "_Getter" |
| 142 blink_entry = tag | |
| 143 elif kind == 'Setter': | 153 elif kind == 'Setter': |
| 144 tag = "%s_Setter" % name | 154 suffix = "_Setter" |
| 145 blink_entry = tag | |
| 146 elif kind == 'Constructor': | 155 elif kind == 'Constructor': |
| 147 tag = "constructorCallback" | 156 name = "constructor" |
| 148 blink_entry = tag | 157 suffix = "Callback" |
| 149 if index is not None: | 158 arity_str = "_" + str(arity) |
| 150 blink_entry = "_create_%s%s" % (index, blink_entry) | |
| 151 elif kind == 'Method': | 159 elif kind == 'Method': |
| 152 tag = "%s_Callback" % name | 160 suffix = "_Callback" |
| 153 if index is None: | 161 arity_str = "_" + str(arity) |
| 154 blink_entry = tag | 162 |
| 155 else: | 163 tag = "%s%s" % (name, suffix) |
| 156 blink_entry = "_%s_%d_Callback" % (name, index) | 164 blink_entry = mkPublic(tag + arity_str) |
| 157 components = [interface_name, tag] | 165 native_entry = "_".join([interface_name, tag]) |
| 158 if types is not None: | 166 |
| 159 components.extend(types) | 167 argument_names = ['__arg_%d' % i for i in range(0, arity)] |
| 160 native_entry = "_".join(components) | |
| 161 if not is_static and kind != 'Constructor': | 168 if not is_static and kind != 'Constructor': |
| 162 args.insert(0, "mthis") | 169 argument_names.insert(0, "mthis") |
| 163 return {'blink_entry': "$" + blink_entry, | 170 |
| 164 'argument_names': args, | 171 return {'blink_entry': blink_entry, |
| 172 'argument_names': argument_names, |
| 165 'resolver_string': native_entry} | 173 'resolver_string': native_entry} |
| 166 | 174 |
| 167 ################################################################################ | 175 ################################################################################ |
| 168 # This is the monkey patched methods most delegate to v8_utilities but some are | 176 # This is the monkey patched methods most delegate to v8_utilities but some are |
| 169 # overridden in dart_utilities. | 177 # overridden in dart_utilities. |
| 170 ################################################################################ | 178 ################################################################################ |
| 171 | 179 |
| 172 | 180 |
| 173 class dart_utilities_monkey(): | 181 class dart_utilities_monkey(): |
| 174 def __init__(self): | 182 def __init__(self): |
| 175 self.base_class_name = 'dart_utilities' | 183 self.base_class_name = 'dart_utilities' |
| 176 | 184 |
| 177 DartUtilities = dart_utilities_monkey() | 185 DartUtilities = dart_utilities_monkey() |
| 178 | 186 |
| 179 DartUtilities.activity_logging_world_list = _activity_logging_world_list | 187 DartUtilities.activity_logging_world_list = _activity_logging_world_list |
| 180 DartUtilities.bool_to_cpp = _bool_to_cpp | 188 DartUtilities.bool_to_cpp = _bool_to_cpp |
| 181 DartUtilities.call_with_arguments = _call_with_arguments | 189 DartUtilities.call_with_arguments = _call_with_arguments |
| 182 DartUtilities.capitalize = v8_utilities.capitalize | 190 DartUtilities.capitalize = v8_utilities.capitalize |
| 183 DartUtilities.conditional_string = v8_utilities.conditional_string | 191 DartUtilities.conditional_string = v8_utilities.conditional_string |
| 184 DartUtilities.cpp_name = v8_utilities.cpp_name | 192 DartUtilities.cpp_name = v8_utilities.cpp_name |
| 185 DartUtilities.deprecate_as = _deprecate_as | 193 DartUtilities.deprecate_as = _deprecate_as |
| 186 DartUtilities.extended_attribute_value_contains = v8_utilities.extended_attribut
e_value_contains | 194 DartUtilities.extended_attribute_value_contains = v8_utilities.extended_attribut
e_value_contains |
| 195 DartUtilities.enum_validation_expression = _enum_validation_expression |
| 187 DartUtilities.gc_type = v8_utilities.gc_type | 196 DartUtilities.gc_type = v8_utilities.gc_type |
| 188 DartUtilities.generate_native_entry = _generate_native_entry | 197 DartUtilities.generate_native_entry = _generate_native_entry |
| 189 DartUtilities.has_extended_attribute = v8_utilities.has_extended_attribute | 198 DartUtilities.has_extended_attribute = v8_utilities.has_extended_attribute |
| 190 DartUtilities.has_extended_attribute_value = v8_utilities.has_extended_attribute
_value | 199 DartUtilities.has_extended_attribute_value = v8_utilities.has_extended_attribute
_value |
| 191 DartUtilities.measure_as = _measure_as | 200 DartUtilities.measure_as = _measure_as |
| 192 DartUtilities.per_context_enabled_function_name = v8_utilities.per_context_enabl
ed_function_name | 201 DartUtilities.per_context_enabled_function_name = v8_utilities.per_context_enabl
ed_function_name |
| 193 DartUtilities.runtime_enabled_function_name = v8_utilities.runtime_enabled_funct
ion_name | 202 DartUtilities.runtime_enabled_function_name = v8_utilities.runtime_enabled_funct
ion_name |
| 194 DartUtilities.scoped_name = _scoped_name | 203 DartUtilities.scoped_name = _scoped_name |
| 195 DartUtilities.strip_suffix = v8_utilities.strip_suffix | 204 DartUtilities.strip_suffix = v8_utilities.strip_suffix |
| 196 DartUtilities.uncapitalize = v8_utilities.uncapitalize | 205 DartUtilities.uncapitalize = v8_utilities.uncapitalize |
| 197 DartUtilities.v8_class_name = v8_utilities.v8_class_name | 206 DartUtilities.v8_class_name = v8_utilities.v8_class_name |
| OLD | NEW |