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 systems to generate | 6 """This module provides shared functionality for the systems to generate |
7 native binding from the IDL database.""" | 7 native binding from the IDL database.""" |
8 | 8 |
9 import emitter | 9 import emitter |
10 import logging | 10 import logging |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 # Unwrap the type to get the JsObject if Type is: | 541 # Unwrap the type to get the JsObject if Type is: |
542 # | 542 # |
543 # - known IDL type | 543 # - known IDL type |
544 # - type_id is None then it's probably a union type or overloaded | 544 # - type_id is None then it's probably a union type or overloaded |
545 # it's a dynamic/any type | 545 # it's a dynamic/any type |
546 # - type is Object | 546 # - type is Object |
547 # | 547 # |
548 # JsObject maybe stored in the Dart class. | 548 # JsObject maybe stored in the Dart class. |
549 return_wrap_jso = wrap_return_type_blink(return_type, attr.type.id, self
._type_registry) | 549 return_wrap_jso = wrap_return_type_blink(return_type, attr.type.id, self
._type_registry) |
550 wrap_unwrap_list.append(return_wrap_jso) # wrap_jso the returned objec
t | 550 wrap_unwrap_list.append(return_wrap_jso) # wrap_jso the returned objec
t |
551 wrap_unwrap_list.append(self._dart_use_blink) | 551 wrap_unwrap_list.append(self._dart_use_blink) |
552 | 552 |
553 # This seems to have been replaced with Custom=Getter (see above), but | 553 # This seems to have been replaced with Custom=Getter (see above), but |
554 # check to be sure we don't see the old syntax | 554 # check to be sure we don't see the old syntax |
555 assert(not ('CustomGetter' in attr.ext_attrs)) | 555 assert(not ('CustomGetter' in attr.ext_attrs)) |
556 native_suffix = 'Getter' | 556 native_suffix = 'Getter' |
557 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) | 557 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) |
558 native_entry = \ | 558 native_entry = \ |
559 self.DeriveNativeEntry(attr.id, 'Getter', None) | 559 self.DeriveNativeEntry(attr.id, 'Getter', None) |
560 output_conversion = self._OutputConversion(attr.type.id, attr.id) | 560 output_conversion = self._OutputConversion(attr.type.id, attr.id) |
561 | 561 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 attr_name = attr.id | 631 attr_name = attr.id |
632 webcore_function_name = re.sub(r'^(xml|css|(?=[A-Z])|\w)', | 632 webcore_function_name = re.sub(r'^(xml|css|(?=[A-Z])|\w)', |
633 lambda s: s.group(1).upper(), | 633 lambda s: s.group(1).upper(), |
634 attr_name) | 634 attr_name) |
635 webcore_function_name = 'set%s' % webcore_function_name | 635 webcore_function_name = 'set%s' % webcore_function_name |
636 | 636 |
637 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, attr) | 637 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi
on_name, attr) |
638 raises = ('RaisesException' in attr.ext_attrs and | 638 raises = ('RaisesException' in attr.ext_attrs and |
639 attr.ext_attrs['RaisesException'] != 'Getter') | 639 attr.ext_attrs['RaisesException'] != 'Getter') |
640 | 640 |
641 def AddIndexer(self, element_type): | 641 def AddIndexer(self, element_type, nullable): |
642 """Adds all the methods required to complete implementation of List.""" | 642 """Adds all the methods required to complete implementation of List.""" |
643 # We would like to simply inherit the implementation of everything except | 643 # We would like to simply inherit the implementation of everything except |
644 # length, [], and maybe []=. It is possible to extend from a base | 644 # length, [], and maybe []=. It is possible to extend from a base |
645 # array implementation class only when there is no other implementation | 645 # array implementation class only when there is no other implementation |
646 # inheritance. There might be no implementation inheritance other than | 646 # inheritance. There might be no implementation inheritance other than |
647 # DOMBaseWrapper for many classes, but there might be some where the | 647 # DOMBaseWrapper for many classes, but there might be some where the |
648 # array-ness is introduced by a non-root interface: | 648 # array-ness is introduced by a non-root interface: |
649 # | 649 # |
650 # interface Y extends X, List<T> ... | 650 # interface Y extends X, List<T> ... |
651 # | 651 # |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 if self._HasNativeIndexSetter(): | 702 if self._HasNativeIndexSetter(): |
703 self._EmitNativeIndexSetter(dart_element_type) | 703 self._EmitNativeIndexSetter(dart_element_type) |
704 else: | 704 else: |
705 self._members_emitter.Emit( | 705 self._members_emitter.Emit( |
706 '\n' | 706 '\n' |
707 ' void operator[]=(int index, $TYPE value) {\n' | 707 ' void operator[]=(int index, $TYPE value) {\n' |
708 ' throw new UnsupportedError("Cannot assign element of immutable Li
st.");\n' | 708 ' throw new UnsupportedError("Cannot assign element of immutable Li
st.");\n' |
709 ' }\n', | 709 ' }\n', |
710 TYPE=dart_element_type) | 710 TYPE=dart_element_type) |
711 | 711 |
712 self.EmitListMixin(dart_element_type) | 712 self.EmitListMixin(dart_element_type, nullable) |
713 | 713 |
714 def AmendIndexer(self, element_type): | 714 def AmendIndexer(self, element_type): |
715 # If interface is marked as having native indexed | 715 # If interface is marked as having native indexed |
716 # getter or setter, we must emit overrides as it's not | 716 # getter or setter, we must emit overrides as it's not |
717 # guaranteed that the corresponding methods in C++ would be | 717 # guaranteed that the corresponding methods in C++ would be |
718 # virtual. For example, as of time of writing, even though | 718 # virtual. For example, as of time of writing, even though |
719 # Uint8ClampedArray inherits from Uint8Array, ::set method | 719 # Uint8ClampedArray inherits from Uint8Array, ::set method |
720 # is not virtual and accessing it through Uint8Array pointer | 720 # is not virtual and accessing it through Uint8Array pointer |
721 # would lead to wrong semantics (modulo vs. clamping.) | 721 # would lead to wrong semantics (modulo vs. clamping.) |
722 dart_element_type = self._DartType(element_type) | 722 dart_element_type = self._DartType(element_type) |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 | 1248 |
1249 def _IsCustom(op_or_attr): | 1249 def _IsCustom(op_or_attr): |
1250 assert(isinstance(op_or_attr, IDLMember)) | 1250 assert(isinstance(op_or_attr, IDLMember)) |
1251 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr
s | 1251 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr
s |
1252 | 1252 |
1253 def _IsCustomValue(op_or_attr, value): | 1253 def _IsCustomValue(op_or_attr, value): |
1254 if _IsCustom(op_or_attr): | 1254 if _IsCustom(op_or_attr): |
1255 return op_or_attr.ext_attrs.get('Custom') == value \ | 1255 return op_or_attr.ext_attrs.get('Custom') == value \ |
1256 or op_or_attr.ext_attrs.get('DartCustom') == value | 1256 or op_or_attr.ext_attrs.get('DartCustom') == value |
1257 return False | 1257 return False |
OLD | NEW |