| 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 operator | 9 import operator |
| 10 from idl_types import IdlType | 10 from idl_types import IdlType |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 dictionary.parent, interfaces_info) | 158 dictionary.parent, interfaces_info) |
| 159 parent_interface_info = interfaces_info.get(dictionary.parent) | 159 parent_interface_info = interfaces_info.get(dictionary.parent) |
| 160 if parent_interface_info: | 160 if parent_interface_info: |
| 161 context['header_includes'].add( | 161 context['header_includes'].add( |
| 162 parent_interface_info['include_path']) | 162 parent_interface_info['include_path']) |
| 163 return context | 163 return context |
| 164 | 164 |
| 165 | 165 |
| 166 def member_impl_context(member, interfaces_info, header_includes): | 166 def member_impl_context(member, interfaces_info, header_includes): |
| 167 idl_type = unwrap_nullable_if_needed(member.idl_type) | 167 idl_type = unwrap_nullable_if_needed(member.idl_type) |
| 168 is_object = idl_type.name == 'Object' | |
| 169 cpp_name = v8_utilities.cpp_name(member) | 168 cpp_name = v8_utilities.cpp_name(member) |
| 170 | 169 |
| 171 def getter_expression(): | 170 def getter_expression(): |
| 172 if idl_type.impl_should_use_nullable_container: | 171 if idl_type.impl_should_use_nullable_container: |
| 173 return 'm_%s.get()' % cpp_name | 172 return 'm_%s.get()' % cpp_name |
| 174 return 'm_%s' % cpp_name | 173 return 'm_%s' % cpp_name |
| 175 | 174 |
| 176 def has_method_expression(): | 175 def has_method_expression(): |
| 177 if idl_type.impl_should_use_nullable_container or idl_type.is_enum or id
l_type.is_string_type or idl_type.is_union_type: | 176 if idl_type.impl_should_use_nullable_container or idl_type.is_enum or id
l_type.is_string_type or idl_type.is_union_type: |
| 178 return '!m_%s.isNull()' % cpp_name | 177 return '!m_%s.isNull()' % cpp_name |
| 179 elif is_object: | 178 elif idl_type.name in ['Any', 'Object']: |
| 180 return '!(m_{0}.isEmpty() || m_{0}.isNull() || m_{0}.isUndefined())'
.format(cpp_name) | 179 return '!(m_{0}.isEmpty() || m_{0}.isNull() || m_{0}.isUndefined())'
.format(cpp_name) |
| 181 else: | 180 else: |
| 182 return 'm_%s' % cpp_name | 181 return 'm_%s' % cpp_name |
| 183 | 182 |
| 184 def member_cpp_type(): | 183 def member_cpp_type(): |
| 185 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) | 184 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) |
| 186 if idl_type.impl_should_use_nullable_container: | 185 if idl_type.impl_should_use_nullable_container: |
| 187 return v8_types.cpp_template_type('Nullable', member_cpp_type) | 186 return v8_types.cpp_template_type('Nullable', member_cpp_type) |
| 188 return member_cpp_type | 187 return member_cpp_type |
| 189 | 188 |
| 190 cpp_default_value = None | 189 cpp_default_value = None |
| 191 if member.default_value and not member.default_value.is_null: | 190 if member.default_value and not member.default_value.is_null: |
| 192 cpp_default_value = idl_type.literal_cpp_value(member.default_value) | 191 cpp_default_value = idl_type.literal_cpp_value(member.default_value) |
| 193 | 192 |
| 194 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) | 193 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) |
| 195 return { | 194 return { |
| 196 'cpp_default_value': cpp_default_value, | 195 'cpp_default_value': cpp_default_value, |
| 197 'cpp_name': cpp_name, | 196 'cpp_name': cpp_name, |
| 198 'getter_expression': getter_expression(), | 197 'getter_expression': getter_expression(), |
| 199 'has_method_expression': has_method_expression(), | 198 'has_method_expression': has_method_expression(), |
| 200 'has_method_name': has_method_name_for_dictionary_member(member), | 199 'has_method_name': has_method_name_for_dictionary_member(member), |
| 201 'is_object': is_object, | |
| 202 'is_traceable': idl_type.is_traceable, | 200 'is_traceable': idl_type.is_traceable, |
| 203 'member_cpp_type': member_cpp_type(), | 201 'member_cpp_type': member_cpp_type(), |
| 204 'null_setter_name': null_setter_name_for_dictionary_member(member), | 202 'null_setter_name': null_setter_name_for_dictionary_member(member), |
| 205 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 203 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
| 206 'setter_name': setter_name_for_dictionary_member(member), | 204 'setter_name': setter_name_for_dictionary_member(member), |
| 207 } | 205 } |
| OLD | NEW |