OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 # Getter | 134 # Getter |
135 | 135 |
136 def generate_getter(interface, attribute, contents): | 136 def generate_getter(interface, attribute, contents): |
137 idl_type = attribute.idl_type | 137 idl_type = attribute.idl_type |
138 extended_attributes = attribute.extended_attributes | 138 extended_attributes = attribute.extended_attributes |
139 | 139 |
140 cpp_value = getter_expression(interface, attribute, contents) | 140 cpp_value = getter_expression(interface, attribute, contents) |
141 # Normally we can inline the function call into the return statement to | 141 # Normally we can inline the function call into the return statement to |
142 # avoid the overhead of using a Ref<> temporary, but for some cases | 142 # avoid the overhead of using a Ref<> temporary, but for some cases |
143 # (nullable types, EventHandler, [CachedAttribute], or if there are | 143 # (nullable types, [RaisesException], [CachedAttribute], and EventHandler) |
144 # exceptions), we need to use a local variable. | 144 # we need to use a local variable. |
145 # FIXME: check if compilers are smart enough to inline this, and if so, | 145 # FIXME: check if compilers are smart enough to inline this, and if so, |
146 # always use a local variable (for readability and CG simplicity). | 146 # always use a local variable (for readability and CG simplicity). |
147 if (attribute.is_nullable or | 147 if idl_type == 'EventHandler': |
148 idl_type == 'EventHandler' or | |
149 'CachedAttribute' in extended_attributes or | |
150 contents['is_getter_raises_exception']): | |
151 contents['cpp_value_original'] = cpp_value | 148 contents['cpp_value_original'] = cpp_value |
152 cpp_value = 'jsValue' | 149 cpp_rvalue = cpp_value = 'jsValue' |
| 150 elif (attribute.is_nullable or |
| 151 contents['is_getter_raises_exception'] or |
| 152 'CachedAttribute' in extended_attributes): |
| 153 contents['cpp_value_original'] = cpp_value |
| 154 cpp_rvalue = cpp_value = 'jsValue' |
| 155 if v8_types.is_interface_type(idl_type): |
| 156 cpp_rvalue += '.release()' |
| 157 else: |
| 158 cpp_rvalue = cpp_value |
153 | 159 |
154 if contents['is_keep_alive_for_gc']: | 160 if contents['is_keep_alive_for_gc']: |
155 v8_set_return_value_statement = 'v8SetReturnValue(info, wrapper)' | 161 v8_set_return_value_statement = 'v8SetReturnValue(info, wrapper)' |
156 includes.add('bindings/v8/V8HiddenPropertyName.h') | 162 includes.add('bindings/v8/V8HiddenPropertyName.h') |
157 else: | 163 else: |
158 v8_set_return_value_statement = v8_types.v8_set_return_value(idl_type, c
pp_value, extended_attributes=extended_attributes, script_wrappable='imp') | 164 v8_set_return_value_statement = v8_types.v8_set_return_value(idl_type, c
pp_rvalue, extended_attributes=extended_attributes, script_wrappable='imp') |
159 | 165 |
160 contents.update({ | 166 contents.update({ |
161 'cpp_value': cpp_value, | 167 'cpp_value': cpp_value, |
162 'v8_set_return_value': v8_set_return_value_statement, | 168 'v8_set_return_value': v8_set_return_value_statement, |
163 }) | 169 }) |
164 | 170 |
165 | 171 |
166 def getter_expression(interface, attribute, contents): | 172 def getter_expression(interface, attribute, contents): |
167 arguments = [] | 173 arguments = [] |
168 this_getter_base_name = getter_base_name(attribute, arguments) | 174 this_getter_base_name = getter_base_name(attribute, arguments) |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 property_attributes_list.append('v8::DontEnum') | 328 property_attributes_list.append('v8::DontEnum') |
323 if 'Unforgeable' in extended_attributes: | 329 if 'Unforgeable' in extended_attributes: |
324 property_attributes_list.append('v8::DontDelete') | 330 property_attributes_list.append('v8::DontDelete') |
325 return property_attributes_list or ['v8::None'] | 331 return property_attributes_list or ['v8::None'] |
326 | 332 |
327 | 333 |
328 # Constructors | 334 # Constructors |
329 | 335 |
330 def is_constructor_attribute(attribute): | 336 def is_constructor_attribute(attribute): |
331 return attribute.idl_type.endswith('Constructor') | 337 return attribute.idl_type.endswith('Constructor') |
OLD | NEW |