OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 """This module provides shared functionality for the system to generate | 6 """This module provides shared functionality for the system to generate |
7 dart:html APIs from the IDL database.""" | 7 dart:html APIs from the IDL database.""" |
8 | 8 |
9 import emitter | 9 import emitter |
10 from generator import AnalyzeOperation, ConstantOutputOrder, \ | 10 from generator import AnalyzeOperation, ConstantOutputOrder, \ |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 converts_null = \ | 413 converts_null = \ |
414 ('TreatNullAs' in argument.ext_attrs) or \ | 414 ('TreatNullAs' in argument.ext_attrs) or \ |
415 (argument.default_value is not None) or \ | 415 (argument.default_value is not None) or \ |
416 (argument.default_value_is_null) | 416 (argument.default_value_is_null) |
417 if argument.type.nullable or converts_null or not typechecked: | 417 if argument.type.nullable or converts_null or not typechecked: |
418 checks.append('(%s is %s || %s == null)' % ( | 418 checks.append('(%s is %s || %s == null)' % ( |
419 parameter_name, test_type, parameter_name)) | 419 parameter_name, test_type, parameter_name)) |
420 else: | 420 else: |
421 checks.append('(%s is %s)' % ( | 421 checks.append('(%s is %s)' % ( |
422 parameter_name, test_type)) | 422 parameter_name, test_type)) |
423 elif i >= number_of_required_in_dart: | 423 elif i >= number_of_required_in_dart and not argument.type.nullable: |
424 checks.append('%s != null' % parameter_name) | 424 checks.append('%s != null' % parameter_name) |
425 | 425 |
426 # There can be multiple presence checks. We need them all since a later | 426 # There can be multiple presence checks. We need them all since a later |
427 # optional argument could have been passed by name, leaving 'holes'. | 427 # optional argument could have been passed by name, leaving 'holes'. |
428 checks.extend(['%s == null' % name for name in parameter_names[argument_co
unt:]]) | 428 checks.extend(['%s == null' % name for name in parameter_names[argument_co
unt:]]) |
429 | 429 |
430 GenerateCall(signature_index, argument_count, checks) | 430 GenerateCall(signature_index, argument_count, checks) |
431 | 431 |
432 # TODO: Optimize the dispatch to avoid repeated checks. | 432 # TODO: Optimize the dispatch to avoid repeated checks. |
433 if len(signatures) > 1: | 433 if len(signatures) > 1: |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 def _InputType(self, type_name, info): | 888 def _InputType(self, type_name, info): |
889 conversion = self._InputConversion(type_name, info.declared_name) | 889 conversion = self._InputConversion(type_name, info.declared_name) |
890 if conversion: | 890 if conversion: |
891 return conversion.input_type | 891 return conversion.input_type |
892 else: | 892 else: |
893 # If typedef it's a union return dynamic. | 893 # If typedef it's a union return dynamic. |
894 if self._database.HasTypeDef(type_name): | 894 if self._database.HasTypeDef(type_name): |
895 return 'dynamic' | 895 return 'dynamic' |
896 else: | 896 else: |
897 return self._NarrowInputType(type_name) if type_name else 'dynamic' | 897 return self._NarrowInputType(type_name) if type_name else 'dynamic' |
OLD | NEW |