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

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

Issue 1987073002: Strip unused functionality from dart:html and fix strong mode errors. Switch from blacklisting pure… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
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 systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import copy 9 import copy
10 import json 10 import json
11 import monitored 11 import monitored
12 import os 12 import os
13 import re 13 import re
14 from htmlrenamer import custom_html_constructors, html_interface_renames, \ 14 from htmlrenamer import custom_html_constructors, html_interface_renames, \
15 typed_array_renames 15 typed_array_renames
16 16
17 _pure_interfaces = monitored.Set('generator._pure_interfaces', [ 17 _safe_interfaces = monitored.Set('generator._safe_interfaces', [
18 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. 18 'double',
19 'DOMStringMap', 19 'Float32Array',
20 'AbstractWorker', 20 'Float64Array',
21 'CanvasPathMethods', 21 'Int8Array',
22 'ChildNode', 22 'Int16Array',
23 'DocumentAnimation', 23 'Int32Array',
24 'DocumentFontFaceSet', 24 'Uint8Array',
25 'DocumentFullscreen', 25 'Uint8ClampedArray',
26 'DocumentXPathEvaluator', 26 'Uint16Array',
27 'ElementAnimation', 27 'Uint32Array',
28 'ElementFullscreen', 28 'ArrayBufferView',
29 'EventListener', 29 'ArrayBuffer',
30 'GlobalEventHandlers', 30 'SourceBuffer', # IDL lies about this class being a pure interface.
31 'ImageBitmapFactories', 31 'Console', # this one is a bit of a hack as our console implementation
32 'MediaQueryListListener', 32 # in dart:html is non-standard for legacy reasons.
33 'MouseEventHitRegion', 33 'AudioContext',
34 'MutationCallback', 34 'AudioSourceNode',
35 'NavigatorCPU', 35 'WebGLVertexArrayObjectOES', # Added a polyfill for this.
36 'NavigatorEvents', 36 # Types where we can get access to the prototype easily enough.
37 'NavigatorID', 37 # We might consider in the future treating these are regular interface types .
38 'NavigatorLanguage', 38 'StereoPannerNode',
39 'NavigatorOnLine', 39 'PannerNode',
40 'ParentNode', 40 'AudioNode',
41 'SVGDocument', 41 'FontFaceSet',
42 'SVGExternalResourcesRequired', 42 'MemoryInfo',
43 'SVGFilterPrimitiveStandardAttributes', 43 'ConsoleBase',
44 'SVGFitToViewBox', 44 'Geolocation',
45 'SVGTests', 45 'Animation',
46 'SVGURIReference', 46 'SourceBufferList',
47 'SVGZoomAndPan', 47 'GamepadList',
48 'TimeoutHandler', 48
49 'URLUtils', 49 # The following classes are enabled just to get the build to go.
50 'URLUtilsReadOnly', 50 # SpeechRecognitionResultList isn't really allowed but the codegen creates
51 'WebGLRenderingContextBase', 51 # invalid output otherwise.
52 'WindowBase64', 52
53 'WindowEventHandlers', 53 'SpeechRecognitionResultList',
54 'WindowImageBitmapFactories', 54 'SQLResultSetRowList',
55 'WindowPagePopup',
56 'WindowTimers',
57 ]) 55 ])
58 56
59 def IsPureInterface(interface_name): 57 # These are interfaces that we have to treat as safe for dart2js and dartium
60 return interface_name in _pure_interfaces 58 # but going in dev compiler we should not treat as safe as these classes
59 # really aren't guaranteed to have a stable interface name.
60 _safe_interfaces_legacy = monitored.Set('generator._safe_interfaces_legacy', [
61 'ANGLEInstancedArrays',
62 'Bluetooth',
63 'Body',
64 'NonDocumentTypeChildNode',
65 'CHROMIUMSubscribeUniform',
66 'CHROMIUMValuebuffer',
67 'GeofencingRegion',
68 'Coordinates',
69 'DOMFileSystem',
70 'DirectoryEntry',
71 'DOMFileSystemSync',
72 'Entry',
73 'Database',
74 'DeprecatedStorageInfo',
75 'DeprecatedStorageQuota',
76 'DeviceAcceleration',
77 'DeviceRotationRate',
78 'DirectoryReader',
79 'EntrySync',
80 'DirectoryEntrySync',
81 'DirectoryReaderSync',
82 'NonElementParentNode',
83 'EXTBlendMinMax',
84 'EXTFragDepth',
85 'EXTShaderTextureLOD',
86 'EXTTextureFilterAnisotropic',
87 'EXTsRGB',
88 'EffectModel',
89 'FileEntry',
90 'FileEntrySync',
91 'FileWriter',
92 'FileWriterSync',
93 'FontFaceSetLoadEvent',
94 'Geofencing',
95 'Geoposition',
96 'Iterator',
97 'MediaDeviceInfo',
98 'MediaStreamTrackEvent',
99 'Metadata',
100 'NavigatorStorageUtils',
101 'StorageQuota',
102 'NavigatorUserMediaError',
103 'OESElementIndexUint',
104 'OESStandardDerivatives',
105 'OESTextureFloat',
106 'OESTextureFloatLinear',
107 'OESTextureHalfFloat',
108 'OESTextureHalfFloatLinear',
109 'OESVertexArrayObject',
110 'PagePopupController',
111 'PluginPlaceholderElement',
112 'PositionError',
113 'RTCDTMFSender',
114 'RTCDataChannel',
115 'RTCDataChannelEvent',
116 'RTCIceCandidateEvent',
117 'RTCStatsReport',
118 'RTCStatsResponse',
119 'ReadableByteStreamReader',
120 'ReadableStreamReader',
121 'ResourceProgressEvent',
122 'SQLError',
123 'SQLResultSet',
124 'SQLTransaction',
125 'SharedArrayBuffer',
126 'SourceInfo',
127 'SpeechRecognitionAlternative',
128 'SpeechRecognitionResult',
129 'SpeechSynthesis',
130 'SpeechSynthesisVoice',
131 'StorageInfo',
132 'StyleMedia',
133 'WebGL2RenderingContextBase',
134 'WebGLCompressedTextureATC',
135 'WebGLCompressedTextureETC1',
136 'WebGLCompressedTexturePVRTC',
137 'WebGLCompressedTextureS3TC',
138 'WebGLDebugRendererInfo',
139 'WebGLDebugShaders',
140 'WebGLDepthTexture',
141 'WebGLDrawBuffers',
142 'WebGLLoseContext',
143 'WorkerConsole',
144 'WorkerPerformance',
145 'XPathNSResolver',
146 ])
147
148 # Classes we should just suppress?
149 # SpeechGrammarList and friends
150
151 def IsPureInterface(interface_name, database):
152 if (interface_name in _safe_interfaces or
153 interface_name in _safe_interfaces_legacy or
154 database.HasInterface(interface_name)):
155 return False
156
157 interface = database.GetInterface(interface_name)
158
159 if 'Constructor' in interface.ext_attrs:
160 return False
161
162 return interface.is_no_interface_object
61 163
62 # 164 #
63 # Classes which have native constructors but which we are suppressing because 165 # Classes which have native constructors but which we are suppressing because
64 # they are not cross-platform. 166 # they are not cross-platform.
65 # 167 #
66 _suppressed_native_constructors = monitored.Set( 168 _suppressed_native_constructors = monitored.Set(
67 'generator._suppressed_native_constructors', [ 169 'generator._suppressed_native_constructors', [
68 'DocumentFragment', 170 'DocumentFragment',
69 'Range', 171 'Range',
70 'Text', 172 'Text',
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 'MutationObserver': 'MutationObserver,WebKitMutationObserver', 258 'MutationObserver': 'MutationObserver,WebKitMutationObserver',
157 259
158 'NamedNodeMap': 'NamedNodeMap,MozNamedAttrMap', 260 'NamedNodeMap': 'NamedNodeMap,MozNamedAttrMap',
159 261
160 'NodeList': 'NodeList,RadioNodeList', 262 'NodeList': 'NodeList,RadioNodeList',
161 263
162 'OscillatorNode': 'OscillatorNode,Oscillator', 264 'OscillatorNode': 'OscillatorNode,Oscillator',
163 265
164 'PannerNode': 'PannerNode,AudioPannerNode,webkitAudioPannerNode', 266 'PannerNode': 'PannerNode,AudioPannerNode,webkitAudioPannerNode',
165 267
166 'RTCPeerConnection': 'RTCPeerConnection,mozRTCPeerConnection', 268 'RTCPeerConnection': 'RTCPeerConnection,webkitRTCPeerConnection,mozRTCPeerCo nnection',
167 269
168 'RTCIceCandidate': 'RTCIceCandidate,mozRTCIceCandidate', 270 'RTCIceCandidate': 'RTCIceCandidate,mozRTCIceCandidate',
169 271
170 'RTCIceCandidateEvent': 'RTCIceCandidateEvent,RTCPeerConnectionIceEvent', 272 'RTCIceCandidateEvent': 'RTCIceCandidateEvent,RTCPeerConnectionIceEvent',
171 273
172 'RTCSessionDescription': 'RTCSessionDescription,mozRTCSessionDescription', 274 'RTCSessionDescription': 'RTCSessionDescription,mozRTCSessionDescription',
173 275
174 'RTCDataChannel': 'RTCDataChannel,DataChannel', 276 'RTCDataChannel': 'RTCDataChannel,DataChannel',
175 277
176 'ScriptProcessorNode': 'ScriptProcessorNode,JavaScriptAudioNode', 278 'ScriptProcessorNode': 'ScriptProcessorNode,JavaScriptAudioNode',
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 return 'List<%s>' % self._type_registry.TypeInfo(self._data.item_type).dar t_type() 1024 return 'List<%s>' % self._type_registry.TypeInfo(self._data.item_type).dar t_type()
923 return self._dart_interface_name 1025 return self._dart_interface_name
924 1026
925 def narrow_dart_type(self): 1027 def narrow_dart_type(self):
926 if self.list_item_type(): 1028 if self.list_item_type():
927 return self.implementation_name() 1029 return self.implementation_name()
928 # TODO(podivilov): only primitive and collection types should override 1030 # TODO(podivilov): only primitive and collection types should override
929 # dart_type. 1031 # dart_type.
930 if self._data.dart_type != None: 1032 if self._data.dart_type != None:
931 return self.dart_type() 1033 return self.dart_type()
932 if IsPureInterface(self.idl_type()): 1034 if IsPureInterface(self.idl_type(), self._type_registry._database):
933 return self.idl_type() 1035 return self.idl_type()
934 return self.interface_name() 1036 return self.interface_name()
935 1037
936 def interface_name(self): 1038 def interface_name(self):
937 return self._dart_interface_name 1039 return self._dart_interface_name
938 1040
939 def implementation_name(self): 1041 def implementation_name(self):
940 implementation_name = self._dart_interface_name 1042 implementation_name = self._dart_interface_name
941 1043
942 if not self.has_generated_interface(): 1044 if not self.has_generated_interface():
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 return_type == 'Rectangle') 1622 return_type == 'Rectangle')
1521 1623
1522 def wrap_return_type_blink(return_type, type_name, type_registry): 1624 def wrap_return_type_blink(return_type, type_name, type_registry):
1523 """Returns True if we should wrap the returned value. This checks 1625 """Returns True if we should wrap the returned value. This checks
1524 a number of different variations, calling the more basic functions 1626 a number of different variations, calling the more basic functions
1525 above.""" 1627 above."""
1526 return (wrap_unwrap_type_blink(return_type, type_registry) or 1628 return (wrap_unwrap_type_blink(return_type, type_registry) or
1527 wrap_unwrap_type_blink(type_name, type_registry) or 1629 wrap_unwrap_type_blink(type_name, type_registry) or
1528 wrap_type_blink(return_type, type_registry) or 1630 wrap_type_blink(return_type, type_registry) or
1529 wrap_unwrap_list_blink(return_type, type_registry)) 1631 wrap_unwrap_list_blink(return_type, type_registry))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698