OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # coding=utf-8 | 2 # coding=utf-8 |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 'has_constructor_attributes': any(attribute['constructor_type'] for attr
ibute in attributes), | 243 'has_constructor_attributes': any(attribute['constructor_type'] for attr
ibute in attributes), |
244 'has_per_context_enabled_attributes': any(attribute['per_context_enabled
_function'] for attribute in attributes), | 244 'has_per_context_enabled_attributes': any(attribute['per_context_enabled
_function'] for attribute in attributes), |
245 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib
ute in attributes), | 245 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib
ute in attributes), |
246 }) | 246 }) |
247 | 247 |
248 # Methods | 248 # Methods |
249 methods = [v8_methods.generate_method(interface, method) | 249 methods = [v8_methods.generate_method(interface, method) |
250 for method in interface.operations | 250 for method in interface.operations |
251 if method.name] # Skip anonymous special operations (methods) | 251 if method.name] # Skip anonymous special operations (methods) |
252 generate_method_overloads(methods) | 252 generate_method_overloads(methods) |
| 253 |
| 254 per_context_enabled_methods = [] |
| 255 custom_registration_methods = [] |
| 256 method_configuration_methods = [] |
| 257 |
253 for method in methods: | 258 for method in methods: |
254 method['do_generate_method_configuration'] = ( | 259 # Skip all but one method in each set of overloaded methods. |
255 method['do_not_check_signature'] and | 260 if 'overload_index' in method and 'overloads' not in method: |
256 not method['per_context_enabled_function'] and | 261 continue |
257 # For overloaded methods, only generate one accessor | |
258 ('overload_index' not in method or method['overload_index'] == 1)) | |
259 | 262 |
| 263 if 'overloads' in method: |
| 264 overloads = method['overloads'] |
| 265 per_context_enabled_function = overloads['per_context_enabled_functi
on_all'] |
| 266 runtime_enabled_function = overloads['runtime_enabled_function_all'] |
| 267 needs_custom_registration = overloads['needs_custom_registration_all
'] |
| 268 else: |
| 269 per_context_enabled_function = method['per_context_enabled_function'
] |
| 270 runtime_enabled_function = method['runtime_enabled_function'] |
| 271 needs_custom_registration = method['needs_custom_registration'] |
| 272 |
| 273 if per_context_enabled_function: |
| 274 per_context_enabled_methods.append(method) |
| 275 continue |
| 276 if runtime_enabled_function or needs_custom_registration: |
| 277 custom_registration_methods.append(method) |
| 278 continue |
| 279 method_configuration_methods.append(method) |
| 280 |
| 281 for method in methods: |
260 # The value of the Function object’s “length” property is a Number | 282 # The value of the Function object’s “length” property is a Number |
261 # determined as follows: | 283 # determined as follows: |
262 # 1. Let S be the effective overload set for regular operations (if the | 284 # 1. Let S be the effective overload set for regular operations (if the |
263 # operation is a regular operation) or for static operations (if the | 285 # operation is a regular operation) or for static operations (if the |
264 # operation is a static operation) with identifier id on interface I and | 286 # operation is a static operation) with identifier id on interface I and |
265 # with argument count 0. | 287 # with argument count 0. |
266 # 2. Return the length of the shortest argument list of the entries in S
. | 288 # 2. Return the length of the shortest argument list of the entries in S
. |
267 # FIXME: This calculation doesn't take into account whether runtime | 289 # FIXME: This calculation doesn't take into account whether runtime |
268 # enabled overloads are actually enabled, so length may be incorrect. | 290 # enabled overloads are actually enabled, so length may be incorrect. |
269 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); | 291 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); |
270 # should have length 1 if Foo is not enabled, but length 0 if it is. | 292 # should have length 1 if Foo is not enabled, but length 0 if it is. |
271 method['length'] = (method['overloads']['minarg'] if 'overloads' in meth
od else | 293 method['length'] = (method['overloads']['minarg'] if 'overloads' in meth
od else |
272 method['number_of_required_arguments']) | 294 method['number_of_required_arguments']) |
273 | 295 |
274 template_contents.update({ | 296 template_contents.update({ |
| 297 'custom_registration_methods': custom_registration_methods, |
275 'has_origin_safe_method_setter': any( | 298 'has_origin_safe_method_setter': any( |
276 method['is_check_security_for_frame'] and not method['is_read_only'] | 299 method['is_check_security_for_frame'] and not method['is_read_only'] |
277 for method in methods), | 300 for method in methods), |
278 'has_method_configuration': any(method['do_generate_method_configuration
'] for method in methods), | 301 'method_configuration_methods': method_configuration_methods, |
279 'has_per_context_enabled_methods': any(method['per_context_enabled_funct
ion'] for method in methods), | 302 'per_context_enabled_methods': per_context_enabled_methods, |
280 'methods': methods, | 303 'methods': methods, |
281 }) | 304 }) |
282 | 305 |
283 template_contents.update({ | 306 template_contents.update({ |
284 'indexed_property_getter': indexed_property_getter(interface), | 307 'indexed_property_getter': indexed_property_getter(interface), |
285 'indexed_property_setter': indexed_property_setter(interface), | 308 'indexed_property_setter': indexed_property_setter(interface), |
286 'indexed_property_deleter': indexed_property_deleter(interface), | 309 'indexed_property_deleter': indexed_property_deleter(interface), |
287 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, | 310 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, |
288 'named_property_getter': named_property_getter(interface), | 311 'named_property_getter': named_property_getter(interface), |
289 'named_property_setter': named_property_setter(interface), | 312 'named_property_setter': named_property_setter(interface), |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 raise ValueError('Function.length of %s depends on runtime enabled featu
res' % overloads[0]['name']) | 407 raise ValueError('Function.length of %s depends on runtime enabled featu
res' % overloads[0]['name']) |
385 | 408 |
386 return { | 409 return { |
387 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca
teAs] | 410 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca
teAs] |
388 'length_tests_methods': length_tests_methods(effective_overloads_by_leng
th), | 411 'length_tests_methods': length_tests_methods(effective_overloads_by_leng
th), |
389 'minarg': lengths[0], | 412 'minarg': lengths[0], |
390 # 1. Let maxarg be the length of the longest type list of the | 413 # 1. Let maxarg be the length of the longest type list of the |
391 # entries in S. | 414 # entries in S. |
392 'maxarg': lengths[-1], | 415 'maxarg': lengths[-1], |
393 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] | 416 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] |
| 417 'needs_custom_registration_all': common_value(overloads, 'needs_custom_r
egistration'), |
| 418 'per_context_enabled_function_all': common_value(overloads, 'per_context
_enabled_function'), # [PerContextEnabled] |
| 419 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled
_function'), # [RuntimeEnabled] |
394 'valid_arities': lengths | 420 'valid_arities': lengths |
395 # Only need to report valid arities if there is a gap in the | 421 # Only need to report valid arities if there is a gap in the |
396 # sequence of possible lengths, otherwise invalid length means | 422 # sequence of possible lengths, otherwise invalid length means |
397 # "not enough arguments". | 423 # "not enough arguments". |
398 if lengths[-1] - lengths[0] != len(lengths) - 1 else None, | 424 if lengths[-1] - lengths[0] != len(lengths) - 1 else None, |
399 } | 425 } |
400 | 426 |
401 | 427 |
402 def effective_overload_set(F): | 428 def effective_overload_set(F): |
403 """Returns the effective overload set of an overloaded function. | 429 """Returns the effective overload set of an overloaded function. |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 deleter = next( | 1059 deleter = next( |
1034 method | 1060 method |
1035 for method in interface.operations | 1061 for method in interface.operations |
1036 if ('deleter' in method.specials and | 1062 if ('deleter' in method.specials and |
1037 len(method.arguments) == 1 and | 1063 len(method.arguments) == 1 and |
1038 str(method.arguments[0].idl_type) == 'DOMString')) | 1064 str(method.arguments[0].idl_type) == 'DOMString')) |
1039 except StopIteration: | 1065 except StopIteration: |
1040 return None | 1066 return None |
1041 | 1067 |
1042 return property_deleter(deleter) | 1068 return property_deleter(deleter) |
OLD | NEW |