| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 checks.append('(%s is %s || %s == null)' % ( | 256 checks.append('(%s is %s || %s == null)' % ( |
| 257 parameter_name, test_type, parameter_name)) | 257 parameter_name, test_type, parameter_name)) |
| 258 # There can be multiple presence checks. We need them all since a later | 258 # There can be multiple presence checks. We need them all since a later |
| 259 # optional argument could have been passed by name, leaving 'holes'. | 259 # optional argument could have been passed by name, leaving 'holes'. |
| 260 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]]
) | 260 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]]
) |
| 261 | 261 |
| 262 GenerateCall(signature_index, argument_count, checks) | 262 GenerateCall(signature_index, argument_count, checks) |
| 263 | 263 |
| 264 # TODO: Optimize the dispatch to avoid repeated checks. | 264 # TODO: Optimize the dispatch to avoid repeated checks. |
| 265 if len(signatures) > 1: | 265 if len(signatures) > 1: |
| 266 swapped = False |
| 267 for signature_index, signature in enumerate(signatures): |
| 268 for argument_position, argument in enumerate(signature): |
| 269 if argument.type.id != 'ArrayBuffer': |
| 270 continue |
| 271 candidates = enumerate( |
| 272 signatures[signature_index + 1:], signature_index + 1) |
| 273 for candidate_index, candidate in candidates: |
| 274 if len(candidate) <= argument_position: |
| 275 continue |
| 276 if candidate[argument_position].type.id != 'ArrayBufferView': |
| 277 continue |
| 278 if swapped: |
| 279 raise Exception('Cannot deal with more than a single swap') |
| 280 swapped = True |
| 281 signatures = signatures[:] |
| 282 signatures[candidate_index], signatures[signature_index] =\ |
| 283 signature, candidate |
| 284 |
| 266 for signature_index, signature in enumerate(signatures): | 285 for signature_index, signature in enumerate(signatures): |
| 267 for argument_position, argument in enumerate(signature): | 286 for argument_position, argument in enumerate(signature): |
| 268 if is_optional(signature_index, argument): | 287 if is_optional(signature_index, argument): |
| 269 GenerateChecksAndCall(signature_index, argument_position) | 288 GenerateChecksAndCall(signature_index, argument_position) |
| 270 GenerateChecksAndCall(signature_index, len(signature)) | 289 GenerateChecksAndCall(signature_index, len(signature)) |
| 271 body_emitter.Emit( | 290 body_emitter.Emit( |
| 272 ' throw new ArgumentError("Incorrect number or type of arguments");
' | 291 ' throw new ArgumentError("Incorrect number or type of arguments");
' |
| 273 '\n'); | 292 '\n'); |
| 274 else: | 293 else: |
| 275 signature = signatures[0] | 294 signature = signatures[0] |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 walk(interface.parents) | 641 walk(interface.parents) |
| 623 else: | 642 else: |
| 624 walk(interface.parents[1:]) | 643 walk(interface.parents[1:]) |
| 625 return result | 644 return result |
| 626 | 645 |
| 627 def _DartType(self, type_name): | 646 def _DartType(self, type_name): |
| 628 return self._type_registry.DartType(type_name) | 647 return self._type_registry.DartType(type_name) |
| 629 | 648 |
| 630 def _IsPrivate(self, name): | 649 def _IsPrivate(self, name): |
| 631 return name.startswith('_') | 650 return name.startswith('_') |
| OLD | NEW |