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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 'has_constructor_attributes': any(attribute['constructor_type'] for attr ibute in attributes), | 243 'has_constructor_attributes': any(attribute['constructor_type'] for attr ibute in attributes), |
244 'has_per_context_enabled_attributes': any(attribute['per_context_enabled _function'] for attribute in attributes), | 244 'has_per_context_enabled_attributes': any(attribute['per_context_enabled _function'] for attribute in attributes), |
245 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib ute in attributes), | 245 'has_replaceable_attributes': any(attribute['is_replaceable'] for attrib ute in attributes), |
246 }) | 246 }) |
247 | 247 |
248 # Methods | 248 # Methods |
249 methods = [v8_methods.generate_method(interface, method) | 249 methods = [v8_methods.generate_method(interface, method) |
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 | |
254 per_context_enabled_methods = [] | |
255 custom_registration_methods = [] | |
256 method_configuration_methods = [] | |
257 | |
253 for method in methods: | 258 for method in methods: |
254 method['do_generate_method_configuration'] = ( | 259 # Skip all but one method in each set of overloaded methods. |
255 method['do_not_check_signature'] and | 260 if 'overload_index' in method and 'overloads' not in method: |
256 not method['per_context_enabled_function'] and | 261 continue |
257 # For overloaded methods, only generate one accessor | |
258 ('overload_index' not in method or method['overload_index'] == 1)) | |
259 | 262 |
263 if 'overloads' in method: | |
264 overloads = method['overloads'] | |
265 per_context_enabled_function = overloads['per_context_enabled_functi on_all'] | |
266 runtime_enabled_function = overloads['runtime_enabled_function_all'] | |
267 has_custom_registration = overloads['has_custom_registration_all'] | |
268 else: | |
269 per_context_enabled_function = method['per_context_enabled_function' ] | |
270 runtime_enabled_function = method['runtime_enabled_function'] | |
271 has_custom_registration = method['has_custom_registration'] | |
272 | |
273 if per_context_enabled_function: | |
274 per_context_enabled_methods.append(method) | |
275 continue | |
276 if runtime_enabled_function or has_custom_registration: | |
277 custom_registration_methods.append(method) | |
278 continue | |
279 method_configuration_methods.append(method) | |
280 | |
281 for method in methods: | |
260 # The value of the Function object’s “length” property is a Number | 282 # The value of the Function object’s “length” property is a Number |
261 # determined as follows: | 283 # determined as follows: |
262 # 1. Let S be the effective overload set for regular operations (if the | 284 # 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 | 285 # operation is a regular operation) or for static operations (if the |
264 # operation is a static operation) with identifier id on interface I and | 286 # operation is a static operation) with identifier id on interface I and |
265 # with argument count 0. | 287 # with argument count 0. |
266 # 2. Return the length of the shortest argument list of the entries in S . | 288 # 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 | 289 # FIXME: This calculation doesn't take into account whether runtime |
268 # enabled overloads are actually enabled, so length may be incorrect. | 290 # enabled overloads are actually enabled, so length may be incorrect. |
269 # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); | 291 # 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. | 292 # 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 | 293 method['length'] = (method['overloads']['minarg'] if 'overloads' in meth od else |
272 method['number_of_required_arguments']) | 294 method['number_of_required_arguments']) |
273 | 295 |
274 template_contents.update({ | 296 template_contents.update({ |
297 'custom_registration_methods': custom_registration_methods, | |
275 'has_origin_safe_method_setter': any( | 298 'has_origin_safe_method_setter': any( |
276 method['is_check_security_for_frame'] and not method['is_read_only'] | 299 method['is_check_security_for_frame'] and not method['is_read_only'] |
277 for method in methods), | 300 for method in methods), |
278 'has_method_configuration': any(method['do_generate_method_configuration '] for method in methods), | 301 'method_configuration_methods': method_configuration_methods, |
279 'has_per_context_enabled_methods': any(method['per_context_enabled_funct ion'] for method in methods), | 302 'per_context_enabled_methods': per_context_enabled_methods, |
280 'methods': methods, | 303 'methods': methods, |
281 }) | 304 }) |
282 | 305 |
283 template_contents.update({ | 306 template_contents.update({ |
284 'indexed_property_getter': indexed_property_getter(interface), | 307 'indexed_property_getter': indexed_property_getter(interface), |
285 'indexed_property_setter': indexed_property_setter(interface), | 308 'indexed_property_setter': indexed_property_setter(interface), |
286 'indexed_property_deleter': indexed_property_deleter(interface), | 309 'indexed_property_deleter': indexed_property_deleter(interface), |
287 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, | 310 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, |
288 'named_property_getter': named_property_getter(interface), | 311 'named_property_getter': named_property_getter(interface), |
289 'named_property_setter': named_property_setter(interface), | 312 'named_property_setter': named_property_setter(interface), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 # function object to an incorrect value when none of those overloads were | 399 # function object to an incorrect value when none of those overloads were |
377 # actually enabled at runtime. The exception is if all overloads are | 400 # actually enabled at runtime. The exception is if all overloads are |
378 # controlled by the same runtime enabled feature, in which case there would | 401 # controlled by the same runtime enabled feature, in which case there would |
379 # be no function object at all if it is not enabled. | 402 # be no function object at all if it is not enabled. |
380 shortest_overloads = effective_overloads_by_length[0][1] | 403 shortest_overloads = effective_overloads_by_length[0][1] |
381 if (all(method.get('runtime_enabled_function') | 404 if (all(method.get('runtime_enabled_function') |
382 for method, _, _ in shortest_overloads) and | 405 for method, _, _ in shortest_overloads) and |
383 not common_value(overloads, 'runtime_enabled_function')): | 406 not common_value(overloads, 'runtime_enabled_function')): |
384 raise ValueError('Function.length of %s depends on runtime enabled featu res' % overloads[0]['name']) | 407 raise ValueError('Function.length of %s depends on runtime enabled featu res' % overloads[0]['name']) |
385 | 408 |
409 # Check and fail if overloads disagree on any of the extended attributes | |
410 # that affect how the method should be registered. | |
411 # Skip the check for overloaded constructors, since they don't support any | |
412 # of the extended attributes in question. | |
413 if not overloads[0].get('is_constructor'): | |
Nils Barth (inactive)
2014/06/11 10:10:28
nit: Normally we'd combine these into a single boo
| |
414 if (common_value(overloads, 'is_do_not_check_security') is None or | |
Nils Barth (inactive)
2014/06/11 10:10:28
This is a bit indirect and hence fragile, going vi
Jens Widell
2014/06/11 10:20:57
Sounds good, except at this point I only have what
| |
415 common_value(overloads, 'is_do_not_check_signature') is None or | |
416 common_value(overloads, 'property_attributes') is None): | |
417 raise ValueError('Overloads of %s have conflicting extended attribut es' % overloads[0]['name']) | |
Nils Barth (inactive)
2014/06/11 10:10:28
Could you factor out a helper variable:
name = ove
| |
418 | |
386 return { | 419 return { |
387 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs] | 420 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [Depreca teAs] |
388 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), | 421 'length_tests_methods': length_tests_methods(effective_overloads_by_leng th), |
389 'minarg': lengths[0], | 422 'minarg': lengths[0], |
390 # 1. Let maxarg be the length of the longest type list of the | 423 # 1. Let maxarg be the length of the longest type list of the |
391 # entries in S. | 424 # entries in S. |
392 'maxarg': lengths[-1], | 425 'maxarg': lengths[-1], |
393 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] | 426 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs] |
427 'has_custom_registration_all': common_value(overloads, 'has_custom_regis tration'), | |
428 'per_context_enabled_function_all': common_value(overloads, 'per_context _enabled_function'), # [PerContextEnabled] | |
429 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled _function'), # [RuntimeEnabled] | |
394 'valid_arities': lengths | 430 'valid_arities': lengths |
395 # Only need to report valid arities if there is a gap in the | 431 # Only need to report valid arities if there is a gap in the |
396 # sequence of possible lengths, otherwise invalid length means | 432 # sequence of possible lengths, otherwise invalid length means |
397 # "not enough arguments". | 433 # "not enough arguments". |
398 if lengths[-1] - lengths[0] != len(lengths) - 1 else None, | 434 if lengths[-1] - lengths[0] != len(lengths) - 1 else None, |
399 } | 435 } |
400 | 436 |
401 | 437 |
402 def effective_overload_set(F): | 438 def effective_overload_set(F): |
403 """Returns the effective overload set of an overloaded function. | 439 """Returns the effective overload set of an overloaded function. |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1033 deleter = next( | 1069 deleter = next( |
1034 method | 1070 method |
1035 for method in interface.operations | 1071 for method in interface.operations |
1036 if ('deleter' in method.specials and | 1072 if ('deleter' in method.specials and |
1037 len(method.arguments) == 1 and | 1073 len(method.arguments) == 1 and |
1038 str(method.arguments[0].idl_type) == 'DOMString')) | 1074 str(method.arguments[0].idl_type) == 'DOMString')) |
1039 except StopIteration: | 1075 except StopIteration: |
1040 return None | 1076 return None |
1041 | 1077 |
1042 return property_deleter(deleter) | 1078 return property_deleter(deleter) |
OLD | NEW |