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

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

Issue 296403007: Set correct Function.length on overloaded methods (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed nits Created 6 years, 6 months 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 for method in interface.operations 250 for method in interface.operations
251 if method.name] # Skip anonymous special operations (methods) 251 if method.name] # Skip anonymous special operations (methods)
252 generate_method_overloads(methods) 252 generate_method_overloads(methods)
253 for method in methods: 253 for method in methods:
254 method['do_generate_method_configuration'] = ( 254 method['do_generate_method_configuration'] = (
255 method['do_not_check_signature'] and 255 method['do_not_check_signature'] and
256 not method['per_context_enabled_function'] and 256 not method['per_context_enabled_function'] and
257 # For overloaded methods, only generate one accessor 257 # For overloaded methods, only generate one accessor
258 ('overload_index' not in method or method['overload_index'] == 1)) 258 ('overload_index' not in method or method['overload_index'] == 1))
259 259
260 # The value of the Function object’s “length” property is a Number
261 # determined as follows:
262 # 1. Let S be the effective overload set for regular operations (if the
263 # operation is a regular operation) or for static operations (if the
264 # operation is a static operation) with identifier id on interface I and
265 # with argument count 0.
266 # 2. Return the length of the shortest argument list of the entries in S .
267 # FIXME: This calculation doesn't take into account whether runtime
268 # enabled overloads are actually enabled, so length may be incorrect.
269 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x);
270 # should have length 1 if Foo is not enabled, but length 0 if it is.
271 method['length'] = (method['overloads']['minarg'] if 'overloads' in meth od else
272 method['number_of_required_arguments'])
273
260 template_contents.update({ 274 template_contents.update({
261 'has_origin_safe_method_setter': any( 275 'has_origin_safe_method_setter': any(
262 method['is_check_security_for_frame'] and not method['is_read_only'] 276 method['is_check_security_for_frame'] and not method['is_read_only']
263 for method in methods), 277 for method in methods),
264 'has_method_configuration': any(method['do_generate_method_configuration '] for method in methods), 278 'has_method_configuration': any(method['do_generate_method_configuration '] for method in methods),
265 'has_per_context_enabled_methods': any(method['per_context_enabled_funct ion'] for method in methods), 279 'has_per_context_enabled_methods': any(method['per_context_enabled_funct ion'] for method in methods),
266 'methods': methods, 280 'methods': methods,
267 }) 281 })
268 282
269 template_contents.update({ 283 template_contents.update({
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 Sets |method.overload_index| in place for |method| in |overloads| 364 Sets |method.overload_index| in place for |method| in |overloads|
351 and returns dict of overall overload template values. 365 and returns dict of overall overload template values.
352 """ 366 """
353 assert len(overloads) > 1 # only apply to overloaded names 367 assert len(overloads) > 1 # only apply to overloaded names
354 for index, method in enumerate(overloads, 1): 368 for index, method in enumerate(overloads, 1):
355 method['overload_index'] = index 369 method['overload_index'] = index
356 370
357 effective_overloads_by_length = effective_overload_set_by_length(overloads) 371 effective_overloads_by_length = effective_overload_set_by_length(overloads)
358 lengths = [length for length, _ in effective_overloads_by_length] 372 lengths = [length for length, _ in effective_overloads_by_length]
359 373
374 # Check and fail if all overloads with the shortest acceptable arguments
375 # list are runtime enabled, since we would otherwise set 'length' on the
376 # function object to an incorrect value when none of those overloads were
377 # actually enabled at runtime. The exception is if all overloads are
378 # controlled by the same runtime enabled feature, in which case there would
379 # be no function object at all if it is not enabled.
380 shortest_overloads = effective_overloads_by_length[0][1]
381 if (all(method.get('runtime_enabled_function')
382 for method, _, _ in shortest_overloads) and
383 not common_value(overloads, 'runtime_enabled_function')):
384 raise ValueError('Function.length of %s depends on runtime enabled featu res' % overloads[0]['name'])
385
360 return { 386 return {
361 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs] 387 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs]
362 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), 388 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th),
363 'minarg': lengths[0], 389 'minarg': lengths[0],
364 # 1. Let maxarg be the length of the longest type list of the 390 # 1. Let maxarg be the length of the longest type list of the
365 # entries in S. 391 # entries in S.
366 'maxarg': lengths[-1], 392 'maxarg': lengths[-1],
367 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] 393 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs]
368 'valid_arities': lengths 394 'valid_arities': lengths
369 # Only need to report valid arities if there is a gap in the 395 # Only need to report valid arities if there is a gap in the
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 deleter = next( 1033 deleter = next(
1008 method 1034 method
1009 for method in interface.operations 1035 for method in interface.operations
1010 if ('deleter' in method.specials and 1036 if ('deleter' in method.specials and
1011 len(method.arguments) == 1 and 1037 len(method.arguments) == 1 and
1012 str(method.arguments[0].idl_type) == 'DOMString')) 1038 str(method.arguments[0].idl_type) == 'DOMString'))
1013 except StopIteration: 1039 except StopIteration:
1014 return None 1040 return None
1015 1041
1016 return property_deleter(deleter) 1042 return property_deleter(deleter)
OLDNEW
« no previous file with comments | « LayoutTests/fast/js/function-length-expected.txt ('k') | Source/bindings/templates/interface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698