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

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: Work for a comment 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_enabled_feature_name, is_legacy_interface_type _checking)
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_feature_name'] 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_feature_name']]
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 'is_immutable_prototype': is_immutable_prototype, 276 'is_immutable_prototype': is_immutable_prototype,
277 'is_node': inherits_interface(interface.name, 'Node'), 277 'is_node': inherits_interface(interface.name, 'Node'),
278 'is_partial': interface.is_partial, 278 'is_partial': interface.is_partial,
279 'is_typed_array_type': is_typed_array_type, 279 'is_typed_array_type': is_typed_array_type,
280 'lifetime': 'Dependent' if (has_visit_dom_wrapper or is_dependent_lifeti me) else 'Independent', 280 'lifetime': 'Dependent' if (has_visit_dom_wrapper or is_dependent_lifeti me) else 'Independent',
281 'measure_as': v8_utilities.measure_as(interface, None), # [MeasureAs] 281 'measure_as': v8_utilities.measure_as(interface, None), # [MeasureAs]
282 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_funct ion_name(interface), 282 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_funct ion_name(interface),
283 'parent_interface': parent_interface, 283 'parent_interface': parent_interface,
284 'pass_cpp_type': cpp_name(interface) + '*', 284 'pass_cpp_type': cpp_name(interface) + '*',
285 'active_scriptwrappable': active_scriptwrappable, 285 'active_scriptwrappable': active_scriptwrappable,
286 'runtime_enabled_function': runtime_enabled_function_name(interface), # [RuntimeEnabled] 286 'runtime_enabled_feature_name': runtime_enabled_feature_name(interface), # [RuntimeEnabled]
287 'set_wrapper_reference_from': set_wrapper_reference_from, 287 'set_wrapper_reference_from': set_wrapper_reference_from,
288 'set_wrapper_reference_to': set_wrapper_reference_to, 288 'set_wrapper_reference_to': set_wrapper_reference_to,
289 'v8_class': v8_class_name, 289 'v8_class': v8_class_name,
290 'v8_class_or_partial': v8_class_name_or_partial, 290 'v8_class_or_partial': v8_class_name_or_partial,
291 'wrapper_class_id': wrapper_class_id, 291 'wrapper_class_id': wrapper_class_id,
292 } 292 }
293 293
294 # Constructors 294 # Constructors
295 constructors = [constructor_context(interface, constructor) 295 constructors = [constructor_context(interface, constructor)
296 for constructor in interface.constructors 296 for constructor in interface.constructors
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 includes.add('core/frame/LocalDOMWindow.h') 330 includes.add('core/frame/LocalDOMWindow.h')
331 elif 'Measure' in extended_attributes or 'MeasureAs' in extended_attributes: 331 elif 'Measure' in extended_attributes or 'MeasureAs' in extended_attributes:
332 if not interface.is_partial: 332 if not interface.is_partial:
333 raise Exception('[Measure] or [MeasureAs] specified for interface wi thout a constructor: ' 333 raise Exception('[Measure] or [MeasureAs] specified for interface wi thout a constructor: '
334 '%s' % interface.name) 334 '%s' % interface.name)
335 335
336 # [Unscopable] attributes and methods 336 # [Unscopable] attributes and methods
337 unscopables = [] 337 unscopables = []
338 for attribute in interface.attributes: 338 for attribute in interface.attributes:
339 if 'Unscopable' in attribute.extended_attributes: 339 if 'Unscopable' in attribute.extended_attributes:
340 unscopables.append((attribute.name, v8_utilities.runtime_enabled_fun ction_name(attribute))) 340 unscopables.append((attribute.name, runtime_enabled_feature_name(att ribute)))
341 for method in interface.operations: 341 for method in interface.operations:
342 if 'Unscopable' in method.extended_attributes: 342 if 'Unscopable' in method.extended_attributes:
343 unscopables.append((method.name, v8_utilities.runtime_enabled_functi on_name(method))) 343 unscopables.append((method.name, runtime_enabled_feature_name(method )))
344 344
345 # [CEReactions] 345 # [CEReactions]
346 setter_or_deleters = ( 346 setter_or_deleters = (
347 interface.indexed_property_setter, 347 interface.indexed_property_setter,
348 interface.indexed_property_deleter, 348 interface.indexed_property_deleter,
349 interface.named_property_setter, 349 interface.named_property_setter,
350 interface.named_property_deleter, 350 interface.named_property_deleter,
351 ) 351 )
352 has_ce_reactions = any(setter_or_deleter and 'CEReactions' in setter_or_dele ter.extended_attributes 352 has_ce_reactions = any(setter_or_deleter and 'CEReactions' in setter_or_dele ter.extended_attributes
353 for setter_or_deleter in setter_or_deleters) 353 for setter_or_deleter in setter_or_deleters)
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 return { 714 return {
715 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), 715 'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'),
716 'deprecate_as': v8_utilities.deprecate_as(constant), # [DeprecateAs] 716 'deprecate_as': v8_utilities.deprecate_as(constant), # [DeprecateAs]
717 'idl_type': constant.idl_type.name, 717 'idl_type': constant.idl_type.name,
718 'measure_as': v8_utilities.measure_as(constant, interface), # [MeasureA s] 718 'measure_as': v8_utilities.measure_as(constant, interface), # [MeasureA s]
719 'name': constant.name, 719 'name': constant.name,
720 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_funct ion_name(constant), # [OriginTrialEnabled] 720 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_funct ion_name(constant), # [OriginTrialEnabled]
721 'origin_trial_feature_name': v8_utilities.origin_trial_feature_name(cons tant), # [OriginTrialEnabled] 721 'origin_trial_feature_name': v8_utilities.origin_trial_feature_name(cons tant), # [OriginTrialEnabled]
722 # FIXME: use 'reflected_name' as correct 'name' 722 # FIXME: use 'reflected_name' as correct 'name'
723 'reflected_name': extended_attributes.get('Reflect', reflected_name(cons tant.name)), 723 'reflected_name': extended_attributes.get('Reflect', reflected_name(cons tant.name)),
724 'runtime_enabled_function': runtime_enabled_function_name(constant), # [RuntimeEnabled] 724 'runtime_enabled_feature_name': runtime_enabled_feature_name(constant), # [RuntimeEnabled]
725 'runtime_feature_name': v8_utilities.runtime_feature_name(constant), # [RuntimeEnabled]
726 'value': constant.value, 725 'value': constant.value,
727 } 726 }
728 727
729 728
730 ################################################################################ 729 ################################################################################
731 # Overloads 730 # Overloads
732 ################################################################################ 731 ################################################################################
733 732
734 def compute_method_overloads_context(interface, methods): 733 def compute_method_overloads_context(interface, methods):
735 # Regular methods 734 # Regular methods
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 lengths = [length for length, _ in effective_overloads_by_length] 792 lengths = [length for length, _ in effective_overloads_by_length]
794 name = overloads[0].get('name', '<constructor>') 793 name = overloads[0].get('name', '<constructor>')
795 794
796 runtime_determined_lengths = None 795 runtime_determined_lengths = None
797 function_length = lengths[0] 796 function_length = lengths[0]
798 runtime_determined_maxargs = None 797 runtime_determined_maxargs = None
799 maxarg = lengths[-1] 798 maxarg = lengths[-1]
800 799
801 # The special case handling below is not needed if all overloads are 800 # The special case handling below is not needed if all overloads are
802 # runtime enabled by the same feature. 801 # runtime enabled by the same feature.
803 if not common_value(overloads, 'runtime_enabled_function'): 802 if not common_value(overloads, 'runtime_enabled_feature_name'):
804 # Check if all overloads with the shortest acceptable arguments list are 803 # Check if all overloads with the shortest acceptable arguments list are
805 # runtime enabled, in which case we need to have a runtime determined 804 # runtime enabled, in which case we need to have a runtime determined
806 # Function.length. 805 # Function.length.
807 shortest_overloads = effective_overloads_by_length[0][1] 806 shortest_overloads = effective_overloads_by_length[0][1]
808 if (all(method.get('runtime_enabled_function') 807 if (all(method.get('runtime_enabled_feature_name')
809 for method, _, _ in shortest_overloads)): 808 for method, _, _ in shortest_overloads)):
810 # Generate a list of (length, runtime_enabled_functions) tuples. 809 # Generate a list of (length, runtime_enabled_feature_names) tuples.
811 runtime_determined_lengths = [] 810 runtime_determined_lengths = []
812 for length, effective_overloads in effective_overloads_by_length: 811 for length, effective_overloads in effective_overloads_by_length:
813 runtime_enabled_functions = set( 812 runtime_enabled_feature_names = set(
814 method['runtime_enabled_function'] 813 method['runtime_enabled_feature_name']
815 for method, _, _ in effective_overloads 814 for method, _, _ in effective_overloads
816 if method.get('runtime_enabled_function')) 815 if method.get('runtime_enabled_feature_name'))
817 if not runtime_enabled_functions: 816 if not runtime_enabled_feature_names:
818 # This "length" is unconditionally enabled, so stop here. 817 # This "length" is unconditionally enabled, so stop here.
819 runtime_determined_lengths.append((length, [None])) 818 runtime_determined_lengths.append((length, [None]))
820 break 819 break
821 runtime_determined_lengths.append( 820 runtime_determined_lengths.append(
822 (length, sorted(runtime_enabled_functions))) 821 (length, sorted(runtime_enabled_feature_names)))
823 function_length = ('%sV8Internal::%sMethodLength()' 822 function_length = ('%sV8Internal::%sMethodLength()'
824 % (cpp_name_or_partial(interface), name)) 823 % (cpp_name_or_partial(interface), name))
825 824
826 # Check if all overloads with the longest required arguments list are 825 # Check if all overloads with the longest required arguments list are
827 # runtime enabled, in which case we need to have a runtime determined 826 # runtime enabled, in which case we need to have a runtime determined
828 # maximum distinguishing argument index. 827 # maximum distinguishing argument index.
829 longest_overloads = effective_overloads_by_length[-1][1] 828 longest_overloads = effective_overloads_by_length[-1][1]
830 if (not common_value(overloads, 'runtime_enabled_function') and 829 if (not common_value(overloads, 'runtime_enabled_feature_name') and
831 all(method.get('runtime_enabled_function') 830 all(method.get('runtime_enabled_feature_name')
832 for method, _, _ in longest_overloads)): 831 for method, _, _ in longest_overloads)):
833 # Generate a list of (length, runtime_enabled_functions) tuples. 832 # Generate a list of (length, runtime_enabled_feature_name) tuples.
834 runtime_determined_maxargs = [] 833 runtime_determined_maxargs = []
835 for length, effective_overloads in reversed(effective_overloads_by_l ength): 834 for length, effective_overloads in reversed(effective_overloads_by_l ength):
836 runtime_enabled_functions = set( 835 runtime_enabled_feature_names = set(
837 method['runtime_enabled_function'] 836 method['runtime_enabled_feature_name']
838 for method, _, _ in effective_overloads 837 for method, _, _ in effective_overloads
839 if method.get('runtime_enabled_function')) 838 if method.get('runtime_enabled_feature_name'))
840 if not runtime_enabled_functions: 839 if not runtime_enabled_feature_names:
841 # This "length" is unconditionally enabled, so stop here. 840 # This "length" is unconditionally enabled, so stop here.
842 runtime_determined_maxargs.append((length, [None])) 841 runtime_determined_maxargs.append((length, [None]))
843 break 842 break
844 runtime_determined_maxargs.append( 843 runtime_determined_maxargs.append(
845 (length, sorted(runtime_enabled_functions))) 844 (length, sorted(runtime_enabled_feature_names)))
846 maxarg = ('%sV8Internal::%sMethodMaxArg()' 845 maxarg = ('%sV8Internal::%sMethodMaxArg()'
847 % (cpp_name_or_partial(interface), name)) 846 % (cpp_name_or_partial(interface), name))
848 847
849 # Check and fail if overloads disagree about whether the return type 848 # Check and fail if overloads disagree about whether the return type
850 # is a Promise or not. 849 # is a Promise or not.
851 promise_overload_count = sum(1 for method in overloads if method.get('return s_promise')) 850 promise_overload_count = sum(1 for method in overloads if method.get('return s_promise'))
852 if promise_overload_count not in (0, len(overloads)): 851 if promise_overload_count not in (0, len(overloads)):
853 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes' 852 raise ValueError('Overloads of %s have conflicting Promise/non-Promise t ypes'
854 % (name)) 853 % (name))
855 854
(...skipping 16 matching lines...) Expand all
872 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ] 871 'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed ]
873 'length': function_length, 872 'length': function_length,
874 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), 873 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th),
875 # 1. Let maxarg be the length of the longest type list of the 874 # 1. Let maxarg be the length of the longest type list of the
876 # entries in S. 875 # entries in S.
877 'maxarg': maxarg, 876 'maxarg': maxarg,
878 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] 877 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs]
879 'returns_promise_all': promise_overload_count > 0, 878 'returns_promise_all': promise_overload_count > 0,
880 'runtime_determined_lengths': runtime_determined_lengths, 879 'runtime_determined_lengths': runtime_determined_lengths,
881 'runtime_determined_maxargs': runtime_determined_maxargs, 880 'runtime_determined_maxargs': runtime_determined_maxargs,
882 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled _function'), # [RuntimeEnabled] 881 'runtime_enabled_all': common_value(overloads, 'runtime_enabled_feature_ name'), # [RuntimeEnabled]
883 'secure_context_test_all': common_value(overloads, 'secure_context_test' ), # [SecureContext] 882 'secure_context_test_all': common_value(overloads, 'secure_context_test' ), # [SecureContext]
884 'valid_arities': (lengths 883 'valid_arities': (lengths
885 # Only need to report valid arities if there is a gap in the 884 # Only need to report valid arities if there is a gap in the
886 # sequence of possible lengths, otherwise invalid leng th means 885 # sequence of possible lengths, otherwise invalid leng th means
887 # "not enough arguments". 886 # "not enough arguments".
888 if lengths[-1] - lengths[0] != len(lengths) - 1 else N one), 887 if lengths[-1] - lengths[0] != len(lengths) - 1 else N one),
889 'visible': has_overload_visible, 888 'visible': has_overload_visible,
890 'has_partial_overloads': has_partial_overloads, 889 'has_partial_overloads': has_partial_overloads,
891 } 890 }
892 891
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 extended_attributes = deleter.extended_attributes 1496 extended_attributes = deleter.extended_attributes
1498 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState') 1497 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete r, 'CallWith', 'ScriptState')
1499 is_ce_reactions = 'CEReactions' in extended_attributes 1498 is_ce_reactions = 'CEReactions' in extended_attributes
1500 return { 1499 return {
1501 'is_call_with_script_state': is_call_with_script_state, 1500 'is_call_with_script_state': is_call_with_script_state,
1502 'is_ce_reactions': is_ce_reactions, 1501 'is_ce_reactions': is_ce_reactions,
1503 'is_custom': 'Custom' in extended_attributes, 1502 'is_custom': 'Custom' in extended_attributes,
1504 'is_raises_exception': 'RaisesException' in extended_attributes, 1503 'is_raises_exception': 'RaisesException' in extended_attributes,
1505 'name': cpp_name(deleter), 1504 'name': cpp_name(deleter),
1506 } 1505 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/scripts/v8_dictionary.py ('k') | third_party/WebKit/Source/bindings/scripts/v8_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698