| 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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 ' $TYPE operator[](int index) => JS("$TYPE", "#[#]", this, index);\n', | 479 ' $TYPE operator[](int index) => JS("$TYPE", "#[#]", this, index);\n', |
| 480 TYPE=self.SecureOutputType(element_type)) | 480 TYPE=self.SecureOutputType(element_type)) |
| 481 | 481 |
| 482 if 'CustomIndexedSetter' in self._interface.ext_attrs: | 482 if 'CustomIndexedSetter' in self._interface.ext_attrs: |
| 483 self._members_emitter.Emit( | 483 self._members_emitter.Emit( |
| 484 '\n' | 484 '\n' |
| 485 ' void operator[]=(int index, $TYPE value) =>' | 485 ' void operator[]=(int index, $TYPE value) =>' |
| 486 ' JS("void", "#[#] = #", this, index, value);\n', | 486 ' JS("void", "#[#] = #", this, index, value);\n', |
| 487 TYPE=self._NarrowInputType(element_type)) | 487 TYPE=self._NarrowInputType(element_type)) |
| 488 else: | 488 else: |
| 489 # The HTML library implementation of NodeList has a custom indexed setter | 489 self._members_emitter.Emit( |
| 490 # implementation that uses the parent node the NodeList is associated | 490 '\n' |
| 491 # with if one is available. | 491 ' void operator[]=(int index, $TYPE value) {\n' |
| 492 if self._interface.id != 'NodeList': | 492 ' throw new UnsupportedError("Cannot assign element of immutable Li
st.");\n' |
| 493 self._members_emitter.Emit( | 493 ' }\n', |
| 494 '\n' | 494 TYPE=self._NarrowInputType(element_type)) |
| 495 ' void operator[]=(int index, $TYPE value) {\n' | |
| 496 ' throw new UnsupportedError("Cannot assign element of immutable
List.");\n' | |
| 497 ' }\n', | |
| 498 TYPE=self._NarrowInputType(element_type)) | |
| 499 | 495 |
| 500 # TODO(sra): Use separate mixins for mutable implementations of List<T>. | 496 # TODO(sra): Use separate mixins for mutable implementations of List<T>. |
| 501 # TODO(sra): Use separate mixins for typed array implementations of List<T>. | 497 # TODO(sra): Use separate mixins for typed array implementations of List<T>. |
| 502 if self._interface.id != 'NodeList': | 498 template_file = 'immutable_list_mixin.darttemplate' |
| 503 template_file = 'immutable_list_mixin.darttemplate' | 499 has_contains = any(op.id == 'contains' for op in self._interface.operations) |
| 504 has_contains = any(op.id == 'contains' for op in self._interface.operation
s) | 500 template = self._template_loader.Load( |
| 505 template = self._template_loader.Load( | 501 template_file, |
| 506 template_file, | 502 {'DEFINE_CONTAINS': not has_contains}) |
| 507 {'DEFINE_CONTAINS': not has_contains}) | 503 self._members_emitter.Emit(template, E=self._DartType(element_type)) |
| 508 self._members_emitter.Emit(template, E=self._DartType(element_type)) | |
| 509 | 504 |
| 510 def EmitAttribute(self, attribute, html_name, read_only): | 505 def EmitAttribute(self, attribute, html_name, read_only): |
| 511 if self._HasCustomImplementation(attribute.id): | 506 if self._HasCustomImplementation(attribute.id): |
| 512 return | 507 return |
| 513 | 508 |
| 514 if IsPureInterface(self._interface.id): | 509 if IsPureInterface(self._interface.id): |
| 515 self._AddInterfaceAttribute(attribute) | 510 self._AddInterfaceAttribute(attribute) |
| 516 return | 511 return |
| 517 | 512 |
| 518 if attribute.id != html_name: | 513 if attribute.id != html_name: |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 'svg': DartLibrary('svg', template_loader, library_type, output_dir), | 968 'svg': DartLibrary('svg', template_loader, library_type, output_dir), |
| 974 'html': DartLibrary('html', template_loader, library_type, output_dir), | 969 'html': DartLibrary('html', template_loader, library_type, output_dir), |
| 975 } | 970 } |
| 976 | 971 |
| 977 def AddFile(self, basename, library_name, path): | 972 def AddFile(self, basename, library_name, path): |
| 978 self._libraries[library_name].AddFile(path) | 973 self._libraries[library_name].AddFile(path) |
| 979 | 974 |
| 980 def Emit(self, emitter, auxiliary_dir): | 975 def Emit(self, emitter, auxiliary_dir): |
| 981 for lib in self._libraries.values(): | 976 for lib in self._libraries.values(): |
| 982 lib.Emit(emitter, auxiliary_dir) | 977 lib.Emit(emitter, auxiliary_dir) |
| OLD | NEW |