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