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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 'number_of_required_arguments': len([ | 117 'number_of_required_arguments': len([ |
118 argument for argument in arguments | 118 argument for argument in arguments |
119 if not (argument.is_optional or argument.is_variadic)]), | 119 if not (argument.is_optional or argument.is_variadic)]), |
120 'number_of_required_or_variadic_arguments': len([ | 120 'number_of_required_or_variadic_arguments': len([ |
121 argument for argument in arguments | 121 argument for argument in arguments |
122 if not argument.is_optional]), | 122 if not argument.is_optional]), |
123 'per_context_enabled_function': v8_utilities.per_context_enabled_functio
n_name(method), # [PerContextEnabled] | 123 'per_context_enabled_function': v8_utilities.per_context_enabled_functio
n_name(method), # [PerContextEnabled] |
124 'property_attributes': property_attributes(method), | 124 'property_attributes': property_attributes(method), |
125 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m
ethod), # [RuntimeEnabled] | 125 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m
ethod), # [RuntimeEnabled] |
126 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig
nature' in extended_attributes else 'defaultSignature', | 126 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig
nature' in extended_attributes else 'defaultSignature', |
127 'v8_set_return_value': v8_set_return_value(method, this_cpp_value), | 127 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
128 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings] | 128 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings] |
129 } | 129 } |
130 return contents | 130 return contents |
131 | 131 |
132 | 132 |
133 def generate_argument(interface, method, argument, index): | 133 def generate_argument(interface, method, argument, index): |
134 extended_attributes = argument.extended_attributes | 134 extended_attributes = argument.extended_attributes |
135 idl_type = argument.idl_type | 135 idl_type = argument.idl_type |
136 this_cpp_value = cpp_value(interface, method, index) | 136 this_cpp_value = cpp_value(interface, method, index) |
137 return { | 137 return { |
138 'cpp_type': v8_types.cpp_type(idl_type), | 138 'cpp_type': v8_types.cpp_type(idl_type), |
139 'cpp_value': this_cpp_value, | 139 'cpp_value': this_cpp_value, |
140 'enum_validation_expression': v8_utilities.enum_validation_expression(id
l_type), | 140 'enum_validation_expression': v8_utilities.enum_validation_expression(id
l_type), |
141 'has_default': 'Default' in extended_attributes, | 141 'has_default': 'Default' in extended_attributes, |
142 'idl_type': idl_type, | 142 'idl_type': idl_type, |
143 'index': index, | 143 'index': index, |
144 'is_clamp': 'Clamp' in extended_attributes, | 144 'is_clamp': 'Clamp' in extended_attributes, |
145 'is_callback_interface': v8_types.is_callback_interface(idl_type), | 145 'is_callback_interface': v8_types.is_callback_interface(idl_type), |
146 'is_nullable': argument.is_nullable, | 146 'is_nullable': argument.is_nullable, |
147 'is_optional': argument.is_optional, | 147 'is_optional': argument.is_optional, |
148 'is_strict_type_checking': 'StrictTypeChecking' in extended_attributes, | 148 'is_strict_type_checking': 'StrictTypeChecking' in extended_attributes, |
149 'is_variadic_wrapper_type': argument.is_variadic and v8_types.is_wrapper
_type(idl_type), | 149 'is_variadic_wrapper_type': argument.is_variadic and v8_types.is_wrapper
_type(idl_type), |
150 'is_wrapper_type': v8_types.is_wrapper_type(idl_type), | 150 'is_wrapper_type': v8_types.is_wrapper_type(idl_type), |
151 'name': argument.name, | 151 'name': argument.name, |
152 'v8_set_return_value': v8_set_return_value(method, this_cpp_value), | 152 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
153 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex), | 153 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex), |
154 } | 154 } |
155 | 155 |
156 | 156 |
157 def cpp_value(interface, method, number_of_arguments): | 157 def cpp_value(interface, method, number_of_arguments): |
158 def cpp_argument(argument): | 158 def cpp_argument(argument): |
159 idl_type = argument.idl_type | 159 idl_type = argument.idl_type |
160 if (v8_types.is_callback_interface(idl_type) or | 160 if (v8_types.is_callback_interface(idl_type) or |
161 idl_type in ['NodeFilter', 'XPathNSResolver']): | 161 idl_type in ['NodeFilter', 'XPathNSResolver']): |
162 # FIXME: remove this special case | 162 # FIXME: remove this special case |
163 return '%s.release()' % argument.name | 163 return '%s.release()' % argument.name |
164 return argument.name | 164 return argument.name |
165 | 165 |
166 # Truncate omitted optional arguments | 166 # Truncate omitted optional arguments |
167 arguments = method.arguments[:number_of_arguments] | 167 arguments = method.arguments[:number_of_arguments] |
168 cpp_arguments = v8_utilities.call_with_arguments(method) | 168 cpp_arguments = v8_utilities.call_with_arguments(method) |
169 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) | 169 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) |
170 if 'RaisesException' in method.extended_attributes: | 170 if 'RaisesException' in method.extended_attributes: |
171 cpp_arguments.append('exceptionState') | 171 cpp_arguments.append('exceptionState') |
172 | 172 |
173 cpp_method_name = v8_utilities.scoped_name(interface, method, v8_utilities.c
pp_name(method)) | 173 cpp_method_name = v8_utilities.scoped_name(interface, method, v8_utilities.c
pp_name(method)) |
174 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) | 174 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) |
175 | 175 |
176 | 176 |
177 def v8_set_return_value(method, cpp_value): | 177 def v8_set_return_value(interface_name, method, cpp_value): |
178 idl_type = method.idl_type | 178 idl_type = method.idl_type |
179 if idl_type == 'void': | 179 if idl_type == 'void': |
180 return None | 180 return None |
181 # [CallWith=ScriptState] | 181 # [CallWith=ScriptState] |
182 if has_extended_attribute_value(method, 'CallWith', 'ScriptState'): | 182 if has_extended_attribute_value(method, 'CallWith', 'ScriptState'): |
183 cpp_value = 'result' # use local variable for value | 183 cpp_value = 'result' # use local variable for value |
184 return v8_types.v8_set_return_value(idl_type, cpp_value, method.extended_att
ributes) | 184 script_wrappable = 'imp' if v8_types.inherits_interface(interface_name, 'Nod
e') else '' |
| 185 return v8_types.v8_set_return_value(idl_type, cpp_value, method.extended_att
ributes, script_wrappable=script_wrappable) |
185 | 186 |
186 | 187 |
187 # [NotEnumerable] | 188 # [NotEnumerable] |
188 def property_attributes(method): | 189 def property_attributes(method): |
189 extended_attributes = method.extended_attributes | 190 extended_attributes = method.extended_attributes |
190 property_attributes_list = [] | 191 property_attributes_list = [] |
191 if 'NotEnumerable' in extended_attributes: | 192 if 'NotEnumerable' in extended_attributes: |
192 property_attributes_list.append('v8::DontEnum') | 193 property_attributes_list.append('v8::DontEnum') |
193 if 'ReadOnly' in extended_attributes: | 194 if 'ReadOnly' in extended_attributes: |
194 property_attributes_list.append('v8::ReadOnly') | 195 property_attributes_list.append('v8::ReadOnly') |
(...skipping 10 matching lines...) Expand all Loading... |
205 return 'V8TRYCATCH_VOID(Vector<{cpp_type}>, {name}, toNativeArguments<{c
pp_type}>(info, {index}))'.format( | 206 return 'V8TRYCATCH_VOID(Vector<{cpp_type}>, {name}, toNativeArguments<{c
pp_type}>(info, {index}))'.format( |
206 cpp_type=v8_types.cpp_type(idl_type), name=name, index=index) | 207 cpp_type=v8_types.cpp_type(idl_type), name=name, index=index) |
207 # [Default=NullString] | 208 # [Default=NullString] |
208 if (argument.is_optional and idl_type == 'DOMString' and | 209 if (argument.is_optional and idl_type == 'DOMString' and |
209 extended_attributes.get('Default') == 'NullString'): | 210 extended_attributes.get('Default') == 'NullString'): |
210 v8_value = 'argumentOrNull(info, %s)' % index | 211 v8_value = 'argumentOrNull(info, %s)' % index |
211 else: | 212 else: |
212 v8_value = 'info[%s]' % index | 213 v8_value = 'info[%s]' % index |
213 return v8_types.v8_value_to_local_cpp_value( | 214 return v8_types.v8_value_to_local_cpp_value( |
214 idl_type, argument.extended_attributes, v8_value, name, index=index) | 215 idl_type, argument.extended_attributes, v8_value, name, index=index) |
OLD | NEW |