Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Generate template contexts of dictionaries for both v8 bindings and | 5 """Generate template contexts of dictionaries for both v8 bindings and |
| 6 implementation classes that are used by blink's core/modules. | 6 implementation classes that are used by blink's core/modules. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import copy | 9 import copy |
| 10 import operator | 10 import operator |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 cpp_value='impl->%s()' % member.name, isolate='isolate', | 79 cpp_value='impl->%s()' % member.name, isolate='isolate', |
| 80 creation_context='creationContext', | 80 creation_context='creationContext', |
| 81 extended_attributes=member.extended_attributes), | 81 extended_attributes=member.extended_attributes), |
| 82 'has_name': has_name_for_dictionary_member(member), | 82 'has_name': has_name_for_dictionary_member(member), |
| 83 'name': member.name, | 83 'name': member.name, |
| 84 'setter_name': setter_name_for_dictionary_member(member), | 84 'setter_name': setter_name_for_dictionary_member(member), |
| 85 'v8_default_value': v8_default_value, | 85 'v8_default_value': v8_default_value, |
| 86 'v8_type': v8_types.v8_type(idl_type.base_type), | 86 'v8_type': v8_types.v8_type(idl_type.base_type), |
| 87 } | 87 } |
| 88 | 88 |
| 89 # FIXME: Implement context for impl class. | 89 |
| 90 # Context for implementation classes | |
| 91 | |
| 92 def dictionary_impl_context(dictionary, interfaces_info): | |
| 93 includes.clear() | |
| 94 header_includes = set(['platform/heap/Handle.h']) | |
| 95 return { | |
| 96 'header_includes': header_includes, | |
| 97 'cpp_class': v8_utilities.cpp_name(dictionary), | |
| 98 'members': [member_impl_context(member, interfaces_info, | |
| 99 header_includes) | |
| 100 for member in dictionary.members], | |
| 101 } | |
| 102 | |
| 103 | |
| 104 def member_impl_context(member, interfaces_info, header_includes): | |
| 105 idl_type = member.idl_type | |
| 106 | |
| 107 def should_use_nullable_container(): | |
| 108 return idl_type.native_array_element_type or idl_type.is_primitive_type | |
| 109 | |
| 110 def collect_includes(idl_type): | |
|
bashi
2014/07/25 10:05:40
Takes idl_type as argument as this function is rec
| |
| 111 includes_for_type = set() | |
| 112 if should_use_nullable_container(): | |
| 113 includes_for_type.add('bindings/core/v8/Nullable.h') | |
| 114 | |
| 115 idl_type = idl_type.preprocessed_type | |
| 116 native_array_element_type = idl_type.native_array_element_type | |
| 117 if native_array_element_type: | |
| 118 includes_for_type.update(collect_includes( | |
| 119 native_array_element_type)) | |
| 120 includes_for_type.add('wtf/Vector.h') | |
| 121 | |
| 122 if idl_type.is_string_type: | |
| 123 includes_for_type.add('wtf/text/WTFString.h') | |
| 124 if idl_type.name in interfaces_info: | |
| 125 interface_info = interfaces_info[idl_type.name] | |
| 126 includes_for_type.add(interface_info['include_path']) | |
| 127 return includes_for_type | |
| 128 | |
| 129 def argument_cpp_type(): | |
| 130 argument_cpp_type = idl_type.cpp_type_args(used_as_argument=True) | |
| 131 if idl_type.native_array_element_type: | |
| 132 return 'const %s&' % argument_cpp_type | |
| 133 return argument_cpp_type | |
| 134 | |
| 135 def getter_cpp_type(): | |
| 136 getter_cpp_type = idl_type.cpp_type_args(used_as_return_type=True) | |
| 137 if (idl_type.native_array_element_type or idl_type.is_string_type): | |
| 138 return 'const %s&' % getter_cpp_type | |
| 139 return getter_cpp_type | |
| 140 | |
| 141 def getter_method_expression(): | |
| 142 if should_use_nullable_container(): | |
| 143 return 'm_%s.get()' % member.name | |
| 144 return 'm_%s' % member.name | |
| 145 | |
| 146 def has_method_expression(): | |
| 147 if should_use_nullable_container() or idl_type.is_string_type: | |
| 148 return '!m_%s.isNull()' % member.name | |
| 149 else: | |
| 150 return 'm_%s' % member.name | |
| 151 | |
| 152 def member_cpp_type(): | |
| 153 member_cpp_type = idl_type.cpp_type_args(used_as_member=True) | |
| 154 if should_use_nullable_container(): | |
| 155 return v8_types.cpp_template_type('Nullable', member_cpp_type) | |
| 156 return member_cpp_type | |
| 157 | |
| 158 header_includes.update(collect_includes(idl_type)) | |
| 159 return { | |
| 160 'argument_cpp_type': argument_cpp_type(), | |
| 161 'getter_cpp_type': getter_cpp_type(), | |
| 162 'getter_method_expression': getter_method_expression(), | |
| 163 'has_method_expression': has_method_expression(), | |
| 164 'has_name': has_name_for_dictionary_member(member), | |
| 165 'is_traceable': (idl_type.is_garbage_collected or | |
| 166 idl_type.is_will_be_garbage_collected), | |
| 167 'member_cpp_type': member_cpp_type(), | |
| 168 'name': member.name, | |
| 169 'setter_name': setter_name_for_dictionary_member(member), | |
| 170 } | |
| OLD | NEW |