| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 def dictionary_context(dictionary, interfaces_info): | 53 def dictionary_context(dictionary, interfaces_info): |
| 54 includes.clear() | 54 includes.clear() |
| 55 includes.update(DICTIONARY_CPP_INCLUDES) | 55 includes.update(DICTIONARY_CPP_INCLUDES) |
| 56 cpp_class = v8_utilities.cpp_name(dictionary) | 56 cpp_class = v8_utilities.cpp_name(dictionary) |
| 57 context = { | 57 context = { |
| 58 'cpp_class': cpp_class, | 58 'cpp_class': cpp_class, |
| 59 'header_includes': set(DICTIONARY_H_INCLUDES), | 59 'header_includes': set(DICTIONARY_H_INCLUDES), |
| 60 'members': [member_context(dictionary, member) | 60 'members': [member_context(dictionary, member) |
| 61 for member in sorted(dictionary.members, | 61 for member in sorted(dictionary.members, |
| 62 key=operator.attrgetter('name'))], | 62 key=operator.attrgetter('name'))], |
| 63 'required_member_names': sorted([member.name |
| 64 for member in dictionary.members |
| 65 if member.is_required]), |
| 63 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion'
in dictionary.extended_attributes, | 66 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion'
in dictionary.extended_attributes, |
| 64 'v8_class': v8_types.v8_type(cpp_class), | 67 'v8_class': v8_types.v8_type(cpp_class), |
| 65 'v8_original_class': v8_types.v8_type(dictionary.name), | 68 'v8_original_class': v8_types.v8_type(dictionary.name), |
| 66 } | 69 } |
| 67 if dictionary.parent: | 70 if dictionary.parent: |
| 68 IdlType(dictionary.parent).add_includes_for_type() | 71 IdlType(dictionary.parent).add_includes_for_type() |
| 69 parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( | 72 parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( |
| 70 dictionary.parent, interfaces_info) | 73 dictionary.parent, interfaces_info) |
| 71 context.update({ | 74 context.update({ |
| 72 'parent_cpp_class': parent_cpp_class, | 75 'parent_cpp_class': parent_cpp_class, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 92 return None, 'v8::Null(isolate)' | 95 return None, 'v8::Null(isolate)' |
| 93 cpp_default_value = unwrapped_idl_type.literal_cpp_value( | 96 cpp_default_value = unwrapped_idl_type.literal_cpp_value( |
| 94 member.default_value) | 97 member.default_value) |
| 95 v8_default_value = unwrapped_idl_type.cpp_value_to_v8_value( | 98 v8_default_value = unwrapped_idl_type.cpp_value_to_v8_value( |
| 96 cpp_value=cpp_default_value, isolate='isolate', | 99 cpp_value=cpp_default_value, isolate='isolate', |
| 97 creation_context='creationContext') | 100 creation_context='creationContext') |
| 98 return cpp_default_value, v8_default_value | 101 return cpp_default_value, v8_default_value |
| 99 | 102 |
| 100 cpp_default_value, v8_default_value = default_values() | 103 cpp_default_value, v8_default_value = default_values() |
| 101 cpp_name = v8_utilities.cpp_name(member) | 104 cpp_name = v8_utilities.cpp_name(member) |
| 105 is_deprecated_dictionary = unwrapped_idl_type.name == 'Dictionary' |
| 102 | 106 |
| 103 return { | 107 return { |
| 104 'cpp_default_value': cpp_default_value, | 108 'cpp_default_value': cpp_default_value, |
| 105 'cpp_name': cpp_name, | 109 'cpp_name': cpp_name, |
| 106 'cpp_type': unwrapped_idl_type.cpp_type, | 110 'cpp_type': unwrapped_idl_type.cpp_type, |
| 107 'cpp_value_to_v8_value': unwrapped_idl_type.cpp_value_to_v8_value( | 111 'cpp_value_to_v8_value': unwrapped_idl_type.cpp_value_to_v8_value( |
| 108 cpp_value='impl.%s()' % cpp_name, isolate='isolate', | 112 cpp_value='impl.%s()' % cpp_name, isolate='isolate', |
| 109 creation_context='creationContext', | 113 creation_context='creationContext', |
| 110 extended_attributes=extended_attributes), | 114 extended_attributes=extended_attributes), |
| 111 'deprecate_as': v8_utilities.deprecate_as(member), | 115 'deprecate_as': v8_utilities.deprecate_as(member), |
| 112 'enum_type': idl_type.enum_type, | 116 'enum_type': idl_type.enum_type, |
| 113 'enum_values': unwrapped_idl_type.enum_values, | 117 'enum_values': unwrapped_idl_type.enum_values, |
| 114 'has_method_name': has_method_name_for_dictionary_member(member), | 118 'has_method_name': has_method_name_for_dictionary_member(member), |
| 115 'idl_type': idl_type.base_type, | 119 'idl_type': idl_type.base_type, |
| 116 'is_interface_type': idl_type.is_interface_type and not idl_type.is_dict
ionary, | 120 'is_interface_type': idl_type.is_interface_type and not (idl_type.is_dic
tionary_type or is_deprecated_dictionary), |
| 117 'is_nullable': idl_type.is_nullable, | 121 'is_nullable': idl_type.is_nullable, |
| 118 'is_object': unwrapped_idl_type.name == 'Object', | 122 'is_object': unwrapped_idl_type.name == 'Object' or is_deprecated_dictio
nary, |
| 119 'is_required': member.is_required, | 123 'is_required': member.is_required, |
| 120 'name': member.name, | 124 'name': member.name, |
| 125 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m
ember), # [RuntimeEnabled] |
| 121 'setter_name': setter_name_for_dictionary_member(member), | 126 'setter_name': setter_name_for_dictionary_member(member), |
| 122 'null_setter_name': null_setter_name_for_dictionary_member(member), | 127 'null_setter_name': null_setter_name_for_dictionary_member(member), |
| 123 'v8_default_value': v8_default_value, | 128 'v8_default_value': v8_default_value, |
| 124 'v8_value_to_local_cpp_value': unwrapped_idl_type.v8_value_to_local_cpp_
value( | 129 'v8_value_to_local_cpp_value': unwrapped_idl_type.v8_value_to_local_cpp_
value( |
| 125 extended_attributes, member.name + 'Value', | 130 extended_attributes, member.name + 'Value', |
| 126 member.name, isolate='isolate', use_exception_state=True), | 131 member.name, isolate='isolate', use_exception_state=True), |
| 127 } | 132 } |
| 128 | 133 |
| 129 | 134 |
| 130 # Context for implementation classes | 135 # Context for implementation classes |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 def getter_expression(): | 175 def getter_expression(): |
| 171 if idl_type.impl_should_use_nullable_container: | 176 if idl_type.impl_should_use_nullable_container: |
| 172 return 'm_%s.get()' % cpp_name | 177 return 'm_%s.get()' % cpp_name |
| 173 return 'm_%s' % cpp_name | 178 return 'm_%s' % cpp_name |
| 174 | 179 |
| 175 def has_method_expression(): | 180 def has_method_expression(): |
| 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: | 181 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: |
| 177 return '!m_%s.isNull()' % cpp_name | 182 return '!m_%s.isNull()' % cpp_name |
| 178 elif idl_type.name in ['Any', 'Object']: | 183 elif idl_type.name in ['Any', 'Object']: |
| 179 return '!(m_{0}.isEmpty() || m_{0}.isNull() || m_{0}.isUndefined())'
.format(cpp_name) | 184 return '!(m_{0}.isEmpty() || m_{0}.isNull() || m_{0}.isUndefined())'
.format(cpp_name) |
| 185 elif idl_type.name == 'Dictionary': |
| 186 return '!m_%s.isUndefinedOrNull()' % cpp_name |
| 180 else: | 187 else: |
| 181 return 'm_%s' % cpp_name | 188 return 'm_%s' % cpp_name |
| 182 | 189 |
| 183 def member_cpp_type(): | 190 def member_cpp_type(): |
| 184 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) | 191 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) |
| 185 if idl_type.impl_should_use_nullable_container: | 192 if idl_type.impl_should_use_nullable_container: |
| 186 return v8_types.cpp_template_type('Nullable', member_cpp_type) | 193 return v8_types.cpp_template_type('Nullable', member_cpp_type) |
| 187 return member_cpp_type | 194 return member_cpp_type |
| 188 | 195 |
| 189 cpp_default_value = None | 196 cpp_default_value = None |
| 190 if member.default_value and not member.default_value.is_null: | 197 if member.default_value and not member.default_value.is_null: |
| 191 cpp_default_value = idl_type.literal_cpp_value(member.default_value) | 198 cpp_default_value = idl_type.literal_cpp_value(member.default_value) |
| 192 | 199 |
| 193 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) | 200 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) |
| 194 return { | 201 return { |
| 195 'cpp_default_value': cpp_default_value, | 202 'cpp_default_value': cpp_default_value, |
| 196 'cpp_name': cpp_name, | 203 'cpp_name': cpp_name, |
| 197 'getter_expression': getter_expression(), | 204 'getter_expression': getter_expression(), |
| 198 'has_method_expression': has_method_expression(), | 205 'has_method_expression': has_method_expression(), |
| 199 'has_method_name': has_method_name_for_dictionary_member(member), | 206 'has_method_name': has_method_name_for_dictionary_member(member), |
| 200 'is_nullable': idl_type.is_nullable, | 207 'is_nullable': idl_type.is_nullable, |
| 201 'is_traceable': idl_type.is_traceable, | 208 'is_traceable': idl_type.is_traceable, |
| 202 'member_cpp_type': member_cpp_type(), | 209 'member_cpp_type': member_cpp_type(), |
| 203 'null_setter_name': null_setter_name_for_dictionary_member(member), | 210 'null_setter_name': null_setter_name_for_dictionary_member(member), |
| 204 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 211 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
| 205 'setter_name': setter_name_for_dictionary_member(member), | 212 'setter_name': setter_name_for_dictionary_member(member), |
| 206 } | 213 } |
| OLD | NEW |