| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 context['parent_cpp_class'] = 'IDLDictionaryBase' | 181 context['parent_cpp_class'] = 'IDLDictionaryBase' |
| 182 context['header_includes'].add( | 182 context['header_includes'].add( |
| 183 'bindings/core/v8/IDLDictionaryBase.h') | 183 'bindings/core/v8/IDLDictionaryBase.h') |
| 184 return context | 184 return context |
| 185 | 185 |
| 186 | 186 |
| 187 def member_impl_context(member, interfaces_info, header_includes): | 187 def member_impl_context(member, interfaces_info, header_includes): |
| 188 idl_type = unwrap_nullable_if_needed(member.idl_type) | 188 idl_type = unwrap_nullable_if_needed(member.idl_type) |
| 189 cpp_name = v8_utilities.cpp_name(member) | 189 cpp_name = v8_utilities.cpp_name(member) |
| 190 | 190 |
| 191 def getter_expression(): | 191 nullable_indicator_name = None |
| 192 if idl_type.impl_should_use_nullable_container: | 192 if not idl_type.cpp_type_has_null_value: |
| 193 return 'm_%s.get()' % cpp_name | 193 nullable_indicator_name = 'm_has' + cpp_name[0].upper() + cpp_name[1:] |
| 194 return 'm_%s' % cpp_name | |
| 195 | 194 |
| 196 def has_method_expression(): | 195 def has_method_expression(): |
| 197 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: | 196 if nullable_indicator_name: |
| 197 return nullable_indicator_name |
| 198 elif idl_type.is_enum or idl_type.is_string_type or idl_type.is_union_ty
pe: |
| 198 return '!m_%s.isNull()' % cpp_name | 199 return '!m_%s.isNull()' % cpp_name |
| 199 elif idl_type.name in ['Any', 'Object']: | 200 elif idl_type.name in ['Any', 'Object']: |
| 200 return '!(m_{0}.isEmpty() || m_{0}.isNull() || m_{0}.isUndefined())'
.format(cpp_name) | 201 return '!(m_{0}.isEmpty() || m_{0}.isNull() || m_{0}.isUndefined())'
.format(cpp_name) |
| 201 elif idl_type.name == 'Dictionary': | 202 elif idl_type.name == 'Dictionary': |
| 202 return '!m_%s.isUndefinedOrNull()' % cpp_name | 203 return '!m_%s.isUndefinedOrNull()' % cpp_name |
| 203 else: | 204 else: |
| 204 return 'm_%s' % cpp_name | 205 return 'm_%s' % cpp_name |
| 205 | 206 |
| 206 def member_cpp_type(): | |
| 207 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) | |
| 208 if idl_type.impl_should_use_nullable_container: | |
| 209 return v8_types.cpp_template_type('Nullable', member_cpp_type) | |
| 210 return member_cpp_type | |
| 211 | |
| 212 cpp_default_value = None | 207 cpp_default_value = None |
| 213 if member.default_value and not member.default_value.is_null: | 208 if member.default_value and not member.default_value.is_null: |
| 214 cpp_default_value = idl_type.literal_cpp_value(member.default_value) | 209 cpp_default_value = idl_type.literal_cpp_value(member.default_value) |
| 215 | 210 |
| 216 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) | 211 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) |
| 217 return { | 212 return { |
| 218 'cpp_default_value': cpp_default_value, | 213 'cpp_default_value': cpp_default_value, |
| 219 'cpp_name': cpp_name, | 214 'cpp_name': cpp_name, |
| 220 'getter_expression': getter_expression(), | 215 'getter_expression': 'm_' + cpp_name, |
| 221 'has_method_expression': has_method_expression(), | 216 'has_method_expression': has_method_expression(), |
| 222 'has_method_name': has_method_name_for_dictionary_member(member), | 217 'has_method_name': has_method_name_for_dictionary_member(member), |
| 223 'is_nullable': idl_type.is_nullable, | 218 'is_nullable': idl_type.is_nullable, |
| 224 'is_traceable': idl_type.is_traceable, | 219 'is_traceable': idl_type.is_traceable, |
| 225 'member_cpp_type': member_cpp_type(), | 220 'member_cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=True), |
| 226 'null_setter_name': null_setter_name_for_dictionary_member(member), | 221 'null_setter_name': null_setter_name_for_dictionary_member(member), |
| 222 'nullable_indicator_name': nullable_indicator_name, |
| 227 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 223 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
| 228 'setter_name': setter_name_for_dictionary_member(member), | 224 'setter_name': setter_name_for_dictionary_member(member), |
| 229 } | 225 } |
| OLD | NEW |