| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 constant['origin_trial_feature_name']] | 91 constant['origin_trial_feature_name']] |
| 92 | 92 |
| 93 | 93 |
| 94 def constant_filters(): | 94 def constant_filters(): |
| 95 return {'has_constant_configuration': filter_has_constant_configuration, | 95 return {'has_constant_configuration': filter_has_constant_configuration, |
| 96 'has_special_getter': filter_has_special_getter, | 96 'has_special_getter': filter_has_special_getter, |
| 97 'runtime_enabled_constants': filter_runtime_enabled, | 97 'runtime_enabled_constants': filter_runtime_enabled, |
| 98 'origin_trial_enabled_constants': filter_origin_trial_enabled} | 98 'origin_trial_enabled_constants': filter_origin_trial_enabled} |
| 99 | 99 |
| 100 | 100 |
| 101 def origin_trial_feature_names(constants, attributes): | 101 def origin_trial_feature_names(interface, constants, attributes, methods): |
| 102 """ Returns a list of the names of each origin trial feature used in this in
terface. | 102 """ Returns a list of the names of each origin trial feature used in this in
terface. |
| 103 | 103 |
| 104 This list is the union of the sets of names used for constants and attribute
s. | 104 This list is the union of the sets of names used for constants, attributes a
nd methods. |
| 105 """ | 105 """ |
| 106 | 106 |
| 107 feature_names = set( | 107 feature_names = set( |
| 108 [constant['origin_trial_feature_name'] for constant in constants if cons
tant['origin_trial_feature_name']] + | 108 [constant['origin_trial_feature_name'] for constant in constants if cons
tant['origin_trial_feature_name']] + |
| 109 [attribute['origin_trial_feature_name'] for attribute in attributes if a
ttribute['origin_trial_feature_name']] | 109 [attribute['origin_trial_feature_name'] for attribute in attributes if a
ttribute['origin_trial_feature_name']] + |
| 110 [method['origin_trial_feature_name'] for method in methods if ( |
| 111 v8_methods.method_is_visible(method, interface.is_partial) and |
| 112 method['origin_trial_feature_name'])] |
| 110 ) | 113 ) |
| 114 if feature_names: |
| 115 includes.add('bindings/core/v8/ScriptState.h') |
| 116 includes.add('core/origin_trials/OriginTrials.h') |
| 111 return sorted(feature_names) | 117 return sorted(feature_names) |
| 112 | 118 |
| 113 | 119 |
| 114 def interface_context(interface): | 120 def interface_context(interface): |
| 115 includes.clear() | 121 includes.clear() |
| 116 includes.update(INTERFACE_CPP_INCLUDES) | 122 includes.update(INTERFACE_CPP_INCLUDES) |
| 117 header_includes = set(INTERFACE_H_INCLUDES) | 123 header_includes = set(INTERFACE_H_INCLUDES) |
| 118 | 124 |
| 119 if interface.is_partial: | 125 if interface.is_partial: |
| 120 # A partial interface definition cannot specify that the interface | 126 # A partial interface definition cannot specify that the interface |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 elif stringifier.operation: | 508 elif stringifier.operation: |
| 503 implemented_as = stringifier.operation.name | 509 implemented_as = stringifier.operation.name |
| 504 else: | 510 else: |
| 505 implemented_as = 'toString' | 511 implemented_as = 'toString' |
| 506 methods.append(generated_method( | 512 methods.append(generated_method( |
| 507 return_type=IdlType('DOMString'), | 513 return_type=IdlType('DOMString'), |
| 508 name='toString', | 514 name='toString', |
| 509 extended_attributes=stringifier_ext_attrs, | 515 extended_attributes=stringifier_ext_attrs, |
| 510 implemented_as=implemented_as)) | 516 implemented_as=implemented_as)) |
| 511 | 517 |
| 512 conditionally_enabled_methods = [] | |
| 513 custom_registration_methods = [] | |
| 514 method_configuration_methods = [] | |
| 515 | |
| 516 for method in methods: | |
| 517 # Skip all but one method in each set of overloaded methods. | |
| 518 if 'overload_index' in method and 'overloads' not in method: | |
| 519 continue | |
| 520 | |
| 521 if 'overloads' in method: | |
| 522 overloads = method['overloads'] | |
| 523 if not overloads['visible']: | |
| 524 continue | |
| 525 # original interface will register instead of partial interface. | |
| 526 if overloads['has_partial_overloads'] and interface.is_partial: | |
| 527 continue | |
| 528 conditionally_exposed_function = overloads['exposed_test_all'] | |
| 529 runtime_enabled_function = overloads['runtime_enabled_function_all'] | |
| 530 has_custom_registration = (overloads['has_custom_registration_all']
or | |
| 531 overloads['runtime_determined_lengths']) | |
| 532 else: | |
| 533 if not method['visible']: | |
| 534 continue | |
| 535 conditionally_exposed_function = method['exposed_test'] | |
| 536 runtime_enabled_function = method['runtime_enabled_function'] | |
| 537 has_custom_registration = method['has_custom_registration'] | |
| 538 | |
| 539 if has_custom_registration: | |
| 540 custom_registration_methods.append(method) | |
| 541 continue | |
| 542 if conditionally_exposed_function: | |
| 543 conditionally_enabled_methods.append(method) | |
| 544 continue | |
| 545 if runtime_enabled_function: | |
| 546 custom_registration_methods.append(method) | |
| 547 continue | |
| 548 if method['should_be_exposed_to_script']: | |
| 549 method_configuration_methods.append(method) | |
| 550 | |
| 551 for method in methods: | 518 for method in methods: |
| 552 # The value of the Function object’s “length” property is a Number | 519 # The value of the Function object’s “length” property is a Number |
| 553 # determined as follows: | 520 # determined as follows: |
| 554 # 1. Let S be the effective overload set for regular operations (if the | 521 # 1. Let S be the effective overload set for regular operations (if the |
| 555 # operation is a regular operation) or for static operations (if the | 522 # operation is a regular operation) or for static operations (if the |
| 556 # operation is a static operation) with identifier id on interface I and | 523 # operation is a static operation) with identifier id on interface I and |
| 557 # with argument count 0. | 524 # with argument count 0. |
| 558 # 2. Return the length of the shortest argument list of the entries in S
. | 525 # 2. Return the length of the shortest argument list of the entries in S
. |
| 559 # FIXME: This calculation doesn't take into account whether runtime | 526 # FIXME: This calculation doesn't take into account whether runtime |
| 560 # enabled overloads are actually enabled, so length may be incorrect. | 527 # enabled overloads are actually enabled, so length may be incorrect. |
| 561 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); | 528 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); |
| 562 # should have length 1 if Foo is not enabled, but length 0 if it is. | 529 # should have length 1 if Foo is not enabled, but length 0 if it is. |
| 563 method['length'] = (method['overloads']['length'] if 'overloads' in meth
od else | 530 method['length'] = (method['overloads']['length'] if 'overloads' in meth
od else |
| 564 method['number_of_required_arguments']) | 531 method['number_of_required_arguments']) |
| 565 | 532 |
| 566 context.update({ | 533 context.update({ |
| 567 'conditionally_enabled_methods': conditionally_enabled_methods, | |
| 568 'custom_registration_methods': custom_registration_methods, | |
| 569 'has_origin_safe_method_setter': is_global and any( | 534 'has_origin_safe_method_setter': is_global and any( |
| 570 method['is_check_security_for_receiver'] and not method['is_unforgea
ble'] | 535 method['is_check_security_for_receiver'] and not method['is_unforgea
ble'] |
| 571 for method in methods), | 536 for method in methods), |
| 572 'has_private_script': (any(attribute['is_implemented_in_private_script']
for attribute in attributes) or | 537 'has_private_script': (any(attribute['is_implemented_in_private_script']
for attribute in attributes) or |
| 573 any(method['is_implemented_in_private_script'] fo
r method in methods)), | 538 any(method['is_implemented_in_private_script'] fo
r method in methods)), |
| 574 'iterator_method': iterator_method, | 539 'iterator_method': iterator_method, |
| 575 'has_array_iterator': has_array_iterator, | 540 'has_array_iterator': has_array_iterator, |
| 576 'method_configuration_methods': method_configuration_methods, | |
| 577 'methods': methods, | 541 'methods': methods, |
| 578 }) | 542 }) |
| 579 | 543 |
| 580 # Conditionally enabled members | 544 # Conditionally enabled members |
| 581 has_conditional_attributes_on_instance = any( | 545 has_conditional_attributes_on_instance = any( |
| 582 attribute['exposed_test'] and attribute['on_instance'] | 546 attribute['exposed_test'] and attribute['on_instance'] |
| 583 for attribute in attributes) | 547 for attribute in attributes) |
| 584 has_conditional_attributes_on_prototype = any( | 548 has_conditional_attributes_on_prototype = any( |
| 585 attribute['exposed_test'] and attribute['on_prototype'] | 549 attribute['exposed_test'] and attribute['on_prototype'] |
| 586 for attribute in attributes) | 550 for attribute in attributes) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 599 'named_property_getter': property_getter(interface.named_property_getter
, ['propertyName']), | 563 'named_property_getter': property_getter(interface.named_property_getter
, ['propertyName']), |
| 600 'named_property_setter': property_setter(interface.named_property_setter
, interface), | 564 'named_property_setter': property_setter(interface.named_property_setter
, interface), |
| 601 'named_property_deleter': property_deleter(interface.named_property_dele
ter), | 565 'named_property_deleter': property_deleter(interface.named_property_dele
ter), |
| 602 }) | 566 }) |
| 603 context.update({ | 567 context.update({ |
| 604 'has_named_properties_object': is_global and context['named_property_get
ter'], | 568 'has_named_properties_object': is_global and context['named_property_get
ter'], |
| 605 }) | 569 }) |
| 606 | 570 |
| 607 # Origin Trials | 571 # Origin Trials |
| 608 context.update({ | 572 context.update({ |
| 609 'origin_trial_feature_names': origin_trial_feature_names(context['consta
nts'], context['attributes']), | 573 'origin_trial_feature_names': origin_trial_feature_names(interface, cont
ext['constants'], context['attributes'], context['methods']), |
| 610 }) | 574 }) |
| 611 return context | 575 return context |
| 612 | 576 |
| 613 | 577 |
| 614 # [DeprecateAs], [OriginTrialEnabled], [Reflect], [RuntimeEnabled] | 578 # [DeprecateAs], [OriginTrialEnabled], [Reflect], [RuntimeEnabled] |
| 615 def constant_context(constant, interface): | 579 def constant_context(constant, interface): |
| 616 extended_attributes = constant.extended_attributes | 580 extended_attributes = constant.extended_attributes |
| 617 | 581 |
| 618 return { | 582 return { |
| 619 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), | 583 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 def overloads_context(interface, overloads): | 643 def overloads_context(interface, overloads): |
| 680 """Returns |overloads| template values for a single name. | 644 """Returns |overloads| template values for a single name. |
| 681 | 645 |
| 682 Sets |method.overload_index| in place for |method| in |overloads| | 646 Sets |method.overload_index| in place for |method| in |overloads| |
| 683 and returns dict of overall overload template values. | 647 and returns dict of overall overload template values. |
| 684 """ | 648 """ |
| 685 assert len(overloads) > 1 # only apply to overloaded names | 649 assert len(overloads) > 1 # only apply to overloaded names |
| 686 for index, method in enumerate(overloads, 1): | 650 for index, method in enumerate(overloads, 1): |
| 687 method['overload_index'] = index | 651 method['overload_index'] = index |
| 688 | 652 |
| 653 # [OriginTrialEnabled] |
| 654 # TODO(iclelland): Allow origin trials on method overloads |
| 655 # (crbug.com/621641) |
| 656 if any(method.get('origin_trial_feature_name') for method in overloads): |
| 657 raise Exception('[OriginTrialEnabled] cannot be specified on ' |
| 658 'overloaded methods: %s.%s' % (interface.name, overloads
[0]['name'])) |
| 659 |
| 689 effective_overloads_by_length = effective_overload_set_by_length(overloads) | 660 effective_overloads_by_length = effective_overload_set_by_length(overloads) |
| 690 lengths = [length for length, _ in effective_overloads_by_length] | 661 lengths = [length for length, _ in effective_overloads_by_length] |
| 691 name = overloads[0].get('name', '<constructor>') | 662 name = overloads[0].get('name', '<constructor>') |
| 692 | 663 |
| 693 runtime_determined_lengths = None | 664 runtime_determined_lengths = None |
| 694 function_length = lengths[0] | 665 function_length = lengths[0] |
| 695 runtime_determined_maxargs = None | 666 runtime_determined_maxargs = None |
| 696 maxarg = lengths[-1] | 667 maxarg = lengths[-1] |
| 697 | 668 |
| 698 # The special case handling below is not needed if all overloads are | 669 # The special case handling below is not needed if all overloads are |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 extended_attributes = deleter.extended_attributes | 1372 extended_attributes = deleter.extended_attributes |
| 1402 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') | 1373 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') |
| 1403 is_ce_reactions = 'CEReactions' in extended_attributes | 1374 is_ce_reactions = 'CEReactions' in extended_attributes |
| 1404 return { | 1375 return { |
| 1405 'is_call_with_script_state': is_call_with_script_state, | 1376 'is_call_with_script_state': is_call_with_script_state, |
| 1406 'is_ce_reactions': is_ce_reactions, | 1377 'is_ce_reactions': is_ce_reactions, |
| 1407 'is_custom': 'Custom' in extended_attributes, | 1378 'is_custom': 'Custom' in extended_attributes, |
| 1408 'is_raises_exception': 'RaisesException' in extended_attributes, | 1379 'is_raises_exception': 'RaisesException' in extended_attributes, |
| 1409 'name': cpp_name(deleter), | 1380 'name': cpp_name(deleter), |
| 1410 } | 1381 } |
| OLD | NEW |