OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
6 | 6 |
7 | 7 |
8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
9 final Compiler compiler; | 9 final Compiler compiler; |
10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 String get finishIsolateConstructorName | 151 String get finishIsolateConstructorName |
152 => '${namer.isolateName}.\$finishIsolateConstructor'; | 152 => '${namer.isolateName}.\$finishIsolateConstructor'; |
153 String get isolatePropertiesName | 153 String get isolatePropertiesName |
154 => '${namer.isolateName}.${namer.isolatePropertiesName}'; | 154 => '${namer.isolateName}.${namer.isolatePropertiesName}'; |
155 String get lazyInitializerProperty | 155 String get lazyInitializerProperty |
156 => r'$lazy'; | 156 => r'$lazy'; |
157 String get lazyInitializerName | 157 String get lazyInitializerName |
158 => '${namer.isolateName}.${lazyInitializerProperty}'; | 158 => '${namer.isolateName}.${lazyInitializerProperty}'; |
159 String get initName => 'init'; | 159 String get initName => 'init'; |
| 160 |
160 String get makeConstListProperty | 161 String get makeConstListProperty |
161 => namer.getMappedInstanceName('makeConstantList'); | 162 => namer.getMappedInstanceName('makeConstantList'); |
162 | 163 |
163 /// The name of the property that contains all field names. | 164 /// The name of the property that contains all field names. |
164 /// | 165 /// |
165 /// This property is added to constructors when isolate support is enabled. | 166 /// This property is added to constructors when isolate support is enabled. |
166 static const String FIELD_NAMES_PROPERTY_NAME = r"$__fields__"; | 167 static const String FIELD_NAMES_PROPERTY_NAME = r"$__fields__"; |
167 | 168 |
168 /// For deferred loading we communicate the initializers via this global var. | 169 /// For deferred loading we communicate the initializers via this global var. |
169 final String deferredInitializers = r"$dart_deferred_initializers"; | 170 final String deferredInitializers = r"$dart_deferred_initializers"; |
(...skipping 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1819 compiler.internalError(element, 'Owner is null.'); | 1820 compiler.internalError(element, 'Owner is null.'); |
1820 } | 1821 } |
1821 return elementDescriptors.putIfAbsent( | 1822 return elementDescriptors.putIfAbsent( |
1822 owner, | 1823 owner, |
1823 () => new ClassBuilder(owner, namer)); | 1824 () => new ClassBuilder(owner, namer)); |
1824 } | 1825 } |
1825 | 1826 |
1826 /// Emits support-code for deferred loading into [buffer]. | 1827 /// Emits support-code for deferred loading into [buffer]. |
1827 void emitDeferredBoilerPlate(CodeBuffer buffer, | 1828 void emitDeferredBoilerPlate(CodeBuffer buffer, |
1828 Map<OutputUnit, String> deferredLoadHashes) { | 1829 Map<OutputUnit, String> deferredLoadHashes) { |
1829 // Function for checking if a hunk is loaded given its hash. | 1830 jsAst.Statement functions = js.statement(''' |
1830 buffer.write(jsAst.prettyPrint( | 1831 { |
1831 js('# = function(hunkHash) {' | 1832 // Function for checking if a hunk is loaded given its hash. |
1832 ' return !!$deferredInitializers[hunkHash];' | 1833 #isHunkLoaded = function(hunkHash) { |
1833 '}', generateEmbeddedGlobalAccess(embeddedNames.IS_HUNK_LOADED)), | 1834 return !!$deferredInitializers[hunkHash]; |
| 1835 }; |
| 1836 #deferredInitialized = new Object(null); |
| 1837 // Function for checking if a hunk is initialized given its hash. |
| 1838 #isHunkInitialized = function(hunkHash) { |
| 1839 return #deferredInitialized[hunkHash]; |
| 1840 }; |
| 1841 // Function for initializing a loaded hunk, given its hash. |
| 1842 #initializeLoadedHunk = function(hunkHash) { |
| 1843 $deferredInitializers[hunkHash]( |
| 1844 $globalsHolder, ${namer.currentIsolate}); |
| 1845 #deferredInitialized[hunkHash] = true; |
| 1846 }; |
| 1847 } |
| 1848 ''', {"isHunkLoaded": generateEmbeddedGlobalAccess( |
| 1849 embeddedNames.IS_HUNK_LOADED), |
| 1850 "isHunkInitialized": generateEmbeddedGlobalAccess( |
| 1851 embeddedNames.IS_HUNK_INITIALIZED), |
| 1852 "initializeLoadedHunk": generateEmbeddedGlobalAccess( |
| 1853 embeddedNames.INITIALIZE_LOADED_HUNK), |
| 1854 "deferredInitialized": generateEmbeddedGlobalAccess( |
| 1855 embeddedNames.DEFERRED_INITIALIZED)}); |
| 1856 buffer.write(jsAst.prettyPrint(functions, |
1834 compiler, monitor: compiler.dumpInfoTask)); | 1857 compiler, monitor: compiler.dumpInfoTask)); |
1835 buffer.write('$N'); | |
1836 // Function for initializing a loaded hunk, given its hash. | |
1837 buffer.write(jsAst.prettyPrint( | |
1838 js('# = function(hunkHash) {' | |
1839 ' $deferredInitializers[hunkHash](' | |
1840 '$globalsHolder, ${namer.currentIsolate})' | |
1841 '}', | |
1842 generateEmbeddedGlobalAccess( | |
1843 embeddedNames.INITIALIZE_LOADED_HUNK)), | |
1844 compiler, monitor: compiler.dumpInfoTask)); | |
1845 buffer.write('$N'); | |
1846 // Write a javascript mapping from Deferred import load ids (derrived | 1858 // Write a javascript mapping from Deferred import load ids (derrived |
1847 // from the import prefix.) to a list of lists of uris of hunks to load, | 1859 // from the import prefix.) to a list of lists of uris of hunks to load, |
1848 // and a corresponding mapping to a list of hashes used by | 1860 // and a corresponding mapping to a list of hashes used by |
1849 // INITIALIZE_LOADED_HUNK and IS_HUNK_LOADED. | 1861 // INITIALIZE_LOADED_HUNK and IS_HUNK_LOADED. |
1850 Map<String, List<String>> deferredLibraryUris = | 1862 Map<String, List<String>> deferredLibraryUris = |
1851 new Map<String, List<String>>(); | 1863 new Map<String, List<String>>(); |
1852 Map<String, List<String>> deferredLibraryHashes = | 1864 Map<String, List<String>> deferredLibraryHashes = |
1853 new Map<String, List<String>>(); | 1865 new Map<String, List<String>>(); |
1854 compiler.deferredLoadTask.hunksToLoad.forEach( | 1866 compiler.deferredLoadTask.hunksToLoad.forEach( |
1855 (String loadId, List<OutputUnit>outputUnits) { | 1867 (String loadId, List<OutputUnit>outputUnits) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2028 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2040 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
2029 if (element.isInstanceMember) { | 2041 if (element.isInstanceMember) { |
2030 cachedClassBuilders.remove(element.enclosingClass); | 2042 cachedClassBuilders.remove(element.enclosingClass); |
2031 | 2043 |
2032 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2044 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
2033 | 2045 |
2034 } | 2046 } |
2035 } | 2047 } |
2036 } | 2048 } |
2037 } | 2049 } |
OLD | NEW |