| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 for method in methods: | 253 for method in methods: |
| 254 method['do_generate_method_configuration'] = ( | 254 if 'overloads' in method: |
| 255 method['do_not_check_signature'] and | 255 overloads = method['overloads'] |
| 256 not method['per_context_enabled_function'] and | 256 method['do_generate_method_configuration'] = ( |
| 257 # For overloaded methods, only generate one accessor | 257 overloads['do_not_check_signature_all'] and |
| 258 ('overload_index' not in method or method['overload_index'] == 1)) | 258 not overloads['per_context_enabled_function_all']) |
| 259 else: |
| 260 method['do_generate_method_configuration'] = ( |
| 261 method['do_not_check_signature'] and |
| 262 not method['per_context_enabled_function'] and |
| 263 # Ignore any overload not handled by the case above |
| 264 'overload_index' not in method) |
| 259 | 265 |
| 260 template_contents.update({ | 266 template_contents.update({ |
| 261 'has_origin_safe_method_setter': any( | 267 'has_origin_safe_method_setter': any( |
| 262 method['is_check_security_for_frame'] and not method['is_read_only'] | 268 method['is_check_security_for_frame'] and not method['is_read_only'] |
| 263 for method in methods), | 269 for method in methods), |
| 264 'has_method_configuration': any(method['do_generate_method_configuration
'] for method in methods), | 270 'has_method_configuration': any(method['do_generate_method_configuration
'] for method in methods), |
| 265 'has_per_context_enabled_methods': any(method['per_context_enabled_funct
ion'] for method in methods), | 271 'has_per_context_enabled_methods': any(method['per_context_enabled_funct
ion'] for method in methods), |
| 266 'methods': methods, | 272 'methods': methods, |
| 267 }) | 273 }) |
| 268 | 274 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 """ | 358 """ |
| 353 assert len(overloads) > 1 # only apply to overloaded names | 359 assert len(overloads) > 1 # only apply to overloaded names |
| 354 for index, method in enumerate(overloads, 1): | 360 for index, method in enumerate(overloads, 1): |
| 355 method['overload_index'] = index | 361 method['overload_index'] = index |
| 356 | 362 |
| 357 effective_overloads_by_length = effective_overload_set_by_length(overloads) | 363 effective_overloads_by_length = effective_overload_set_by_length(overloads) |
| 358 lengths = [length for length, _ in effective_overloads_by_length] | 364 lengths = [length for length, _ in effective_overloads_by_length] |
| 359 | 365 |
| 360 return { | 366 return { |
| 361 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca
teAs] | 367 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca
teAs] |
| 368 'do_not_check_signature_all': common_value(overloads, 'do_not_check_sign
ature'), |
| 362 'length_tests_methods': length_tests_methods(effective_overloads_by_leng
th), | 369 'length_tests_methods': length_tests_methods(effective_overloads_by_leng
th), |
| 363 'minarg': lengths[0], | 370 'minarg': lengths[0], |
| 364 # 1. Let maxarg be the length of the longest type list of the | 371 # 1. Let maxarg be the length of the longest type list of the |
| 365 # entries in S. | 372 # entries in S. |
| 366 'maxarg': lengths[-1], | 373 'maxarg': lengths[-1], |
| 367 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] | 374 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] |
| 375 'per_context_enabled_function_all': common_value(overloads, 'per_context
_enabled_function'), # [PerContextEnabled] |
| 376 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled
_function'), # [RuntimeEnabled] |
| 368 'valid_arities': lengths | 377 'valid_arities': lengths |
| 369 # Only need to report valid arities if there is a gap in the | 378 # Only need to report valid arities if there is a gap in the |
| 370 # sequence of possible lengths, otherwise invalid length means | 379 # sequence of possible lengths, otherwise invalid length means |
| 371 # "not enough arguments". | 380 # "not enough arguments". |
| 372 if lengths[-1] - lengths[0] != len(lengths) - 1 else None, | 381 if lengths[-1] - lengths[0] != len(lengths) - 1 else None, |
| 373 } | 382 } |
| 374 | 383 |
| 375 | 384 |
| 376 def effective_overload_set(F): | 385 def effective_overload_set(F): |
| 377 """Returns the effective overload set of an overloaded function. | 386 """Returns the effective overload set of an overloaded function. |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 # • a numeric type | 689 # • a numeric type |
| 681 try: | 690 try: |
| 682 method = next(method for idl_type, method in idl_types_methods | 691 method = next(method for idl_type, method in idl_types_methods |
| 683 if idl_type.is_numeric_type) | 692 if idl_type.is_numeric_type) |
| 684 test = '%s->IsNumber()' % cpp_value | 693 test = '%s->IsNumber()' % cpp_value |
| 685 yield test, method | 694 yield test, method |
| 686 except StopIteration: | 695 except StopIteration: |
| 687 pass | 696 pass |
| 688 | 697 |
| 689 # (Perform automatic type conversion, in order. If any of these match, | 698 # (Perform automatic type conversion, in order. If any of these match, |
| 690 # that’s the end, and no other tests are needed.) | 699 # that’s the end, and no other tests are needed.) To keep this code simple, |
| 700 # we rely on the C++ compiler's dead code elimination to deal with the |
| 701 # redundancy if both cases below trigger. |
| 691 | 702 |
| 692 # 11. Otherwise: if there is an entry in S that has one of the following | 703 # 11. Otherwise: if there is an entry in S that has one of the following |
| 693 # types at position i of its type list, | 704 # types at position i of its type list, |
| 694 # • DOMString | 705 # • DOMString |
| 695 # • an enumeration type | 706 # • an enumeration type |
| 696 try: | 707 try: |
| 697 method = next(method for idl_type, method in idl_types_methods | 708 method = next(method for idl_type, method in idl_types_methods |
| 698 if idl_type.name == 'String' or idl_type.is_enum) | 709 if idl_type.name == 'String' or idl_type.is_enum) |
| 699 yield 'true', method | 710 yield 'true', method |
| 700 return | |
| 701 except StopIteration: | 711 except StopIteration: |
| 702 pass | 712 pass |
| 703 | 713 |
| 704 # 12. Otherwise: if there is an entry in S that has one of the following | 714 # 12. Otherwise: if there is an entry in S that has one of the following |
| 705 # types at position i of its type list, | 715 # types at position i of its type list, |
| 706 # • a numeric type | 716 # • a numeric type |
| 707 try: | 717 try: |
| 708 method = next(method for idl_type, method in idl_types_methods | 718 method = next(method for idl_type, method in idl_types_methods |
| 709 if idl_type.is_numeric_type) | 719 if idl_type.is_numeric_type) |
| 710 yield 'true', method | 720 yield 'true', method |
| 711 return | |
| 712 except StopIteration: | 721 except StopIteration: |
| 713 pass | 722 pass |
| 714 | 723 |
| 715 | 724 |
| 716 ################################################################################ | 725 ################################################################################ |
| 717 # Utility functions | 726 # Utility functions |
| 718 ################################################################################ | 727 ################################################################################ |
| 719 | 728 |
| 720 def Counter(iterable): | 729 def Counter(iterable): |
| 721 # Once using Python 2.7, using collections.Counter | 730 # Once using Python 2.7, using collections.Counter |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 deleter = next( | 1016 deleter = next( |
| 1008 method | 1017 method |
| 1009 for method in interface.operations | 1018 for method in interface.operations |
| 1010 if ('deleter' in method.specials and | 1019 if ('deleter' in method.specials and |
| 1011 len(method.arguments) == 1 and | 1020 len(method.arguments) == 1 and |
| 1012 str(method.arguments[0].idl_type) == 'DOMString')) | 1021 str(method.arguments[0].idl_type) == 'DOMString')) |
| 1013 except StopIteration: | 1022 except StopIteration: |
| 1014 return None | 1023 return None |
| 1015 | 1024 |
| 1016 return property_deleter(deleter) | 1025 return property_deleter(deleter) |
| OLD | NEW |