Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/v8_interface.py

Issue 2578943002: [Bindings] Refactoring of binding code around runtime enabled features (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 28 matching lines...) Expand all
39 from operator import itemgetter, or_ 39 from operator import itemgetter, or_
40 40
41 from idl_definitions import IdlOperation, IdlArgument 41 from idl_definitions import IdlOperation, IdlArgument
42 from idl_types import IdlType, inherits_interface 42 from idl_types import IdlType, inherits_interface
43 import v8_attributes 43 import v8_attributes
44 from v8_globals import includes 44 from v8_globals import includes
45 import v8_methods 45 import v8_methods
46 import v8_types 46 import v8_types
47 import v8_utilities 47 import v8_utilities
48 from v8_utilities import (cpp_name_or_partial, cpp_name, has_extended_attribute_ value, 48 from v8_utilities import (cpp_name_or_partial, cpp_name, has_extended_attribute_ value,
49 runtime_enabled_function_name, is_legacy_interface_typ e_checking) 49 runtime_feature_name, is_legacy_interface_type_checkin g)
50 50
51 51
52 INTERFACE_H_INCLUDES = frozenset([ 52 INTERFACE_H_INCLUDES = frozenset([
53 'bindings/core/v8/ScriptWrappable.h', 53 'bindings/core/v8/ScriptWrappable.h',
54 'bindings/core/v8/ToV8.h', 54 'bindings/core/v8/ToV8.h',
55 'bindings/core/v8/V8Binding.h', 55 'bindings/core/v8/V8Binding.h',
56 'bindings/core/v8/V8DOMWrapper.h', 56 'bindings/core/v8/V8DOMWrapper.h',
57 'bindings/core/v8/WrapperTypeInfo.h', 57 'bindings/core/v8/WrapperTypeInfo.h',
58 'platform/heap/Handle.h', 58 'platform/heap/Handle.h',
59 ]) 59 ])
60 INTERFACE_CPP_INCLUDES = frozenset([ 60 INTERFACE_CPP_INCLUDES = frozenset([
61 'bindings/core/v8/ExceptionState.h', 61 'bindings/core/v8/ExceptionState.h',
62 'bindings/core/v8/GeneratedCodeHelper.h', 62 'bindings/core/v8/GeneratedCodeHelper.h',
63 'bindings/core/v8/V8DOMConfiguration.h', 63 'bindings/core/v8/V8DOMConfiguration.h',
64 'bindings/core/v8/V8ObjectConstructor.h', 64 'bindings/core/v8/V8ObjectConstructor.h',
65 'core/dom/Document.h', 65 'core/dom/Document.h',
66 'wtf/GetPtr.h', 66 'wtf/GetPtr.h',
67 'wtf/RefPtr.h', 67 'wtf/RefPtr.h',
68 ]) 68 ])
69 69
70 70
71 def filter_has_constant_configuration(constants): 71 def filter_has_constant_configuration(constants):
72 return [constant for constant in constants if 72 return [constant for constant in constants if
73 not constant['measure_as'] and 73 not constant['measure_as'] and
74 not constant['deprecate_as'] and 74 not constant['deprecate_as'] and
75 not constant['runtime_enabled_function'] and 75 not constant['runtime_enabled'] and
76 not constant['origin_trial_feature_name']] 76 not constant['origin_trial_feature_name']]
77 77
78 78
79 def filter_has_special_getter(constants): 79 def filter_has_special_getter(constants):
80 return [constant for constant in constants if 80 return [constant for constant in constants if
81 constant['measure_as'] or 81 constant['measure_as'] or
82 constant['deprecate_as']] 82 constant['deprecate_as']]
83 83
84 84
85 def filter_runtime_enabled(constants): 85 def filter_runtime_enabled(constants):
86 return [constant for constant in constants if 86 return [constant for constant in constants if
87 constant['runtime_enabled_function']] 87 constant['runtime_enabled']]
88 88
89 89
90 def filter_origin_trial_enabled(constants): 90 def filter_origin_trial_enabled(constants):
91 return [constant for constant in constants if 91 return [constant for constant in constants if
92 constant['origin_trial_feature_name']] 92 constant['origin_trial_feature_name']]
93 93
94 94
95 def constant_filters(): 95 def constant_filters():
96 return {'has_constant_configuration': filter_has_constant_configuration, 96 return {'has_constant_configuration': filter_has_constant_configuration,
97 'has_special_getter': filter_has_special_getter, 97 'has_special_getter': filter_has_special_getter,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 'is_immutable_prototype': is_immutable_prototype, 266 'is_immutable_prototype': is_immutable_prototype,
267 'is_node': inherits_interface(interface.name, 'Node'), 267 'is_node': inherits_interface(interface.name, 'Node'),
268 'is_partial': interface.is_partial, 268 'is_partial': interface.is_partial,
269 'is_typed_array_type': is_typed_array_type, 269 'is_typed_array_type': is_typed_array_type,
270 'lifetime': 'Dependent' if (has_visit_dom_wrapper or is_dependent_lifeti me) else 'Independent', 270 'lifetime': 'Dependent' if (has_visit_dom_wrapper or is_dependent_lifeti me) else 'Independent',
271 'measure_as': v8_utilities.measure_as(interface, None), # [MeasureAs] 271 'measure_as': v8_utilities.measure_as(interface, None), # [MeasureAs]
272 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_funct ion_name(interface), 272 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_funct ion_name(interface),
273 'parent_interface': parent_interface, 273 'parent_interface': parent_interface,
274 'pass_cpp_type': cpp_name(interface) + '*', 274 'pass_cpp_type': cpp_name(interface) + '*',
275 'active_scriptwrappable': active_scriptwrappable, 275 'active_scriptwrappable': active_scriptwrappable,
276 'runtime_enabled_function': runtime_enabled_function_name(interface), # [RuntimeEnabled] 276 'runtime_enabled': runtime_feature_name(interface), # [RuntimeEnabled]
277 'set_wrapper_reference_from': set_wrapper_reference_from, 277 'set_wrapper_reference_from': set_wrapper_reference_from,
278 'set_wrapper_reference_to': set_wrapper_reference_to, 278 'set_wrapper_reference_to': set_wrapper_reference_to,
279 'v8_class': v8_class_name, 279 'v8_class': v8_class_name,
280 'v8_class_or_partial': v8_class_name_or_partial, 280 'v8_class_or_partial': v8_class_name_or_partial,
281 'wrapper_class_id': wrapper_class_id, 281 'wrapper_class_id': wrapper_class_id,
282 } 282 }
283 283
284 # Constructors 284 # Constructors
285 constructors = [constructor_context(interface, constructor) 285 constructors = [constructor_context(interface, constructor)
286 for constructor in interface.constructors 286 for constructor in interface.constructors
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 includes.add('core/frame/LocalDOMWindow.h') 320 includes.add('core/frame/LocalDOMWindow.h')
321 elif 'Measure' in extended_attributes or 'MeasureAs' in extended_attributes: 321 elif 'Measure' in extended_attributes or 'MeasureAs' in extended_attributes:
322 if not interface.is_partial: 322 if not interface.is_partial:
323 raise Exception('[Measure] or [MeasureAs] specified for interface wi thout a constructor: ' 323 raise Exception('[Measure] or [MeasureAs] specified for interface wi thout a constructor: '
324 '%s' % interface.name) 324 '%s' % interface.name)
325 325
326 # [Unscopable] attributes and methods 326 # [Unscopable] attributes and methods
327 unscopables = [] 327 unscopables = []
328 for attribute in interface.attributes: 328 for attribute in interface.attributes:
329 if 'Unscopable' in attribute.extended_attributes: 329 if 'Unscopable' in attribute.extended_attributes:
330 unscopables.append((attribute.name, v8_utilities.runtime_enabled_fun ction_name(attribute))) 330 unscopables.append((attribute.name, runtime_feature_name(attribute)) )
331 for method in interface.operations: 331 for method in interface.operations:
332 if 'Unscopable' in method.extended_attributes: 332 if 'Unscopable' in method.extended_attributes:
333 unscopables.append((method.name, v8_utilities.runtime_enabled_functi on_name(method))) 333 unscopables.append((method.name, runtime_feature_name(method)))
334 334
335 # [CEReactions] 335 # [CEReactions]
336 setter_or_deleters = ( 336 setter_or_deleters = (
337 interface.indexed_property_setter, 337 interface.indexed_property_setter,
338 interface.indexed_property_deleter, 338 interface.indexed_property_deleter,
339 interface.named_property_setter, 339 interface.named_property_setter,
340 interface.named_property_deleter, 340 interface.named_property_deleter,
341 ) 341 )
342 has_ce_reactions = any(setter_or_deleter and 'CEReactions' in setter_or_dele ter.extended_attributes 342 has_ce_reactions = any(setter_or_deleter and 'CEReactions' in setter_or_dele ter.extended_attributes
343 for setter_or_deleter in setter_or_deleters) 343 for setter_or_deleter in setter_or_deleters)
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 return { 704 return {
705 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), 705 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'),
706 'deprecate_as': v8_utilities.deprecate_as(constant), # [DeprecateAs] 706 'deprecate_as': v8_utilities.deprecate_as(constant), # [DeprecateAs]
707 'idl_type': constant.idl_type.name, 707 'idl_type': constant.idl_type.name,
708 'measure_as': v8_utilities.measure_as(constant, interface), # [MeasureA s] 708 'measure_as': v8_utilities.measure_as(constant, interface), # [MeasureA s]
709 'name': constant.name, 709 'name': constant.name,
710 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_funct ion_name(constant), # [OriginTrialEnabled] 710 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_funct ion_name(constant), # [OriginTrialEnabled]
711 'origin_trial_feature_name': v8_utilities.origin_trial_feature_name(cons tant), # [OriginTrialEnabled] 711 'origin_trial_feature_name': v8_utilities.origin_trial_feature_name(cons tant), # [OriginTrialEnabled]
712 # FIXME: use 'reflected_name' as correct 'name' 712 # FIXME: use 'reflected_name' as correct 'name'
713 'reflected_name': extended_attributes.get('Reflect', reflected_name(cons tant.name)), 713 'reflected_name': extended_attributes.get('Reflect', reflected_name(cons tant.name)),
714 'runtime_enabled_function': runtime_enabled_function_name(constant), # [RuntimeEnabled] 714 'runtime_enabled': runtime_feature_name(constant), # [RuntimeEnabled]
715 'runtime_feature_name': v8_utilities.runtime_feature_name(constant), # [RuntimeEnabled]
716 'value': constant.value, 715 'value': constant.value,
717 } 716 }
718 717
719 718
720 ################################################################################ 719 ################################################################################
721 # Overloads 720 # Overloads
722 ################################################################################ 721 ################################################################################
723 722
724 def compute_method_overloads_context(interface, methods): 723 def compute_method_overloads_context(interface, methods):
725 # Regular methods 724 # Regular methods
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 lengths = [length for length, _ in effective_overloads_by_length] 782 lengths = [length for length, _ in effective_overloads_by_length]
784 name = overloads[0].get('name', '<constructor>') 783 name = overloads[0].get('name', '<constructor>')
785 784
786 runtime_determined_lengths = None 785 runtime_determined_lengths = None
787 function_length = lengths[0] 786 function_length = lengths[0]
788 runtime_determined_maxargs = None 787 runtime_determined_maxargs = None
789 maxarg = lengths[-1] 788 maxarg = lengths[-1]
790 789
791 # The special case handling below is not needed if all overloads are 790 # The special case handling below is not needed if all overloads are
792 # runtime enabled by the same feature. 791 # runtime enabled by the same feature.
793 if not common_value(overloads, 'runtime_enabled_function'): 792 if not common_value(overloads, 'runtime_enabled'):
794 # Check if all overloads with the shortest acceptable arguments list are 793 # Check if all overloads with the shortest acceptable arguments list are
795 # runtime enabled, in which case we need to have a runtime determined 794 # runtime enabled, in which case we need to have a runtime determined
796 # Function.length. 795 # Function.length.
797 shortest_overloads = effective_overloads_by_length[0][1] 796 shortest_overloads = effective_overloads_by_length[0][1]
798 if (all(method.get('runtime_enabled_function') 797 if (all(method.get('runtime_enabled')
799 for method, _, _ in shortest_overloads)): 798 for method, _, _ in shortest_overloads)):
800 # Generate a list of (length, runtime_enabled_functions) tuples. 799 # Generate a list of (length, runtime_enabled) tuples.
801 runtime_determined_lengths = [] 800 runtime_determined_lengths = []
802 for length, effective_overloads in effective_overloads_by_length: 801 for length, effective_overloads in effective_overloads_by_length:
803 runtime_enabled_functions = set( 802 runtime_enableds = set(
804 method['runtime_enabled_function'] 803 method['runtime_enabled']
805 for method, _, _ in effective_overloads 804 for method, _, _ in effective_overloads
806 if method.get('runtime_enabled_function')) 805 if method.get('runtime_enabled'))
807 if not runtime_enabled_functions: 806 if not runtime_enableds:
808 # This "length" is unconditionally enabled, so stop here. 807 # This "length" is unconditionally enabled, so stop here.
809 runtime_determined_lengths.append((length, [None])) 808 runtime_determined_lengths.append((length, [None]))
810 break 809 break
811 runtime_determined_lengths.append( 810 runtime_determined_lengths.append(
812 (length, sorted(runtime_enabled_functions))) 811 (length, sorted(runtime_enableds)))
813 function_length = ('%sV8Internal::%sMethodLength()' 812 function_length = ('%sV8Internal::%sMethodLength()'
814 % (cpp_name_or_partial(interface), name)) 813 % (cpp_name_or_partial(interface), name))
815 814
816 # Check if all overloads with the longest required arguments list are 815 # Check if all overloads with the longest required arguments list are
817 # runtime enabled, in which case we need to have a runtime determined 816 # runtime enabled, in which case we need to have a runtime determined
818 # maximum distinguishing argument index. 817 # maximum distinguishing argument index.
819 longest_overloads = effective_overloads_by_length[-1][1] 818 longest_overloads = effective_overloads_by_length[-1][1]
820 if (not common_value(overloads, 'runtime_enabled_function') and 819 if (not common_value(overloads, 'runtime_enabled') and
821 all(method.get('runtime_enabled_function') 820 all(method.get('runtime_enabled')
822 for method, _, _ in longest_overloads)): 821 for method, _, _ in longest_overloads)):
823 # Generate a list of (length, runtime_enabled_functions) tuples. 822 # Generate a list of (length, runtime_enabled) tuples.
824 runtime_determined_maxargs = [] 823 runtime_determined_maxargs = []
825 for length, effective_overloads in reversed(effective_overloads_by_l ength): 824 for length, effective_overloads in reversed(effective_overloads_by_l ength):
826 runtime_enabled_functions = set( 825 runtime_enableds = set(
827 method['runtime_enabled_function'] 826 method['runtime_enabled']
828 for method, _, _ in effective_overloads 827 for method, _, _ in effective_overloads
829 if method.get('runtime_enabled_function')) 828 if method.get('runtime_enabled'))
830 if not runtime_enabled_functions: 829 if not runtime_enableds:
831 # This "length" is unconditionally enabled, so stop here. 830 # This "length" is unconditionally enabled, so stop here.
832 runtime_determined_maxargs.append((length, [None])) 831 runtime_determined_maxargs.append((length, [None]))
833 break 832 break
834 runtime_determined_maxargs.append( 833 runtime_determined_maxargs.append(
835 (length, sorted(runtime_enabled_functions))) 834 (length, sorted(runtime_enableds)))
836 maxarg = ('%sV8Internal::%sMethodMaxArg()' 835 maxarg = ('%sV8Internal::%sMethodMaxArg()'
837 % (cpp_name_or_partial(interface), name)) 836 % (cpp_name_or_partial(interface), name))
838 837
839 # Check and fail if overloads disagree about whether the return type 838 # Check and fail if overloads disagree about whether the return type
840 # is a Promise or not. 839 # is a Promise or not.
841 promise_overload_count = sum(1 for method in overloads if method.get('return s_promise')) 840 promise_overload_count = sum(1 for method in overloads if method.get('return s_promise'))
842 if promise_overload_count not in (0, len(overloads)): 841 if promise_overload_count not in (0, len(overloads)):
843 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes' 842 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes'
844 % (name)) 843 % (name))
845 844
(...skipping 16 matching lines...) Expand all
862 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ] 861 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ]
863 'length': function_length, 862 'length': function_length,
864 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), 863 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th),
865 # 1. Let maxarg be the length of the longest type list of the 864 # 1. Let maxarg be the length of the longest type list of the
866 # entries in S. 865 # entries in S.
867 'maxarg': maxarg, 866 'maxarg': maxarg,
868 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] 867 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs]
869 'returns_promise_all': promise_overload_count > 0, 868 'returns_promise_all': promise_overload_count > 0,
870 'runtime_determined_lengths': runtime_determined_lengths, 869 'runtime_determined_lengths': runtime_determined_lengths,
871 'runtime_determined_maxargs': runtime_determined_maxargs, 870 'runtime_determined_maxargs': runtime_determined_maxargs,
872 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled _function'), # [RuntimeEnabled] 871 'runtime_enabled_all': common_value(overloads, 'runtime_enabled'), # [R untimeEnabled]
873 'secure_context_test_all': common_value(overloads, 'secure_context_test' ), # [SecureContext] 872 'secure_context_test_all': common_value(overloads, 'secure_context_test' ), # [SecureContext]
874 'valid_arities': (lengths 873 'valid_arities': (lengths
875 # Only need to report valid arities if there is a gap in the 874 # Only need to report valid arities if there is a gap in the
876 # sequence of possible lengths, otherwise invalid leng th means 875 # sequence of possible lengths, otherwise invalid leng th means
877 # "not enough arguments". 876 # "not enough arguments".
878 if lengths[-1] - lengths[0] != len(lengths) - 1 else N one), 877 if lengths[-1] - lengths[0] != len(lengths) - 1 else N one),
879 'visible': has_overload_visible, 878 'visible': has_overload_visible,
880 'has_partial_overloads': has_partial_overloads, 879 'has_partial_overloads': has_partial_overloads,
881 } 880 }
882 881
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 extended_attributes = deleter.extended_attributes 1486 extended_attributes = deleter.extended_attributes
1488 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState') 1487 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState')
1489 is_ce_reactions = 'CEReactions' in extended_attributes 1488 is_ce_reactions = 'CEReactions' in extended_attributes
1490 return { 1489 return {
1491 'is_call_with_script_state': is_call_with_script_state, 1490 'is_call_with_script_state': is_call_with_script_state,
1492 'is_ce_reactions': is_ce_reactions, 1491 'is_ce_reactions': is_ce_reactions,
1493 'is_custom': 'Custom' in extended_attributes, 1492 'is_custom': 'Custom' in extended_attributes,
1494 'is_raises_exception': 'RaisesException' in extended_attributes, 1493 'is_raises_exception': 'RaisesException' in extended_attributes,
1495 'name': cpp_name(deleter), 1494 'name': cpp_name(deleter),
1496 } 1495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698