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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( | 69 parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( |
70 dictionary.parent, interfaces_info) | 70 dictionary.parent, interfaces_info) |
71 context.update({ | 71 context.update({ |
72 'parent_cpp_class': parent_cpp_class, | 72 'parent_cpp_class': parent_cpp_class, |
73 'parent_v8_class': v8_types.v8_type(parent_cpp_class), | 73 'parent_v8_class': v8_types.v8_type(parent_cpp_class), |
74 }) | 74 }) |
75 return context | 75 return context |
76 | 76 |
77 | 77 |
78 def member_context(dictionary, member): | 78 def member_context(dictionary, member): |
| 79 extended_attributes = member.extended_attributes |
79 idl_type = member.idl_type | 80 idl_type = member.idl_type |
80 idl_type.add_includes_for_type() | 81 idl_type.add_includes_for_type(extended_attributes) |
81 unwrapped_idl_type = unwrap_nullable_if_needed(idl_type) | 82 unwrapped_idl_type = unwrap_nullable_if_needed(idl_type) |
82 | 83 |
83 if member.is_required and member.default_value: | 84 if member.is_required and member.default_value: |
84 raise Exception( | 85 raise Exception( |
85 'Required member %s must not have a default value.' % member.name) | 86 'Required member %s must not have a default value.' % member.name) |
86 | 87 |
87 def default_values(): | 88 def default_values(): |
88 if not member.default_value: | 89 if not member.default_value: |
89 return None, None | 90 return None, None |
90 if member.default_value.is_null: | 91 if member.default_value.is_null: |
91 return None, 'v8::Null(isolate)' | 92 return None, 'v8::Null(isolate)' |
92 cpp_default_value = unwrapped_idl_type.literal_cpp_value( | 93 cpp_default_value = unwrapped_idl_type.literal_cpp_value( |
93 member.default_value) | 94 member.default_value) |
94 v8_default_value = unwrapped_idl_type.cpp_value_to_v8_value( | 95 v8_default_value = unwrapped_idl_type.cpp_value_to_v8_value( |
95 cpp_value=cpp_default_value, isolate='isolate', | 96 cpp_value=cpp_default_value, isolate='isolate', |
96 creation_context='creationContext') | 97 creation_context='creationContext') |
97 return cpp_default_value, v8_default_value | 98 return cpp_default_value, v8_default_value |
98 | 99 |
99 cpp_default_value, v8_default_value = default_values() | 100 cpp_default_value, v8_default_value = default_values() |
100 cpp_name = v8_utilities.cpp_name(member) | 101 cpp_name = v8_utilities.cpp_name(member) |
101 | 102 |
102 return { | 103 return { |
103 'cpp_default_value': cpp_default_value, | 104 'cpp_default_value': cpp_default_value, |
104 'cpp_name': cpp_name, | 105 'cpp_name': cpp_name, |
105 'cpp_type': unwrapped_idl_type.cpp_type, | 106 'cpp_type': unwrapped_idl_type.cpp_type, |
106 'cpp_value_to_v8_value': unwrapped_idl_type.cpp_value_to_v8_value( | 107 'cpp_value_to_v8_value': unwrapped_idl_type.cpp_value_to_v8_value( |
107 cpp_value='impl.%s()' % cpp_name, isolate='isolate', | 108 cpp_value='impl.%s()' % cpp_name, isolate='isolate', |
108 creation_context='creationContext', | 109 creation_context='creationContext', |
109 extended_attributes=member.extended_attributes), | 110 extended_attributes=extended_attributes), |
110 'deprecate_as': v8_utilities.deprecate_as(member), | 111 'deprecate_as': v8_utilities.deprecate_as(member), |
111 'enum_type': idl_type.enum_type, | 112 'enum_type': idl_type.enum_type, |
112 'enum_values': unwrapped_idl_type.enum_values, | 113 'enum_values': unwrapped_idl_type.enum_values, |
113 'has_method_name': has_method_name_for_dictionary_member(member), | 114 'has_method_name': has_method_name_for_dictionary_member(member), |
114 'idl_type': idl_type.base_type, | 115 'idl_type': idl_type.base_type, |
115 'is_interface_type': idl_type.is_interface_type and not idl_type.is_dict
ionary, | 116 'is_interface_type': idl_type.is_interface_type and not idl_type.is_dict
ionary, |
116 'is_nullable': idl_type.is_nullable, | 117 'is_nullable': idl_type.is_nullable, |
117 'is_object': unwrapped_idl_type.name == 'Object', | 118 'is_object': unwrapped_idl_type.name == 'Object', |
118 'is_required': member.is_required, | 119 'is_required': member.is_required, |
119 'name': member.name, | 120 'name': member.name, |
120 'setter_name': setter_name_for_dictionary_member(member), | 121 'setter_name': setter_name_for_dictionary_member(member), |
121 'null_setter_name': null_setter_name_for_dictionary_member(member), | 122 'null_setter_name': null_setter_name_for_dictionary_member(member), |
122 'v8_default_value': v8_default_value, | 123 'v8_default_value': v8_default_value, |
123 'v8_value_to_local_cpp_value': unwrapped_idl_type.v8_value_to_local_cpp_
value( | 124 'v8_value_to_local_cpp_value': unwrapped_idl_type.v8_value_to_local_cpp_
value( |
124 member.extended_attributes, member.name + 'Value', | 125 extended_attributes, member.name + 'Value', |
125 member.name, isolate='isolate', use_exception_state=True), | 126 member.name, isolate='isolate', use_exception_state=True), |
126 } | 127 } |
127 | 128 |
128 | 129 |
129 # Context for implementation classes | 130 # Context for implementation classes |
130 | 131 |
131 def dictionary_impl_context(dictionary, interfaces_info): | 132 def dictionary_impl_context(dictionary, interfaces_info): |
132 def remove_duplicate_members(members): | 133 def remove_duplicate_members(members): |
133 # When [ImplementedAs] is used, cpp_name can conflict. For example, | 134 # When [ImplementedAs] is used, cpp_name can conflict. For example, |
134 # dictionary D { long foo; [ImplementedAs=foo, DeprecateAs=Foo] long old
Foo; }; | 135 # dictionary D { long foo; [ImplementedAs=foo, DeprecateAs=Foo] long old
Foo; }; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 'getter_expression': getter_expression(), | 198 'getter_expression': getter_expression(), |
198 'has_method_expression': has_method_expression(), | 199 'has_method_expression': has_method_expression(), |
199 'has_method_name': has_method_name_for_dictionary_member(member), | 200 'has_method_name': has_method_name_for_dictionary_member(member), |
200 'is_object': is_object, | 201 'is_object': is_object, |
201 'is_traceable': idl_type.is_traceable, | 202 'is_traceable': idl_type.is_traceable, |
202 'member_cpp_type': member_cpp_type(), | 203 'member_cpp_type': member_cpp_type(), |
203 'null_setter_name': null_setter_name_for_dictionary_member(member), | 204 'null_setter_name': null_setter_name_for_dictionary_member(member), |
204 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 205 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
205 'setter_name': setter_name_for_dictionary_member(member), | 206 'setter_name': setter_name_for_dictionary_member(member), |
206 } | 207 } |
OLD | NEW |