| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, 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 generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
| 7 | 7 |
| 8 import emitter | 8 import emitter |
| 9 import idlnode | 9 import idlnode |
| 10 import logging | 10 import logging |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 # browsers, but are otherwise identical. The alternates are tried in order and | 129 # browsers, but are otherwise identical. The alternates are tried in order and |
| 130 # the first one defined is used. | 130 # the first one defined is used. |
| 131 # | 131 # |
| 132 # This can be probably be removed when Chrome renames initWebKitWheelEvent to | 132 # This can be probably be removed when Chrome renames initWebKitWheelEvent to |
| 133 # initWheelEvent. | 133 # initWheelEvent. |
| 134 # | 134 # |
| 135 _alternate_methods = { | 135 _alternate_methods = { |
| 136 ('WheelEvent', 'initWheelEvent'): ['initWebKitWheelEvent', 'initWheelEvent'] | 136 ('WheelEvent', 'initWheelEvent'): ['initWebKitWheelEvent', 'initWheelEvent'] |
| 137 } | 137 } |
| 138 | 138 |
| 139 # |
| 140 # Unexpandable types require special support for |
| 141 # dartObjectLocalStorage. Normally, in the overlay dom, it is |
| 142 # implemented as an expando field. For these types, we cannot use an |
| 143 # expando. Instead, we define a specialized getter and setter. |
| 144 # |
| 145 _frog_unexpandable_types = { |
| 146 # (type name, field name) -> Replacement text |
| 147 ('Storage', 'dartObjectLocalStorage'): ''' |
| 148 var get dartObjectLocalStorage() native """ |
| 149 |
| 150 if (this === window.localStorage) |
| 151 return window._dartLocalStorageLocalStorage; |
| 152 else if (this === window.sessionStorage) |
| 153 return window._dartSessionStorageLocalStorage; |
| 154 else |
| 155 throw new UnsupportedOperationException('Cannot dartObjectLocalStorage for
unknown Storage object.'); |
| 156 |
| 157 """ { |
| 158 throw new UnsupportedOperationException(''); |
| 159 } |
| 160 |
| 161 void set dartObjectLocalStorage(var value) native """ |
| 162 |
| 163 if (this === window.localStorage) |
| 164 window._dartLocalStorageLocalStorage = value; |
| 165 else if (this === window.sessionStorage) |
| 166 window._dartSessionStorageLocalStorage = value; |
| 167 else |
| 168 throw new UnsupportedOperationException('Cannot dartObjectLocalStorage for
unknown Storage object.'); |
| 169 |
| 170 """ { |
| 171 throw new UnsupportedOperationException(''); |
| 172 } |
| 173 ''', |
| 174 } |
| 175 |
| 139 def _MatchSourceFilter(filter, thing): | 176 def _MatchSourceFilter(filter, thing): |
| 140 if not filter: | 177 if not filter: |
| 141 return True | 178 return True |
| 142 else: | 179 else: |
| 143 return any(token in thing.annotations for token in filter) | 180 return any(token in thing.annotations for token in filter) |
| 144 | 181 |
| 145 def _IsDartListType(type): | 182 def _IsDartListType(type): |
| 146 return type == 'List' or type.startswith('List<') | 183 return type == 'List' or type.startswith('List<') |
| 147 | 184 |
| 148 def _IsDartCollectionType(type): | 185 def _IsDartCollectionType(type): |
| (...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 '\n' | 1860 '\n' |
| 1824 'class $CLASS$BASE$IMPLEMENTS native "$NATIVE" {\n' | 1861 'class $CLASS$BASE$IMPLEMENTS native "$NATIVE" {\n' |
| 1825 '$!MEMBERS' | 1862 '$!MEMBERS' |
| 1826 '$!ADDITIONS' | 1863 '$!ADDITIONS' |
| 1827 '}\n', | 1864 '}\n', |
| 1828 CLASS=self._class_name, BASE=extends, | 1865 CLASS=self._class_name, BASE=extends, |
| 1829 INTERFACE=interface_name, | 1866 INTERFACE=interface_name, |
| 1830 IMPLEMENTS=implements, | 1867 IMPLEMENTS=implements, |
| 1831 NATIVE=native_spec) | 1868 NATIVE=native_spec) |
| 1832 | 1869 |
| 1833 if interface_name in _constructable_types.keys(): | 1870 if interface_name in _constructable_types: |
| 1834 self._members_emitter.Emit( | 1871 self._members_emitter.Emit( |
| 1835 ' $NAME($PARAMS) native;\n\n', | 1872 ' $NAME($PARAMS) native;\n\n', |
| 1836 NAME=interface_name, | 1873 NAME=interface_name, |
| 1837 PARAMS=_constructable_types[interface_name]) | 1874 PARAMS=_constructable_types[interface_name]) |
| 1838 | 1875 |
| 1839 element_type = MaybeTypedArrayElementType(interface) | 1876 element_type = MaybeTypedArrayElementType(interface) |
| 1840 if element_type: | 1877 if element_type: |
| 1841 self.AddTypedArrayConstructors(element_type) | 1878 self.AddTypedArrayConstructors(element_type) |
| 1842 | 1879 |
| 1843 if not base: | 1880 if not base: |
| 1844 # Emit shared base functionality here as we have no common base type. | 1881 # Emit shared base functionality here as we have no common base type. |
| 1882 if (interface_name, 'dartObjectLocalStorage') in _frog_unexpandable_types: |
| 1883 ols_code = _frog_unexpandable_types[(interface_name, |
| 1884 'dartObjectLocalStorage')] |
| 1885 self._base_emitter.Emit(ols_code) |
| 1886 else: |
| 1887 self._base_emitter.Emit( |
| 1888 '\n' |
| 1889 ' var dartObjectLocalStorage;\n') |
| 1845 self._base_emitter.Emit( | 1890 self._base_emitter.Emit( |
| 1846 '\n' | 1891 '\n' |
| 1847 ' var dartObjectLocalStorage;\n' | |
| 1848 '\n' | |
| 1849 ' String get typeName() native;\n') | 1892 ' String get typeName() native;\n') |
| 1850 | 1893 |
| 1851 def _ImplClassName(self, type_name): | 1894 def _ImplClassName(self, type_name): |
| 1852 return type_name | 1895 return type_name |
| 1853 | 1896 |
| 1854 def FinishInterface(self): | 1897 def FinishInterface(self): |
| 1855 """.""" | 1898 """.""" |
| 1856 pass | 1899 pass |
| 1857 | 1900 |
| 1858 def AddConstant(self, constant): | 1901 def AddConstant(self, constant): |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1952 Arguments: | 1995 Arguments: |
| 1953 info: An OperationInfo object. | 1996 info: An OperationInfo object. |
| 1954 """ | 1997 """ |
| 1955 # TODO(vsm): Handle overloads. | 1998 # TODO(vsm): Handle overloads. |
| 1956 self._members_emitter.Emit( | 1999 self._members_emitter.Emit( |
| 1957 '\n' | 2000 '\n' |
| 1958 ' $TYPE $NAME($ARGS) native;\n', | 2001 ' $TYPE $NAME($ARGS) native;\n', |
| 1959 TYPE=info.type_name, | 2002 TYPE=info.type_name, |
| 1960 NAME=info.name, | 2003 NAME=info.name, |
| 1961 ARGS=info.arg_implementation_declaration) | 2004 ARGS=info.arg_implementation_declaration) |
| OLD | NEW |