| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 idl_type = unwrap_nullable_if_needed(member.idl_type) | 201 idl_type = unwrap_nullable_if_needed(member.idl_type) |
| 202 cpp_name = v8_utilities.cpp_name(member) | 202 cpp_name = v8_utilities.cpp_name(member) |
| 203 | 203 |
| 204 nullable_indicator_name = None | 204 nullable_indicator_name = None |
| 205 if not idl_type.cpp_type_has_null_value: | 205 if not idl_type.cpp_type_has_null_value: |
| 206 nullable_indicator_name = 'm_has' + cpp_name[0].upper() + cpp_name[1:] | 206 nullable_indicator_name = 'm_has' + cpp_name[0].upper() + cpp_name[1:] |
| 207 | 207 |
| 208 def has_method_expression(): | 208 def has_method_expression(): |
| 209 if nullable_indicator_name: | 209 if nullable_indicator_name: |
| 210 return nullable_indicator_name | 210 return nullable_indicator_name |
| 211 elif idl_type.is_enum or idl_type.is_string_type or idl_type.is_union_ty
pe: | 211 elif idl_type.is_union_type: |
| 212 return '!m_%s.isNull()' % cpp_name | 212 return '!m_%s.isNull()' % cpp_name |
| 213 elif idl_type.is_enum or idl_type.is_string_type: |
| 214 return '!m_%s.IsNull()' % cpp_name |
| 213 elif idl_type.name in ['Any', 'Object']: | 215 elif idl_type.name in ['Any', 'Object']: |
| 214 return '!(m_{0}.isEmpty() || m_{0}.isNull() || m_{0}.isUndefined())'
.format(cpp_name) | 216 return '!(m_{0}.IsEmpty() || m_{0}.IsNull() || m_{0}.IsUndefined())'
.format(cpp_name) |
| 215 elif idl_type.name == 'Dictionary': | 217 elif idl_type.name == 'Dictionary': |
| 216 return '!m_%s.isUndefinedOrNull()' % cpp_name | 218 return '!m_%s.IsUndefinedOrNull()' % cpp_name |
| 217 else: | 219 else: |
| 218 return 'm_%s' % cpp_name | 220 return 'm_%s' % cpp_name |
| 219 | 221 |
| 220 cpp_default_value = None | 222 cpp_default_value = None |
| 221 if member.default_value and not member.default_value.is_null: | 223 if member.default_value and not member.default_value.is_null: |
| 222 cpp_default_value = idl_type.literal_cpp_value(member.default_value) | 224 cpp_default_value = idl_type.literal_cpp_value(member.default_value) |
| 223 | 225 |
| 224 forward_decl_name = idl_type.impl_forward_declaration_name | 226 forward_decl_name = idl_type.impl_forward_declaration_name |
| 225 if forward_decl_name: | 227 if forward_decl_name: |
| 226 includes.update(idl_type.impl_includes_for_type(interfaces_info)) | 228 includes.update(idl_type.impl_includes_for_type(interfaces_info)) |
| 227 header_forward_decls.add(forward_decl_name) | 229 header_forward_decls.add(forward_decl_name) |
| 228 else: | 230 else: |
| 229 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) | 231 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) |
| 230 | 232 |
| 231 return { | 233 return { |
| 232 'cpp_default_value': cpp_default_value, | 234 'cpp_default_value': cpp_default_value, |
| 233 'cpp_name': cpp_name, | 235 'cpp_name': cpp_name, |
| 234 'getter_expression': 'm_' + cpp_name, | 236 'getter_expression': 'm_' + cpp_name, |
| 235 'getter_name': getter_name_for_dictionary_member(member), | 237 'getter_name': getter_name_for_dictionary_member(member), |
| 236 'has_method_expression': has_method_expression(), | 238 'has_method_expression': has_method_expression(), |
| 237 'has_method_name': has_method_name_for_dictionary_member(member), | 239 'has_method_name': has_method_name_for_dictionary_member(member), |
| 238 'is_nullable': idl_type.is_nullable, | 240 'is_nullable': idl_type.is_nullable, |
| 239 'is_traceable': idl_type.is_traceable, | 241 'is_traceable': idl_type.is_traceable, |
| 240 'member_cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=True), | 242 'member_cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=True), |
| 241 'null_setter_name': null_setter_name_for_dictionary_member(member), | 243 'null_setter_name': null_setter_name_for_dictionary_member(member), |
| 242 'nullable_indicator_name': nullable_indicator_name, | 244 'nullable_indicator_name': nullable_indicator_name, |
| 243 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 245 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
| 244 'setter_name': setter_name_for_dictionary_member(member), | 246 'setter_name': setter_name_for_dictionary_member(member), |
| 245 } | 247 } |
| OLD | NEW |