| 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 monitored | 10 import monitored |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 # interface Y extends X, List<T> ... | 664 # interface Y extends X, List<T> ... |
| 665 # | 665 # |
| 666 # In the non-root case we have to choose between: | 666 # In the non-root case we have to choose between: |
| 667 # | 667 # |
| 668 # class YImpl extends XImpl { add List<T> methods; } | 668 # class YImpl extends XImpl { add List<T> methods; } |
| 669 # | 669 # |
| 670 # and | 670 # and |
| 671 # | 671 # |
| 672 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } | 672 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } |
| 673 # | 673 # |
| 674 self._members_emitter.Emit( | 674 |
| 675 '\n' | 675 ext_attrs = self._interface.ext_attrs |
| 676 ' $TYPE operator[](int index) => JS("$TYPE", "#[#]", this, index);\n', | 676 has_indexed_getter = ('IndexedGetter' in ext_attrs or |
| 677 TYPE=self.SecureOutputType(element_type)) | 677 'CustomIndexedSetter' in ext_attrs) |
| 678 |
| 679 if has_indexed_getter: |
| 680 self._members_emitter.Emit( |
| 681 '\n' |
| 682 ' $TYPE operator[](int index) => ' |
| 683 'JS("$TYPE", "#[#]", this, index);\n', |
| 684 TYPE=self.SecureOutputType(element_type)) |
| 685 else: |
| 686 if any(op.id == 'getItem' for op in self._interface.operations): |
| 687 indexed_getter = 'this.getItem(index)' |
| 688 elif any(op.id == 'item' for op in self._interface.operations): |
| 689 indexed_getter = 'this.item(index)' |
| 690 self._members_emitter.Emit( |
| 691 '\n' |
| 692 ' $TYPE operator[](int index) => $INDEXED_GETTER;\n', |
| 693 INDEXED_GETTER=indexed_getter, |
| 694 TYPE=self.SecureOutputType(element_type)) |
| 678 | 695 |
| 679 if 'CustomIndexedSetter' in self._interface.ext_attrs: | 696 if 'CustomIndexedSetter' in self._interface.ext_attrs: |
| 680 self._members_emitter.Emit( | 697 self._members_emitter.Emit( |
| 681 '\n' | 698 '\n' |
| 682 ' void operator[]=(int index, $TYPE value) {' | 699 ' void operator[]=(int index, $TYPE value) {' |
| 683 ' JS("void", "#[#] = #", this, index, value); }', | 700 ' JS("void", "#[#] = #", this, index, value); }', |
| 684 TYPE=self._NarrowInputType(element_type)) | 701 TYPE=self._NarrowInputType(element_type)) |
| 685 else: | 702 else: |
| 686 self._members_emitter.Emit( | 703 self._members_emitter.Emit( |
| 687 '\n' | 704 '\n' |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 for library_name in libraries: | 1135 for library_name in libraries: |
| 1119 self._libraries[library_name] = DartLibrary( | 1136 self._libraries[library_name] = DartLibrary( |
| 1120 library_name, template_loader, library_type, output_dir) | 1137 library_name, template_loader, library_type, output_dir) |
| 1121 | 1138 |
| 1122 def AddFile(self, basename, library_name, path): | 1139 def AddFile(self, basename, library_name, path): |
| 1123 self._libraries[library_name].AddFile(path) | 1140 self._libraries[library_name].AddFile(path) |
| 1124 | 1141 |
| 1125 def Emit(self, emitter, auxiliary_dir): | 1142 def Emit(self, emitter, auxiliary_dir): |
| 1126 for lib in self._libraries.values(): | 1143 for lib in self._libraries.values(): |
| 1127 lib.Emit(emitter, auxiliary_dir) | 1144 lib.Emit(emitter, auxiliary_dir) |
| OLD | NEW |