| 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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 for attr in self._interface.attributes) | 618 for attr in self._interface.attributes) |
| 619 | 619 |
| 620 template = self._template_loader.Load( | 620 template = self._template_loader.Load( |
| 621 template_file, | 621 template_file, |
| 622 { | 622 { |
| 623 'DEFINE_LENGTH_AS_NUM_ITEMS': not has_length and has_num_items, | 623 'DEFINE_LENGTH_AS_NUM_ITEMS': not has_length and has_num_items, |
| 624 'DEFINE_LENGTH_SETTER': not has_length_setter, | 624 'DEFINE_LENGTH_SETTER': not has_length_setter, |
| 625 }) | 625 }) |
| 626 self._members_emitter.Emit(template, E=element_name) | 626 self._members_emitter.Emit(template, E=element_name) |
| 627 | 627 |
| 628 def SecureOutputType(self, type_name, is_dart_type=False): | 628 def SecureOutputType(self, type_name, is_dart_type=False, |
| 629 can_narrow_type=False): |
| 629 """ Converts the type name to the secure type name for return types. | 630 """ Converts the type name to the secure type name for return types. |
| 631 Arguments: |
| 632 can_narrow_type - True if the output type can be narrowed further than |
| 633 what would be accepted for input, used to narrow num APIs down to double |
| 634 or int. |
| 630 """ | 635 """ |
| 631 if is_dart_type: | 636 if is_dart_type: |
| 632 dart_name = type_name | 637 dart_name = type_name |
| 633 else: | 638 else: |
| 634 dart_name = self._DartType(type_name) | 639 type_info = self._TypeInfo(type_name) |
| 640 dart_name = type_info.dart_type() |
| 641 if can_narrow_type and dart_name == 'num': |
| 642 dart_name = type_info.native_type() |
| 643 |
| 635 # We only need to secure Window. Only local History and Location are | 644 # We only need to secure Window. Only local History and Location are |
| 636 # returned in generated code. | 645 # returned in generated code. |
| 637 assert(dart_name != 'HistoryBase' and dart_name != 'LocationBase') | 646 assert(dart_name != 'HistoryBase' and dart_name != 'LocationBase') |
| 638 if dart_name == 'Window': | 647 if dart_name == 'Window': |
| 639 return _secure_base_types[dart_name] | 648 return _secure_base_types[dart_name] |
| 640 return dart_name | 649 return dart_name |
| 641 | 650 |
| 642 def SecureBaseName(self, type_name): | 651 def SecureBaseName(self, type_name): |
| 643 if type_name in _secure_base_types: | 652 if type_name in _secure_base_types: |
| 644 return _secure_base_types[type_name] | 653 return _secure_base_types[type_name] |
| 645 | 654 |
| 646 def _DartType(self, type_name): | 655 def _DartType(self, type_name): |
| 647 return self._type_registry.DartType(type_name) | 656 return self._type_registry.DartType(type_name) |
| 657 |
| 658 def _TypeInfo(self, type_name): |
| 659 return self._type_registry.TypeInfo(type_name) |
| OLD | NEW |