Chromium Code Reviews| 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 | 446 |
| 447 | 447 |
| 448 ################################################################################ | 448 ################################################################################ |
| 449 # Constructors | 449 # Constructors |
| 450 ################################################################################ | 450 ################################################################################ |
| 451 | 451 |
| 452 # [Constructor] | 452 # [Constructor] |
| 453 def generate_constructor(interface, constructor): | 453 def generate_constructor(interface, constructor): |
| 454 return { | 454 return { |
| 455 'argument_list': constructor_argument_list(interface, constructor), | 455 'argument_list': constructor_argument_list(interface, constructor), |
| 456 'arguments': [constructor_argument(argument, index) | 456 'arguments': [constructor_argument(interface, constructor, argument, ind ex) |
| 457 for index, argument in enumerate(constructor.arguments)], | 457 for index, argument in enumerate(constructor.arguments)], |
| 458 'has_exception_state': | 458 'has_exception_state': |
| 459 # [RaisesException=Constructor] | 459 # [RaisesException=Constructor] |
| 460 interface.extended_attributes.get('RaisesException') == 'Constructor ' or | 460 interface.extended_attributes.get('RaisesException') == 'Constructor ' or |
| 461 any(argument for argument in constructor.arguments | 461 any(argument for argument in constructor.arguments |
| 462 if argument.idl_type.name == 'SerializedScriptValue' or | 462 if argument.idl_type.name == 'SerializedScriptValue' or |
| 463 argument.idl_type.is_integer_type), | 463 argument.idl_type.is_integer_type), |
| 464 'is_constructor': True, | 464 'is_constructor': True, |
| 465 'is_named_constructor': False, | |
| 465 'is_variadic': False, # Required for overload resolution | 466 'is_variadic': False, # Required for overload resolution |
| 466 'number_of_required_arguments': | 467 'number_of_required_arguments': |
| 467 number_of_required_arguments(constructor), | 468 number_of_required_arguments(constructor), |
| 468 } | 469 } |
| 469 | 470 |
| 470 | 471 |
| 471 def constructor_argument_list(interface, constructor): | 472 def constructor_argument_list(interface, constructor): |
| 472 arguments = [] | 473 arguments = [] |
| 473 # [ConstructorCallWith=ExecutionContext] | 474 # [ConstructorCallWith=ExecutionContext] |
| 474 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Execution Context'): | 475 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Execution Context'): |
| 475 arguments.append('context') | 476 arguments.append('context') |
| 476 # [ConstructorCallWith=Document] | 477 # [ConstructorCallWith=Document] |
| 477 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document' ): | 478 if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document' ): |
| 478 arguments.append('document') | 479 arguments.append('document') |
| 479 | 480 |
| 480 arguments.extend([argument.name for argument in constructor.arguments]) | 481 arguments.extend([argument.name for argument in constructor.arguments]) |
| 481 | 482 |
| 482 # [RaisesException=Constructor] | 483 # [RaisesException=Constructor] |
| 483 if interface.extended_attributes.get('RaisesException') == 'Constructor': | 484 if interface.extended_attributes.get('RaisesException') == 'Constructor': |
| 484 arguments.append('exceptionState') | 485 arguments.append('exceptionState') |
| 485 | 486 |
| 486 return arguments | 487 return arguments |
| 487 | 488 |
| 488 | 489 |
| 489 def constructor_argument(argument, index): | 490 def constructor_argument(interface, constructor, argument, index): |
| 490 idl_type = argument.idl_type | 491 idl_type = argument.idl_type |
| 491 return { | 492 return { |
| 493 'cpp_value': | |
| 494 v8_methods.cpp_value(interface, constructor, index), | |
| 492 'has_default': 'Default' in argument.extended_attributes, | 495 'has_default': 'Default' in argument.extended_attributes, |
| 493 'idl_type_object': idl_type, | |
| 494 # Dictionary is special-cased, but arrays and sequences shouldn't be | 496 # Dictionary is special-cased, but arrays and sequences shouldn't be |
| 495 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, | 497 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, |
| 498 'idl_type_object': idl_type, | |
| 496 'index': index, | 499 'index': index, |
| 497 'is_optional': argument.is_optional, | 500 'is_optional': argument.is_optional, |
| 498 'is_strict_type_checking': False, # Required for overload resolution | 501 'is_strict_type_checking': False, # Required for overload resolution |
| 499 'name': argument.name, | 502 'name': argument.name, |
| 500 'v8_value_to_local_cpp_value': | 503 'v8_value_to_local_cpp_value': |
| 501 v8_methods.v8_value_to_local_cpp_value(argument, index), | 504 v8_methods.v8_value_to_local_cpp_value(argument, index), |
| 502 } | 505 } |
| 503 | 506 |
| 504 | 507 |
| 505 def generate_constructor_overloads(constructors): | 508 def generate_constructor_overloads(constructors): |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 517 def generate_named_constructor(interface): | 520 def generate_named_constructor(interface): |
| 518 extended_attributes = interface.extended_attributes | 521 extended_attributes = interface.extended_attributes |
| 519 if 'NamedConstructor' not in extended_attributes: | 522 if 'NamedConstructor' not in extended_attributes: |
| 520 return None | 523 return None |
| 521 # FIXME: parser should return named constructor separately; | 524 # FIXME: parser should return named constructor separately; |
| 522 # included in constructors (and only name stored in extended attribute) | 525 # included in constructors (and only name stored in extended attribute) |
| 523 # for Perl compatibility | 526 # for Perl compatibility |
| 524 idl_constructor = interface.constructors[0] | 527 idl_constructor = interface.constructors[0] |
| 525 constructor = generate_constructor(interface, idl_constructor) | 528 constructor = generate_constructor(interface, idl_constructor) |
| 526 constructor['argument_list'].insert(0, '*document') | 529 constructor['argument_list'].insert(0, '*document') |
| 527 constructor['name'] = extended_attributes['NamedConstructor'] | 530 constructor['name'] = extended_attributes['NamedConstructor'] |
|
Nils Barth (inactive)
2014/04/09 09:36:38
As it's 2+ new values, could you use update instea
sof
2014/04/09 10:53:16
Done.
| |
| 531 constructor['is_named_constructor'] = True | |
| 528 return constructor | 532 return constructor |
| 529 | 533 |
| 530 | 534 |
| 531 def number_of_required_arguments(constructor): | 535 def number_of_required_arguments(constructor): |
| 532 return len([argument for argument in constructor.arguments | 536 return len([argument for argument in constructor.arguments |
| 533 if not argument.is_optional]) | 537 if not argument.is_optional]) |
| 534 | 538 |
| 535 | 539 |
| 536 def interface_length(interface, constructors): | 540 def interface_length(interface, constructors): |
| 537 # Docs: http://heycam.github.io/webidl/#es-interface-call | 541 # Docs: http://heycam.github.io/webidl/#es-interface-call |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 deleter = next( | 729 deleter = next( |
| 726 method | 730 method |
| 727 for method in interface.operations | 731 for method in interface.operations |
| 728 if ('deleter' in method.specials and | 732 if ('deleter' in method.specials and |
| 729 len(method.arguments) == 1 and | 733 len(method.arguments) == 1 and |
| 730 str(method.arguments[0].idl_type) == 'DOMString')) | 734 str(method.arguments[0].idl_type) == 'DOMString')) |
| 731 except StopIteration: | 735 except StopIteration: |
| 732 return None | 736 return None |
| 733 | 737 |
| 734 return property_deleter(deleter) | 738 return property_deleter(deleter) |
| OLD | NEW |