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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 return None, 'v8::Null(isolate)' | 92 return None, 'v8::Null(isolate)' |
93 cpp_default_value = unwrapped_idl_type.literal_cpp_value( | 93 cpp_default_value = unwrapped_idl_type.literal_cpp_value( |
94 member.default_value) | 94 member.default_value) |
95 v8_default_value = unwrapped_idl_type.cpp_value_to_v8_value( | 95 v8_default_value = unwrapped_idl_type.cpp_value_to_v8_value( |
96 cpp_value=cpp_default_value, isolate='isolate', | 96 cpp_value=cpp_default_value, isolate='isolate', |
97 creation_context='creationContext') | 97 creation_context='creationContext') |
98 return cpp_default_value, v8_default_value | 98 return cpp_default_value, v8_default_value |
99 | 99 |
100 cpp_default_value, v8_default_value = default_values() | 100 cpp_default_value, v8_default_value = default_values() |
101 cpp_name = v8_utilities.cpp_name(member) | 101 cpp_name = v8_utilities.cpp_name(member) |
| 102 is_deprecated_dictionary = unwrapped_idl_type.name == 'Dictionary' |
102 | 103 |
103 return { | 104 return { |
104 'cpp_default_value': cpp_default_value, | 105 'cpp_default_value': cpp_default_value, |
105 'cpp_name': cpp_name, | 106 'cpp_name': cpp_name, |
106 'cpp_type': unwrapped_idl_type.cpp_type, | 107 'cpp_type': unwrapped_idl_type.cpp_type, |
107 'cpp_value_to_v8_value': unwrapped_idl_type.cpp_value_to_v8_value( | 108 'cpp_value_to_v8_value': unwrapped_idl_type.cpp_value_to_v8_value( |
108 cpp_value='impl.%s()' % cpp_name, isolate='isolate', | 109 cpp_value='impl.%s()' % cpp_name, isolate='isolate', |
109 creation_context='creationContext', | 110 creation_context='creationContext', |
110 extended_attributes=extended_attributes), | 111 extended_attributes=extended_attributes), |
111 'deprecate_as': v8_utilities.deprecate_as(member), | 112 'deprecate_as': v8_utilities.deprecate_as(member), |
112 'enum_type': idl_type.enum_type, | 113 'enum_type': idl_type.enum_type, |
113 'enum_values': unwrapped_idl_type.enum_values, | 114 'enum_values': unwrapped_idl_type.enum_values, |
114 'has_method_name': has_method_name_for_dictionary_member(member), | 115 'has_method_name': has_method_name_for_dictionary_member(member), |
115 'idl_type': idl_type.base_type, | 116 'idl_type': idl_type.base_type, |
116 'is_interface_type': idl_type.is_interface_type and not idl_type.is_dict
ionary, | 117 '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, | 118 'is_nullable': idl_type.is_nullable, |
118 'is_object': unwrapped_idl_type.name == 'Object', | 119 'is_object': unwrapped_idl_type.name == 'Object' or is_deprecated_dictio
nary, |
119 'is_required': member.is_required, | 120 'is_required': member.is_required, |
120 'name': member.name, | 121 'name': member.name, |
121 'setter_name': setter_name_for_dictionary_member(member), | 122 'setter_name': setter_name_for_dictionary_member(member), |
122 'null_setter_name': null_setter_name_for_dictionary_member(member), | 123 'null_setter_name': null_setter_name_for_dictionary_member(member), |
123 'v8_default_value': v8_default_value, | 124 'v8_default_value': v8_default_value, |
124 'v8_value_to_local_cpp_value': unwrapped_idl_type.v8_value_to_local_cpp_
value( | 125 'v8_value_to_local_cpp_value': unwrapped_idl_type.v8_value_to_local_cpp_
value( |
125 extended_attributes, member.name + 'Value', | 126 extended_attributes, member.name + 'Value', |
126 member.name, isolate='isolate', use_exception_state=True), | 127 member.name, isolate='isolate', use_exception_state=True), |
127 } | 128 } |
128 | 129 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 def getter_expression(): | 171 def getter_expression(): |
171 if idl_type.impl_should_use_nullable_container: | 172 if idl_type.impl_should_use_nullable_container: |
172 return 'm_%s.get()' % cpp_name | 173 return 'm_%s.get()' % cpp_name |
173 return 'm_%s' % cpp_name | 174 return 'm_%s' % cpp_name |
174 | 175 |
175 def has_method_expression(): | 176 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: | 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: |
177 return '!m_%s.isNull()' % cpp_name | 178 return '!m_%s.isNull()' % cpp_name |
178 elif idl_type.name in ['Any', 'Object']: | 179 elif idl_type.name in ['Any', 'Object']: |
179 return '!(m_{0}.isEmpty() || m_{0}.isNull() || m_{0}.isUndefined())'
.format(cpp_name) | 180 return '!(m_{0}.isEmpty() || m_{0}.isNull() || m_{0}.isUndefined())'
.format(cpp_name) |
| 181 elif idl_type.name == 'Dictionary': |
| 182 return '!m_%s.isUndefinedOrNull()' % cpp_name |
180 else: | 183 else: |
181 return 'm_%s' % cpp_name | 184 return 'm_%s' % cpp_name |
182 | 185 |
183 def member_cpp_type(): | 186 def member_cpp_type(): |
184 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) | 187 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) |
185 if idl_type.impl_should_use_nullable_container: | 188 if idl_type.impl_should_use_nullable_container: |
186 return v8_types.cpp_template_type('Nullable', member_cpp_type) | 189 return v8_types.cpp_template_type('Nullable', member_cpp_type) |
187 return member_cpp_type | 190 return member_cpp_type |
188 | 191 |
189 cpp_default_value = None | 192 cpp_default_value = None |
190 if member.default_value and not member.default_value.is_null: | 193 if member.default_value and not member.default_value.is_null: |
191 cpp_default_value = idl_type.literal_cpp_value(member.default_value) | 194 cpp_default_value = idl_type.literal_cpp_value(member.default_value) |
192 | 195 |
193 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) | 196 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) |
194 return { | 197 return { |
195 'cpp_default_value': cpp_default_value, | 198 'cpp_default_value': cpp_default_value, |
196 'cpp_name': cpp_name, | 199 'cpp_name': cpp_name, |
197 'getter_expression': getter_expression(), | 200 'getter_expression': getter_expression(), |
198 'has_method_expression': has_method_expression(), | 201 'has_method_expression': has_method_expression(), |
199 'has_method_name': has_method_name_for_dictionary_member(member), | 202 'has_method_name': has_method_name_for_dictionary_member(member), |
200 'is_nullable': idl_type.is_nullable, | 203 'is_nullable': idl_type.is_nullable, |
201 'is_traceable': idl_type.is_traceable, | 204 'is_traceable': idl_type.is_traceable, |
202 'member_cpp_type': member_cpp_type(), | 205 'member_cpp_type': member_cpp_type(), |
203 'null_setter_name': null_setter_name_for_dictionary_member(member), | 206 'null_setter_name': null_setter_name_for_dictionary_member(member), |
204 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 207 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
205 'setter_name': setter_name_for_dictionary_member(member), | 208 'setter_name': setter_name_for_dictionary_member(member), |
206 } | 209 } |
OLD | NEW |