in bindings/scripts/v8_interface.py [0:0]
def overloads_context(interface, overloads):
"""Returns |overloads| template values for a single name.
Sets |method.overload_index| in place for |method| in |overloads|
and returns dict of overall overload template values.
"""
assert len(overloads) > 1 # only apply to overloaded names
for index, method in enumerate(overloads, 1):
method['overload_index'] = index
# [OriginTrialEnabled]
# TODO(iclelland): Allow origin trials on method overloads
# (crbug.com/621641)
if any(method.get('origin_trial_feature_name') for method in overloads):
raise Exception('[OriginTrialEnabled] cannot be specified on '
'overloaded methods: %s.%s' % (interface.name, overloads[0]['name']))
effective_overloads_by_length = effective_overload_set_by_length(overloads)
lengths = [length for length, _ in effective_overloads_by_length]
name = overloads[0].get('name', '<constructor>')
runtime_determined_lengths = None
function_length = lengths[0]
runtime_determined_maxargs = None
maxarg = lengths[-1]
# The special case handling below is not needed if all overloads are
# runtime enabled by the same feature.
if not common_value(overloads, 'runtime_enabled_feature_name'):
# Check if all overloads with the shortest acceptable arguments list are
# runtime enabled, in which case we need to have a runtime determined
# Function.length.
shortest_overloads = effective_overloads_by_length[0][1]
if (all(method.get('runtime_enabled_feature_name')
for method, _, _ in shortest_overloads)):
# Generate a list of (length, runtime_enabled_feature_names) tuples.
runtime_determined_lengths = []
for length, effective_overloads in effective_overloads_by_length:
runtime_enabled_feature_names = set(
method['runtime_enabled_feature_name']
for method, _, _ in effective_overloads
if method.get('runtime_enabled_feature_name'))
if not runtime_enabled_feature_names:
# This "length" is unconditionally enabled, so stop here.
runtime_determined_lengths.append((length, [None]))
break
runtime_determined_lengths.append(
(length, sorted(runtime_enabled_feature_names)))
function_length = ('%sV8Internal::%sMethodLength()'
% (cpp_name_or_partial(interface), name))
# Check if all overloads with the longest required arguments list are
# runtime enabled, in which case we need to have a runtime determined
# maximum distinguishing argument index.
longest_overloads = effective_overloads_by_length[-1][1]
if (not common_value(overloads, 'runtime_enabled_feature_name') and
all(method.get('runtime_enabled_feature_name')
for method, _, _ in longest_overloads)):
# Generate a list of (length, runtime_enabled_feature_name) tuples.
runtime_determined_maxargs = []
for length, effective_overloads in reversed(effective_overloads_by_length):
runtime_enabled_feature_names = set(
method['runtime_enabled_feature_name']
for method, _, _ in effective_overloads
if method.get('runtime_enabled_feature_name'))
if not runtime_enabled_feature_names:
# This "length" is unconditionally enabled, so stop here.
runtime_determined_maxargs.append((length, [None]))
break
runtime_determined_maxargs.append(
(length, sorted(runtime_enabled_feature_names)))
maxarg = ('%sV8Internal::%sMethodMaxArg()'
% (cpp_name_or_partial(interface), name))
# Check and fail if overloads disagree about whether the return type
# is a Promise or not.
promise_overload_count = sum(1 for method in overloads if method.get('returns_promise'))
if promise_overload_count not in (0, len(overloads)):
raise ValueError('Overloads of %s have conflicting Promise/non-Promise types'
% (name))
has_overload_visible = False
has_overload_not_visible = False
for overload in overloads:
if overload.get('visible', True):
# If there exists an overload which is visible, need to generate
# overload_resolution, i.e. overlods_visible should be True.
has_overload_visible = True
else:
has_overload_not_visible = True
# If some overloads are not visible and others are visible,
# the method is overloaded between core and modules.
has_partial_overloads = has_overload_visible and has_overload_not_visible
return {
'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [DeprecateAs]
'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed]
'length': function_length,
'length_tests_methods': length_tests_methods(effective_overloads_by_length),
# 1. Let maxarg be the length of the longest type list of the
# entries in S.
'maxarg': maxarg,
'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs]
'returns_promise_all': promise_overload_count > 0,
'runtime_determined_lengths': runtime_determined_lengths,
'runtime_determined_maxargs': runtime_determined_maxargs,
'runtime_enabled_all': common_value(overloads, 'runtime_enabled_feature_name'), # [RuntimeEnabled]
'secure_context_test_all': common_value(overloads, 'secure_context_test'), # [SecureContext]
'valid_arities': (lengths
# Only need to report valid arities if there is a gap in the
# sequence of possible lengths, otherwise invalid length means
# "not enough arguments".
if lengths[-1] - lengths[0] != len(lengths) - 1 else None),
'visible': has_overload_visible,
'has_partial_overloads': has_partial_overloads,
}