| 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 import os | 10 import os |
| (...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 checks = ['!?%s' % name for name in parameter_names] | 977 checks = ['!?%s' % name for name in parameter_names] |
| 978 for i in range(0, argument_count): | 978 for i in range(0, argument_count): |
| 979 argument = operation.arguments[i] | 979 argument = operation.arguments[i] |
| 980 parameter_name = parameter_names[i] | 980 parameter_name = parameter_names[i] |
| 981 test_type = self._DartType(argument.type.id) | 981 test_type = self._DartType(argument.type.id) |
| 982 if test_type in ['Dynamic', 'Object']: | 982 if test_type in ['Dynamic', 'Object']: |
| 983 checks[i] = '?%s' % parameter_name | 983 checks[i] = '?%s' % parameter_name |
| 984 elif test_type == parameter_types[i]: | 984 elif test_type == parameter_types[i]: |
| 985 checks[i] = 'true' | 985 checks[i] = 'true' |
| 986 else: | 986 else: |
| 987 checks[i] = '(%s is %s || %s === null)' % ( | 987 checks[i] = '(%s is %s || %s == null)' % ( |
| 988 parameter_name, test_type, parameter_name) | 988 parameter_name, test_type, parameter_name) |
| 989 # There can be multiple presence checks. We need them all since a later | 989 # There can be multiple presence checks. We need them all since a later |
| 990 # optional argument could have been passed by name, leaving 'holes'. | 990 # optional argument could have been passed by name, leaving 'holes'. |
| 991 GenerateCall(operation, argument_count, checks) | 991 GenerateCall(operation, argument_count, checks) |
| 992 | 992 |
| 993 # TODO: Optimize the dispatch to avoid repeated checks. | 993 # TODO: Optimize the dispatch to avoid repeated checks. |
| 994 if len(operations) > 1: | 994 if len(operations) > 1: |
| 995 for operation in operations: | 995 for operation in operations: |
| 996 for position, argument in enumerate(operation.arguments): | 996 for position, argument in enumerate(operation.arguments): |
| 997 if self._IsOptional(operation, argument): | 997 if self._IsOptional(operation, argument): |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 | 1114 |
| 1115 library_emitter = self._multiemitter.FileEmitter(library_file_path) | 1115 library_emitter = self._multiemitter.FileEmitter(library_file_path) |
| 1116 library_file_dir = os.path.dirname(library_file_path) | 1116 library_file_dir = os.path.dirname(library_file_path) |
| 1117 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) | 1117 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) |
| 1118 imports_emitter = library_emitter.Emit( | 1118 imports_emitter = library_emitter.Emit( |
| 1119 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) | 1119 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) |
| 1120 for path in sorted(self._path_to_emitter.keys()): | 1120 for path in sorted(self._path_to_emitter.keys()): |
| 1121 relpath = os.path.relpath(path, library_file_dir) | 1121 relpath = os.path.relpath(path, library_file_dir) |
| 1122 imports_emitter.Emit( | 1122 imports_emitter.Emit( |
| 1123 "#source('$PATH');\n", PATH=massage_path(relpath)) | 1123 "#source('$PATH');\n", PATH=massage_path(relpath)) |
| OLD | NEW |