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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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. | |
Nils Barth (inactive)
2014/06/05 00:26:22
Could you elaborate slightly, giving an example?
E
| |
269 method['length'] = method['overloads']['minarg'] if 'overloads' in metho d else method['number_of_required_arguments'] | |
Nils Barth (inactive)
2014/06/05 00:26:22
Could you wrap this line?
| |
270 | |
260 template_contents.update({ | 271 template_contents.update({ |
261 'has_origin_safe_method_setter': any( | 272 'has_origin_safe_method_setter': any( |
262 method['is_check_security_for_frame'] and not method['is_read_only'] | 273 method['is_check_security_for_frame'] and not method['is_read_only'] |
263 for method in methods), | 274 for method in methods), |
264 'has_method_configuration': any(method['do_generate_method_configuration '] for method in methods), | 275 '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), | 276 'has_per_context_enabled_methods': any(method['per_context_enabled_funct ion'] for method in methods), |
266 'methods': methods, | 277 'methods': methods, |
267 }) | 278 }) |
268 | 279 |
269 template_contents.update({ | 280 template_contents.update({ |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 Sets |method.overload_index| in place for |method| in |overloads| | 361 Sets |method.overload_index| in place for |method| in |overloads| |
351 and returns dict of overall overload template values. | 362 and returns dict of overall overload template values. |
352 """ | 363 """ |
353 assert len(overloads) > 1 # only apply to overloaded names | 364 assert len(overloads) > 1 # only apply to overloaded names |
354 for index, method in enumerate(overloads, 1): | 365 for index, method in enumerate(overloads, 1): |
355 method['overload_index'] = index | 366 method['overload_index'] = index |
356 | 367 |
357 effective_overloads_by_length = effective_overload_set_by_length(overloads) | 368 effective_overloads_by_length = effective_overload_set_by_length(overloads) |
358 lengths = [length for length, _ in effective_overloads_by_length] | 369 lengths = [length for length, _ in effective_overloads_by_length] |
359 | 370 |
371 # Check and fail if all overloads with the shortest acceptable arguments | |
Nils Barth (inactive)
2014/06/05 00:26:22
Thanks, this is a great explanation!
| |
372 # list are runtime enabled, since we would otherwise set 'length' on the | |
373 # function object to an incorrect value when none of those overloads were | |
374 # actually enabled at runtime. The exception is if all overloads are | |
375 # controlled by the same runtime enabled feature, in which case there would | |
376 # be no function object at all if it is not enabled. | |
377 if (not common_value(overloads, 'runtime_enabled_function') and | |
378 all(method.get('runtime_enabled_function') for method, _, _ in effective _overloads_by_length[0][1])): | |
Nils Barth (inactive)
2014/06/05 00:26:22
Style points:
* Could you wrap this line?
* Could
| |
379 raise ValueError('Function.length of %s depends on runtime enabled featu res' % overloads[0]['name']) | |
380 | |
360 return { | 381 return { |
361 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs] | 382 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs] |
362 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), | 383 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), |
363 'minarg': lengths[0], | 384 'minarg': lengths[0], |
364 # 1. Let maxarg be the length of the longest type list of the | 385 # 1. Let maxarg be the length of the longest type list of the |
365 # entries in S. | 386 # entries in S. |
366 'maxarg': lengths[-1], | 387 'maxarg': lengths[-1], |
367 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] | 388 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] |
368 'valid_arities': lengths | 389 'valid_arities': lengths |
369 # Only need to report valid arities if there is a gap in the | 390 # 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 Loading... | |
1007 deleter = next( | 1028 deleter = next( |
1008 method | 1029 method |
1009 for method in interface.operations | 1030 for method in interface.operations |
1010 if ('deleter' in method.specials and | 1031 if ('deleter' in method.specials and |
1011 len(method.arguments) == 1 and | 1032 len(method.arguments) == 1 and |
1012 str(method.arguments[0].idl_type) == 'DOMString')) | 1033 str(method.arguments[0].idl_type) == 'DOMString')) |
1013 except StopIteration: | 1034 except StopIteration: |
1014 return None | 1035 return None |
1015 | 1036 |
1016 return property_deleter(deleter) | 1037 return property_deleter(deleter) |
OLD | NEW |