Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: tools/dom/scripts/systemhtml.py

Issue 21555003: Exposing native doubles as doubles when they are read-only or method return values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/dom/scripts/htmldartgenerator.py ('k') | tools/dom/scripts/systemnative.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 logging 10 import logging
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 if indexed_getter: 743 if indexed_getter:
744 self._members_emitter.Emit( 744 self._members_emitter.Emit(
745 '\n' 745 '\n'
746 ' $TYPE operator[](int index) {\n' 746 ' $TYPE operator[](int index) {\n'
747 ' if (JS("bool", "# >>> 0 !== # || # >= #", index,\n' 747 ' if (JS("bool", "# >>> 0 !== # || # >= #", index,\n'
748 ' index, index, length))\n' 748 ' index, index, length))\n'
749 ' throw new RangeError.range(index, 0, length);\n' 749 ' throw new RangeError.range(index, 0, length);\n'
750 ' return $INDEXED_GETTER;\n' 750 ' return $INDEXED_GETTER;\n'
751 ' }', 751 ' }',
752 INDEXED_GETTER=indexed_getter, 752 INDEXED_GETTER=indexed_getter,
753 TYPE=self.SecureOutputType(element_type)) 753 TYPE=self.SecureOutputType(element_type, False, True))
754 754
755 if 'CustomIndexedSetter' in self._interface.ext_attrs: 755 if 'CustomIndexedSetter' in self._interface.ext_attrs:
756 self._members_emitter.Emit( 756 self._members_emitter.Emit(
757 '\n' 757 '\n'
758 ' void operator[]=(int index, $TYPE value) {' 758 ' void operator[]=(int index, $TYPE value) {'
759 ' JS("void", "#[#] = #", this, index, value); }', 759 ' JS("void", "#[#] = #", this, index, value); }',
760 TYPE=self._NarrowInputType(element_type)) 760 TYPE=self._NarrowInputType(element_type))
761 else: 761 else:
762 self._members_emitter.Emit( 762 self._members_emitter.Emit(
763 '\n' 763 '\n'
(...skipping 24 matching lines...) Expand all
788 if read_only: 788 if read_only:
789 if attribute.type.id == super_attribute.type.id: 789 if attribute.type.id == super_attribute.type.id:
790 # Compatible attribute, use the superclass property. This works 790 # Compatible attribute, use the superclass property. This works
791 # because JavaScript will do its own dynamic dispatch. 791 # because JavaScript will do its own dynamic dispatch.
792 self._members_emitter.Emit( 792 self._members_emitter.Emit(
793 '\n' 793 '\n'
794 ' // Use implementation from $SUPER.\n' 794 ' // Use implementation from $SUPER.\n'
795 ' // final $TYPE $NAME;\n', 795 ' // final $TYPE $NAME;\n',
796 SUPER=super_attribute_interface, 796 SUPER=super_attribute_interface,
797 NAME=html_name, 797 NAME=html_name,
798 TYPE=self.SecureOutputType(attribute.type.id)) 798 TYPE=self.SecureOutputType(attribute.type.id, False, read_only))
799 return 799 return
800 self._members_emitter.Emit('\n // Shadowing definition.') 800 self._members_emitter.Emit('\n // Shadowing definition.')
801 self._AddAttributeUsingProperties(attribute, html_name, read_only) 801 self._AddAttributeUsingProperties(attribute, html_name, read_only)
802 return 802 return
803 803
804 # If the type has a conversion we need a getter or setter to contain the 804 # If the type has a conversion we need a getter or setter to contain the
805 # conversion code. 805 # conversion code.
806 if (self._OutputConversion(attribute.type.id, attribute.id) or 806 if (self._OutputConversion(attribute.type.id, attribute.id) or
807 self._InputConversion(attribute.type.id, attribute.id)): 807 self._InputConversion(attribute.type.id, attribute.id)):
808 self._AddAttributeUsingProperties(attribute, html_name, read_only) 808 self._AddAttributeUsingProperties(attribute, html_name, read_only)
809 return 809 return
810 810
811 output_type = self.SecureOutputType(attribute.type.id) 811 output_type = self.SecureOutputType(attribute.type.id, False, read_only)
812 input_type = self._NarrowInputType(attribute.type.id) 812 input_type = self._NarrowInputType(attribute.type.id)
813 metadata = self._Metadata(attribute.type.id, attribute.id, output_type) 813 metadata = self._Metadata(attribute.type.id, attribute.id, output_type)
814 rename = self._RenamingAnnotation(attribute.id, html_name) 814 rename = self._RenamingAnnotation(attribute.id, html_name)
815 if not read_only: 815 if not read_only:
816 self._members_emitter.Emit( 816 self._members_emitter.Emit(
817 '\n $RENAME$METADATA$TYPE $NAME;' 817 '\n $RENAME$METADATA$TYPE $NAME;'
818 '\n', 818 '\n',
819 RENAME=rename, 819 RENAME=rename,
820 METADATA=metadata, 820 METADATA=metadata,
821 NAME=html_name, 821 NAME=html_name,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 self._AddDirectNativeOperation(info, html_name) 931 self._AddDirectNativeOperation(info, html_name)
932 932
933 def _AddDirectNativeOperation(self, info, html_name): 933 def _AddDirectNativeOperation(self, info, html_name):
934 self._members_emitter.Emit( 934 self._members_emitter.Emit(
935 '\n' 935 '\n'
936 ' $RENAME$METADATA$MODIFIERS$TYPE $NAME($PARAMS) native;\n', 936 ' $RENAME$METADATA$MODIFIERS$TYPE $NAME($PARAMS) native;\n',
937 RENAME=self._RenamingAnnotation(info.declared_name, html_name), 937 RENAME=self._RenamingAnnotation(info.declared_name, html_name),
938 METADATA=self._Metadata(info.type_name, info.declared_name, 938 METADATA=self._Metadata(info.type_name, info.declared_name,
939 self.SecureOutputType(info.type_name)), 939 self.SecureOutputType(info.type_name)),
940 MODIFIERS='static ' if info.IsStatic() else '', 940 MODIFIERS='static ' if info.IsStatic() else '',
941 TYPE=self.SecureOutputType(info.type_name), 941 TYPE=self.SecureOutputType(info.type_name, False, True),
942 NAME=html_name, 942 NAME=html_name,
943 PARAMS=info.ParametersDeclaration(self._NarrowInputType)) 943 PARAMS=info.ParametersDeclaration(self._NarrowInputType))
944 944
945 def _AddOperationWithConversions(self, info, html_name): 945 def _AddOperationWithConversions(self, info, html_name):
946 # Assert all operations have same return type. 946 # Assert all operations have same return type.
947 assert len(set([op.type.id for op in info.operations])) == 1 947 assert len(set([op.type.id for op in info.operations])) == 1
948 output_conversion = self._OutputConversion(info.type_name, 948 output_conversion = self._OutputConversion(info.type_name,
949 info.declared_name) 949 info.declared_name)
950 if output_conversion: 950 if output_conversion:
951 return_type = output_conversion.output_type 951 return_type = output_conversion.output_type
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 operations, 1036 operations,
1037 declaration, 1037 declaration,
1038 GenerateCall, 1038 GenerateCall,
1039 lambda _, argument: IsOptional(argument), 1039 lambda _, argument: IsOptional(argument),
1040 can_omit_type_check=lambda type, pos: type == parameter_types[pos]) 1040 can_omit_type_check=lambda type, pos: type == parameter_types[pos])
1041 1041
1042 def _AddInterfaceOperation(self, info, html_name): 1042 def _AddInterfaceOperation(self, info, html_name):
1043 self._members_emitter.Emit( 1043 self._members_emitter.Emit(
1044 '\n' 1044 '\n'
1045 ' $TYPE $NAME($PARAMS);\n', 1045 ' $TYPE $NAME($PARAMS);\n',
1046 TYPE=self.SecureOutputType(info.type_name), 1046 TYPE=self.SecureOutputType(info.type_name, False, True),
1047 NAME=info.name, 1047 NAME=info.name,
1048 PARAMS=info.ParametersDeclaration(self._NarrowInputType)) 1048 PARAMS=info.ParametersDeclaration(self._NarrowInputType))
1049 1049
1050 1050
1051 def _OperationRequiresConversions(self, operation): 1051 def _OperationRequiresConversions(self, operation):
1052 return (self._OperationRequiresOutputConversion(operation) or 1052 return (self._OperationRequiresOutputConversion(operation) or
1053 self._OperationRequiresInputConversions(operation)) 1053 self._OperationRequiresInputConversions(operation))
1054 1054
1055 def _OperationRequiresOutputConversion(self, operation): 1055 def _OperationRequiresOutputConversion(self, operation):
1056 return self._OutputConversion(operation.type.id, operation.id) 1056 return self._OutputConversion(operation.type.id, operation.id)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 attr2 = FindMatchingAttribute(interface, attr) 1134 attr2 = FindMatchingAttribute(interface, attr)
1135 if attr2: 1135 if attr2:
1136 return (attr2, parent_interface_name) 1136 return (attr2, parent_interface_name)
1137 1137
1138 return FindInParent( 1138 return FindInParent(
1139 self._database.GetInterface(parent_interface_name)) 1139 self._database.GetInterface(parent_interface_name))
1140 return (None, None) 1140 return (None, None)
1141 1141
1142 return FindInParent(self._interface) if attr else (None, None) 1142 return FindInParent(self._interface) if attr else (None, None)
1143 1143
1144 def _DartType(self, type_name):
1145 return self._type_registry.DartType(type_name)
1146
1147 # ------------------------------------------------------------------------------ 1144 # ------------------------------------------------------------------------------
1148 1145
1149 class DartLibraryEmitter(): 1146 class DartLibraryEmitter():
1150 def __init__(self, multiemitter, dart_sources_dir, dart_libraries): 1147 def __init__(self, multiemitter, dart_sources_dir, dart_libraries):
1151 self._multiemitter = multiemitter 1148 self._multiemitter = multiemitter
1152 self._dart_sources_dir = dart_sources_dir 1149 self._dart_sources_dir = dart_sources_dir
1153 self._path_to_emitter = {} 1150 self._path_to_emitter = {}
1154 self._dart_libraries = dart_libraries 1151 self._dart_libraries = dart_libraries
1155 1152
1156 def FileEmitter(self, basename, library_name, template=None): 1153 def FileEmitter(self, basename, library_name, template=None):
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 for library_name in libraries: 1201 for library_name in libraries:
1205 self._libraries[library_name] = DartLibrary( 1202 self._libraries[library_name] = DartLibrary(
1206 library_name, template_loader, library_type, output_dir) 1203 library_name, template_loader, library_type, output_dir)
1207 1204
1208 def AddFile(self, basename, library_name, path): 1205 def AddFile(self, basename, library_name, path):
1209 self._libraries[library_name].AddFile(path) 1206 self._libraries[library_name].AddFile(path)
1210 1207
1211 def Emit(self, emitter, auxiliary_dir): 1208 def Emit(self, emitter, auxiliary_dir):
1212 for lib in self._libraries.values(): 1209 for lib in self._libraries.values():
1213 lib.Emit(emitter, auxiliary_dir) 1210 lib.Emit(emitter, auxiliary_dir)
OLDNEW
« no previous file with comments | « tools/dom/scripts/htmldartgenerator.py ('k') | tools/dom/scripts/systemnative.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698