| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 conditional_enabled_attributes = v8_attributes.filter_conditionally_enabled(
attributes) | 367 conditional_enabled_attributes = v8_attributes.filter_conditionally_enabled(
attributes) |
| 368 has_conditional_attributes_on_prototype = any( # pylint: disable=invalid-na
me | 368 has_conditional_attributes_on_prototype = any( # pylint: disable=invalid-na
me |
| 369 attribute['on_prototype'] for attribute in conditional_enabled_attribute
s) | 369 attribute['on_prototype'] for attribute in conditional_enabled_attribute
s) |
| 370 context.update({ | 370 context.update({ |
| 371 'has_conditional_attributes_on_prototype': | 371 'has_conditional_attributes_on_prototype': |
| 372 has_conditional_attributes_on_prototype, | 372 has_conditional_attributes_on_prototype, |
| 373 'conditionally_enabled_attributes': conditional_enabled_attributes, | 373 'conditionally_enabled_attributes': conditional_enabled_attributes, |
| 374 }) | 374 }) |
| 375 | 375 |
| 376 # Methods | 376 # Methods |
| 377 methods, iterator_method = methods_context(interface) | 377 context.update(methods_context(interface)) |
| 378 methods = context['methods'] |
| 378 context.update({ | 379 context.update({ |
| 379 'has_origin_safe_method_setter': any(method['is_cross_origin'] and not m
ethod['is_unforgeable'] | 380 'has_origin_safe_method_setter': any(method['is_cross_origin'] and not m
ethod['is_unforgeable'] |
| 380 for method in methods), | 381 for method in methods), |
| 381 'iterator_method': iterator_method, | |
| 382 'methods': methods, | |
| 383 'conditionally_enabled_methods': v8_methods.filter_conditionally_enabled
(methods, interface.is_partial), | 382 'conditionally_enabled_methods': v8_methods.filter_conditionally_enabled
(methods, interface.is_partial), |
| 384 }) | 383 }) |
| 385 | 384 |
| 386 # Window.idl in Blink has indexed properties, but the spec says Window | 385 # Window.idl in Blink has indexed properties, but the spec says Window |
| 387 # interface doesn't have indexed properties, instead the WindowProxy exotic | 386 # interface doesn't have indexed properties, instead the WindowProxy exotic |
| 388 # object has indexed properties. Thus, Window interface must not support | 387 # object has indexed properties. Thus, Window interface must not support |
| 389 # iterators. | 388 # iterators. |
| 390 has_array_iterator = (not interface.is_partial and | 389 has_array_iterator = (not interface.is_partial and |
| 391 interface.has_indexed_elements and | 390 interface.has_indexed_elements and |
| 392 interface.name != 'Window') | 391 interface.name != 'Window') |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 return attributes | 499 return attributes |
| 501 | 500 |
| 502 | 501 |
| 503 def methods_context(interface): | 502 def methods_context(interface): |
| 504 """Creates a list of Jinja template contexts for methods of an interface. | 503 """Creates a list of Jinja template contexts for methods of an interface. |
| 505 | 504 |
| 506 Args: | 505 Args: |
| 507 interface: An interface to create contexts for | 506 interface: An interface to create contexts for |
| 508 | 507 |
| 509 Returns: | 508 Returns: |
| 510 A list of method contexts, and an iterator context if available or None | 509 A dictionary with 3 keys: |
| 510 'iterator_method': An iterator context if available or None. |
| 511 'iterator_method_alias': A string that can also be used to refer to the |
| 512 @@iterator symbol or None. |
| 513 'methods': A list of method contexts. |
| 511 """ | 514 """ |
| 512 | 515 |
| 513 methods = [] | 516 methods = [] |
| 514 | 517 |
| 515 if interface.original_interface: | 518 if interface.original_interface: |
| 516 methods.extend([v8_methods.method_context(interface, operation, is_visib
le=False) | 519 methods.extend([v8_methods.method_context(interface, operation, is_visib
le=False) |
| 517 for operation in interface.original_interface.operations | 520 for operation in interface.original_interface.operations |
| 518 if operation.name]) | 521 if operation.name]) |
| 519 methods.extend([v8_methods.method_context(interface, method) | 522 methods.extend([v8_methods.method_context(interface, method) |
| 520 for method in interface.operations | 523 for method in interface.operations |
| (...skipping 24 matching lines...) Expand all Loading... |
| 545 argument.idl_type = idl_type | 548 argument.idl_type = idl_type |
| 546 argument.name = name | 549 argument.name = name |
| 547 argument.is_optional = is_optional | 550 argument.is_optional = is_optional |
| 548 if extended_attributes: | 551 if extended_attributes: |
| 549 argument.extended_attributes.update(extended_attributes) | 552 argument.extended_attributes.update(extended_attributes) |
| 550 return argument | 553 return argument |
| 551 | 554 |
| 552 # iterable<>, maplike<> and setlike<> | 555 # iterable<>, maplike<> and setlike<> |
| 553 iterator_method = None | 556 iterator_method = None |
| 554 | 557 |
| 558 # Depending on the declaration, @@iterator may be a synonym for e.g. |
| 559 # 'entries' or 'values'. |
| 560 iterator_method_alias = None |
| 561 |
| 555 # FIXME: support Iterable in partial interfaces. However, we don't | 562 # FIXME: support Iterable in partial interfaces. However, we don't |
| 556 # need to support iterator overloads between interface and | 563 # need to support iterator overloads between interface and |
| 557 # partial interface definitions. | 564 # partial interface definitions. |
| 558 # http://heycam.github.io/webidl/#idl-overloading | 565 # http://heycam.github.io/webidl/#idl-overloading |
| 559 if (not interface.is_partial and ( | 566 if (not interface.is_partial and ( |
| 560 interface.iterable or interface.maplike or interface.setlike or | 567 interface.iterable or interface.maplike or interface.setlike or |
| 561 interface.has_indexed_elements)): | 568 interface.has_indexed_elements)): |
| 562 | 569 |
| 563 used_extended_attributes = {} | 570 used_extended_attributes = {} |
| 564 | 571 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 595 iterator_method = generated_iterator_method('iterator', implemented_
as='GetIterator') | 602 iterator_method = generated_iterator_method('iterator', implemented_
as='GetIterator') |
| 596 | 603 |
| 597 if interface.iterable or interface.maplike or interface.setlike: | 604 if interface.iterable or interface.maplike or interface.setlike: |
| 598 non_overridable_methods = [] | 605 non_overridable_methods = [] |
| 599 overridable_methods = [] | 606 overridable_methods = [] |
| 600 | 607 |
| 601 is_value_iterator = interface.iterable and interface.iterable.key_ty
pe is None | 608 is_value_iterator = interface.iterable and interface.iterable.key_ty
pe is None |
| 602 | 609 |
| 603 # For value iterators, the |entries|, |forEach|, |keys| and |values|
are originally set | 610 # For value iterators, the |entries|, |forEach|, |keys| and |values|
are originally set |
| 604 # to corresponding properties in %ArrayPrototype%. | 611 # to corresponding properties in %ArrayPrototype%. |
| 612 # For pair iterators and maplike declarations, |entries| is an alias
for @@iterator |
| 613 # itself. For setlike declarations, |values| is an alias for @@itera
tor. |
| 605 if not is_value_iterator: | 614 if not is_value_iterator: |
| 615 if not interface.setlike: |
| 616 iterator_method_alias = 'entries' |
| 617 entries_or_values_method = generated_iterator_method('values
') |
| 618 else: |
| 619 iterator_method_alias = 'values' |
| 620 entries_or_values_method = generated_iterator_method('entrie
s') |
| 621 |
| 606 non_overridable_methods.extend([ | 622 non_overridable_methods.extend([ |
| 607 generated_iterator_method('keys'), | 623 generated_iterator_method('keys'), |
| 608 generated_iterator_method('values'), | 624 entries_or_values_method, |
| 609 generated_iterator_method('entries'), | |
| 610 | 625 |
| 611 # void forEach(Function callback, [Default=Undefined] option
al any thisArg) | 626 # void forEach(Function callback, [Default=Undefined] option
al any thisArg) |
| 612 generated_method(IdlType('void'), 'forEach', | 627 generated_method(IdlType('void'), 'forEach', |
| 613 arguments=[generated_argument(IdlType('Func
tion'), 'callback'), | 628 arguments=[generated_argument(IdlType('Func
tion'), 'callback'), |
| 614 generated_argument(IdlType('any'
), 'thisArg', | 629 generated_argument(IdlType('any'
), 'thisArg', |
| 615 is_optional=T
rue, | 630 is_optional=T
rue, |
| 616 extended_attr
ibutes={'Default': 'Undefined'})], | 631 extended_attr
ibutes={'Default': 'Undefined'})], |
| 617 extended_attributes=forEach_extended_attrib
utes), | 632 extended_attributes=forEach_extended_attrib
utes), |
| 618 ]) | 633 ]) |
| 619 | 634 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 # operation is a static operation) with identifier id on interface I and | 741 # operation is a static operation) with identifier id on interface I and |
| 727 # with argument count 0. | 742 # with argument count 0. |
| 728 # 2. Return the length of the shortest argument list of the entries in S
. | 743 # 2. Return the length of the shortest argument list of the entries in S
. |
| 729 # FIXME: This calculation doesn't take into account whether runtime | 744 # FIXME: This calculation doesn't take into account whether runtime |
| 730 # enabled overloads are actually enabled, so length may be incorrect. | 745 # enabled overloads are actually enabled, so length may be incorrect. |
| 731 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); | 746 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); |
| 732 # should have length 1 if Foo is not enabled, but length 0 if it is. | 747 # should have length 1 if Foo is not enabled, but length 0 if it is. |
| 733 method['length'] = (method['overloads']['length'] if 'overloads' in meth
od else | 748 method['length'] = (method['overloads']['length'] if 'overloads' in meth
od else |
| 734 method['number_of_required_arguments']) | 749 method['number_of_required_arguments']) |
| 735 | 750 |
| 736 return methods, iterator_method | 751 return { |
| 752 'iterator_method': iterator_method, |
| 753 'iterator_method_alias': iterator_method_alias, |
| 754 'methods': methods, |
| 755 } |
| 737 | 756 |
| 738 | 757 |
| 739 def reflected_name(constant_name): | 758 def reflected_name(constant_name): |
| 740 """Returns the name to use for the matching constant name in blink code. | 759 """Returns the name to use for the matching constant name in blink code. |
| 741 | 760 |
| 742 Given an all-uppercase 'CONSTANT_NAME', returns a camel-case | 761 Given an all-uppercase 'CONSTANT_NAME', returns a camel-case |
| 743 'kConstantName'. | 762 'kConstantName'. |
| 744 """ | 763 """ |
| 745 # Check for SHOUTY_CASE constants | 764 # Check for SHOUTY_CASE constants |
| 746 if constant_name.upper() != constant_name: | 765 if constant_name.upper() != constant_name: |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 extended_attributes = deleter.extended_attributes | 1433 extended_attributes = deleter.extended_attributes |
| 1415 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') | 1434 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') |
| 1416 is_ce_reactions = 'CEReactions' in extended_attributes | 1435 is_ce_reactions = 'CEReactions' in extended_attributes |
| 1417 return { | 1436 return { |
| 1418 'is_call_with_script_state': is_call_with_script_state, | 1437 'is_call_with_script_state': is_call_with_script_state, |
| 1419 'is_ce_reactions': is_ce_reactions, | 1438 'is_ce_reactions': is_ce_reactions, |
| 1420 'is_custom': 'Custom' in extended_attributes, | 1439 'is_custom': 'Custom' in extended_attributes, |
| 1421 'is_raises_exception': 'RaisesException' in extended_attributes, | 1440 'is_raises_exception': 'RaisesException' in extended_attributes, |
| 1422 'name': cpp_name(deleter), | 1441 'name': cpp_name(deleter), |
| 1423 } | 1442 } |
| OLD | NEW |