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 copy | 9 import copy |
10 import operator | 10 import operator |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 | 72 |
73 cpp_default_value, v8_default_value = default_values() | 73 cpp_default_value, v8_default_value = default_values() |
74 | 74 |
75 return { | 75 return { |
76 'cpp_default_value': cpp_default_value, | 76 'cpp_default_value': cpp_default_value, |
77 'cpp_type': idl_type.cpp_type, | 77 'cpp_type': idl_type.cpp_type, |
78 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 78 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
79 cpp_value='impl->%s()' % member.name, isolate='isolate', | 79 cpp_value='impl->%s()' % member.name, isolate='isolate', |
80 creation_context='creationContext', | 80 creation_context='creationContext', |
81 extended_attributes=member.extended_attributes), | 81 extended_attributes=member.extended_attributes), |
82 'has_name': has_name_for_dictionary_member(member), | 82 'has_name': has_name_for_dictionary_member(member), |
haraken
2014/07/27 07:46:35
has_name => has_method_name
has_name_for_dictionar
bashi
2014/07/29 03:52:50
Done.
| |
83 'name': member.name, | 83 'name': member.name, |
84 'setter_name': setter_name_for_dictionary_member(member), | 84 'setter_name': setter_name_for_dictionary_member(member), |
85 'v8_default_value': v8_default_value, | 85 'v8_default_value': v8_default_value, |
86 'v8_type': v8_types.v8_type(idl_type.base_type), | 86 'v8_type': v8_types.v8_type(idl_type.base_type), |
87 } | 87 } |
88 | 88 |
89 # FIXME: Implement context for impl class. | 89 |
90 # Context for implementation classes | |
91 | |
92 def dictionary_impl_context(dictionary, interfaces_info): | |
93 includes.clear() | |
94 header_includes = set(['platform/heap/Handle.h']) | |
95 return { | |
96 'header_includes': header_includes, | |
97 'cpp_class': v8_utilities.cpp_name(dictionary), | |
98 'members': [member_impl_context(member, interfaces_info, | |
99 header_includes) | |
100 for member in dictionary.members], | |
101 } | |
102 | |
103 | |
104 def member_impl_context(member, interfaces_info, header_includes): | |
105 idl_type = member.idl_type | |
106 | |
107 def should_use_nullable_container(): | |
haraken
2014/07/27 07:46:35
Can we use is_implicit_nullable/is_explicit_nullab
bashi
2014/07/29 03:52:50
It seems that we can't use is_implicit_nullable/is
| |
108 return idl_type.native_array_element_type or idl_type.is_primitive_type | |
109 | |
110 def collect_includes(idl_type): | |
haraken
2014/07/27 07:46:35
Can we move this method to v8_types.py?
Similarly
bashi
2014/07/29 03:52:50
Done.
| |
111 includes_for_type = set() | |
112 if should_use_nullable_container(): | |
113 includes_for_type.add('bindings/core/v8/Nullable.h') | |
114 | |
115 idl_type = idl_type.preprocessed_type | |
116 native_array_element_type = idl_type.native_array_element_type | |
117 if native_array_element_type: | |
118 includes_for_type.update(collect_includes( | |
119 native_array_element_type)) | |
120 includes_for_type.add('wtf/Vector.h') | |
121 | |
122 if idl_type.is_string_type: | |
123 includes_for_type.add('wtf/text/WTFString.h') | |
124 if idl_type.name in interfaces_info: | |
125 interface_info = interfaces_info[idl_type.name] | |
126 includes_for_type.add(interface_info['include_path']) | |
127 return includes_for_type | |
128 | |
129 def argument_cpp_type(): | |
130 argument_cpp_type = idl_type.cpp_type_args(used_as_argument=True) | |
131 if idl_type.native_array_element_type: | |
132 return 'const %s&' % argument_cpp_type | |
133 return argument_cpp_type | |
134 | |
135 def getter_cpp_type(): | |
136 getter_cpp_type = idl_type.cpp_type_args(used_as_return_type=True) | |
137 if (idl_type.native_array_element_type or idl_type.is_string_type): | |
138 return 'const %s&' % getter_cpp_type | |
139 return getter_cpp_type | |
140 | |
141 def getter_method_expression(): | |
142 if should_use_nullable_container(): | |
143 return 'm_%s.get()' % member.name | |
144 return 'm_%s' % member.name | |
145 | |
146 def has_method_expression(): | |
147 if should_use_nullable_container() or idl_type.is_string_type: | |
148 return '!m_%s.isNull()' % member.name | |
haraken
2014/07/27 07:46:35
I think we should share this code with property_ge
bashi
2014/07/29 03:52:51
Hmm, the semantics of Nullable usage are different
haraken
2014/07/29 11:09:19
Thanks for the clarification, makes sense!
| |
149 else: | |
150 return 'm_%s' % member.name | |
151 | |
152 def member_cpp_type(): | |
153 member_cpp_type = idl_type.cpp_type_args(used_as_member=True) | |
154 if should_use_nullable_container(): | |
155 return v8_types.cpp_template_type('Nullable', member_cpp_type) | |
haraken
2014/07/27 07:46:35
Ditto. We can share this code with v8_method.py.
bashi
2014/07/29 03:52:51
I put these functions in this file because these a
| |
156 return member_cpp_type | |
157 | |
158 header_includes.update(collect_includes(idl_type)) | |
159 return { | |
160 'argument_cpp_type': argument_cpp_type(), | |
161 'getter_cpp_type': getter_cpp_type(), | |
162 'getter_method_expression': getter_method_expression(), | |
163 'has_method_expression': has_method_expression(), | |
164 'has_name': has_name_for_dictionary_member(member), | |
165 'is_traceable': (idl_type.is_garbage_collected or | |
166 idl_type.is_will_be_garbage_collected), | |
167 'member_cpp_type': member_cpp_type(), | |
168 'name': member.name, | |
169 'setter_name': setter_name_for_dictionary_member(member), | |
170 } | |
OLD | NEW |