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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 } else { | 564 } else { |
565 return js('#(#,#,#,#)', | 565 return js('#(#,#,#,#)', |
566 [js(lazyInitializerName), | 566 [js(lazyInitializerName), |
567 js.string(namer.globalPropertyName(element)), | 567 js.string(namer.globalPropertyName(element)), |
568 js.string(namer.lazyInitializerName(element)), | 568 js.string(namer.lazyInitializerName(element)), |
569 code, | 569 code, |
570 js.string(element.name)]); | 570 js.string(element.name)]); |
571 } | 571 } |
572 } | 572 } |
573 | 573 |
574 void emitMetadata(Program program, CodeOutput output) { | 574 void emitMetadata(Program program, CodeOutput output, OutputUnit outputUnit) { |
575 | 575 |
576 addMetadataGlobal(List<String> list, String global) { | 576 addMetadata(List<String> list, String listAccess) { |
577 String globalAccess = generateEmbeddedGlobalAccessString(global); | 577 output.add('$listAccess$_=$_['); |
578 output.add('$globalAccess$_=$_['); | 578 if (list != null) { |
579 for (String data in list) { | 579 for (String data in list) { |
580 if (data is String) { | 580 if (data is String) { |
581 if (data != 'null') { | 581 if (data != 'null') { |
582 output.add(data); | 582 output.add(data); |
583 } | 583 } |
584 } else { | 584 } else { |
585 throw 'Unexpected value in ${global}: ${Error.safeToString(data)}'; | 585 throw 'Unexpected value in ${listAccess}: ' |
sigurdm
2015/04/09 13:00:15
Make this an assert
zarah
2015/04/10 10:56:03
Changed the code. See below.
| |
586 } | 586 '${Error.safeToString(data)}'; |
587 output.add(',$n'); | 587 } |
588 } | 588 output.add(',$n'); |
589 output.add('];$n'); | 589 } |
590 } | 590 } |
591 output.add('];$n'); | |
sigurdm
2015/04/09 13:00:15
Again here you could let listaccess be a js-expres
zarah
2015/04/10 10:56:03
Done.
| |
592 } | |
591 | 593 |
592 addMetadataGlobal(program.metadata, embeddedNames.METADATA); | 594 List<String> types = program.metadataTypes[outputUnit]; |
593 addMetadataGlobal(program.metadataTypes, embeddedNames.TYPES); | 595 List<String> metadata = program.metadata; |
596 | |
597 if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) { | |
598 addMetadata(metadata, | |
599 generateEmbeddedGlobalAccessString(embeddedNames.METADATA)); | |
600 addMetadata(types, | |
601 generateEmbeddedGlobalAccessString(embeddedNames.TYPES)); | |
602 } else { | |
603 if (types != null) { | |
604 addMetadata(types, 'var ${namer.deferredTypesName}'); | |
605 } | |
606 } | |
594 } | 607 } |
595 | 608 |
596 void emitCompileTimeConstants(CodeOutput output, | 609 void emitCompileTimeConstants(CodeOutput output, |
597 List<Constant> constants, | 610 List<Constant> constants, |
598 {bool isMainFragment}) { | 611 {bool isMainFragment}) { |
599 assert(isMainFragment != null); | 612 assert(isMainFragment != null); |
600 | 613 |
601 if (constants.isEmpty) return; | 614 if (constants.isEmpty) return; |
602 CodeOutput constantOutput = output; | 615 CodeOutput constantOutput = output; |
603 if (compiler.hasIncrementalSupport && isMainFragment) { | 616 if (compiler.hasIncrementalSupport && isMainFragment) { |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1252 buildCspPrecompiledFunctionFor(mainOutputUnit); | 1265 buildCspPrecompiledFunctionFor(mainOutputUnit); |
1253 mainOutput.addBuffer( | 1266 mainOutput.addBuffer( |
1254 jsAst.prettyPrint( | 1267 jsAst.prettyPrint( |
1255 precompiledFunctionAst, | 1268 precompiledFunctionAst, |
1256 compiler, | 1269 compiler, |
1257 monitor: compiler.dumpInfoTask, | 1270 monitor: compiler.dumpInfoTask, |
1258 allowVariableMinification: false)); | 1271 allowVariableMinification: false)); |
1259 mainOutput.add(N); | 1272 mainOutput.add(N); |
1260 } | 1273 } |
1261 | 1274 |
1262 mainOutput.add('$setupProgramName(dart)$N'); | 1275 mainOutput.add('$setupProgramName(dart, 0)$N'); |
1263 | 1276 |
1264 interceptorEmitter.emitGetInterceptorMethods(mainOutput); | 1277 interceptorEmitter.emitGetInterceptorMethods(mainOutput); |
1265 interceptorEmitter.emitOneShotInterceptors(mainOutput); | 1278 interceptorEmitter.emitOneShotInterceptors(mainOutput); |
1266 | 1279 |
1267 if (task.outputContainsConstantList) { | 1280 if (task.outputContainsConstantList) { |
1268 emitMakeConstantList(mainOutput); | 1281 emitMakeConstantList(mainOutput); |
1269 } | 1282 } |
1270 | 1283 |
1271 // Constants in checked mode call into RTI code to set type information | 1284 // Constants in checked mode call into RTI code to set type information |
1272 // which may need getInterceptor (and one-shot interceptor) methods, so | 1285 // which may need getInterceptor (and one-shot interceptor) methods, so |
1273 // we have to make sure that [emitGetInterceptorMethods] and | 1286 // we have to make sure that [emitGetInterceptorMethods] and |
1274 // [emitOneShotInterceptors] have been called. | 1287 // [emitOneShotInterceptors] have been called. |
1275 emitCompileTimeConstants( | 1288 emitCompileTimeConstants( |
1276 mainOutput, mainFragment.constants, isMainFragment: true); | 1289 mainOutput, mainFragment.constants, isMainFragment: true); |
1277 | 1290 |
1278 emitDeferredBoilerPlate(mainOutput, deferredLoadHashes); | 1291 emitDeferredBoilerPlate(mainOutput, deferredLoadHashes); |
1279 | 1292 |
1280 if (compiler.deferredMapUri != null) { | 1293 if (compiler.deferredMapUri != null) { |
1281 outputDeferredMap(); | 1294 outputDeferredMap(); |
1282 } | 1295 } |
1283 | 1296 |
1284 // Static field initializations require the classes and compile-time | 1297 // Static field initializations require the classes and compile-time |
1285 // constants to be set up. | 1298 // constants to be set up. |
1286 emitStaticNonFinalFieldInitializations(mainOutput, mainOutputUnit); | 1299 emitStaticNonFinalFieldInitializations(mainOutput, mainOutputUnit); |
1287 interceptorEmitter.emitTypeToInterceptorMap(program, mainOutput); | 1300 interceptorEmitter.emitTypeToInterceptorMap(program, mainOutput); |
1288 emitLazilyInitializedStaticFields(mainOutput); | 1301 emitLazilyInitializedStaticFields(mainOutput); |
1289 | 1302 |
1290 mainOutput.add('\n'); | 1303 mainOutput.add('\n'); |
1291 | 1304 |
1292 emitMetadata(program, mainOutput); | 1305 emitMetadata(program, mainOutput, mainOutputUnit); |
1293 | 1306 |
1294 isolateProperties = isolatePropertiesName; | 1307 isolateProperties = isolatePropertiesName; |
1295 // The following code should not use the short-hand for the | 1308 // The following code should not use the short-hand for the |
1296 // initialStatics. | 1309 // initialStatics. |
1297 mainOutput.add('${namer.currentIsolate}$_=${_}null$N'); | 1310 mainOutput.add('${namer.currentIsolate}$_=${_}null$N'); |
1298 | 1311 |
1299 emitFinishIsolateConstructorInvocation(mainOutput); | 1312 emitFinishIsolateConstructorInvocation(mainOutput); |
1300 mainOutput.add( | 1313 mainOutput.add( |
1301 '${namer.currentIsolate}$_=${_}new ${namer.isolateName}()$N'); | 1314 '${namer.currentIsolate}$_=${_}new ${namer.isolateName}()$N'); |
1302 | 1315 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1688 output | 1701 output |
1689 .add('var $globalObject$_=$_' | 1702 .add('var $globalObject$_=$_' |
1690 '${globalsHolder}.$globalObject$N'); | 1703 '${globalsHolder}.$globalObject$N'); |
1691 } | 1704 } |
1692 output | 1705 output |
1693 ..add('var init$_=$_${globalsHolder}.init$N') | 1706 ..add('var init$_=$_${globalsHolder}.init$N') |
1694 ..add('var $setupProgramName$_=$_' | 1707 ..add('var $setupProgramName$_=$_' |
1695 '$globalsHolder.$setupProgramName$N') | 1708 '$globalsHolder.$setupProgramName$N') |
1696 ..add('var ${namer.isolateName}$_=$_' | 1709 ..add('var ${namer.isolateName}$_=$_' |
1697 '${globalsHolder}.${namer.isolateName}$N'); | 1710 '${globalsHolder}.${namer.isolateName}$N'); |
1711 String typesAccess = | |
1712 generateEmbeddedGlobalAccessString(embeddedNames.TYPES); | |
1698 if (libraryDescriptorBuffer != null) { | 1713 if (libraryDescriptorBuffer != null) { |
1699 // TODO(ahe): This defines a lot of properties on the | 1714 // TODO(ahe): This defines a lot of properties on the |
1700 // Isolate.prototype object. We know this will turn it into a | 1715 // Isolate.prototype object. We know this will turn it into a |
1701 // slow object in V8, so instead we should do something similar | 1716 // slow object in V8, so instead we should do something similar |
1702 // to Isolate.$finishIsolateConstructor. | 1717 // to Isolate.$finishIsolateConstructor. |
1703 output | 1718 output |
1704 ..add('var ${namer.currentIsolate}$_=$_$isolatePropertiesName$N') | 1719 ..add('var ${namer.currentIsolate}$_=$_$isolatePropertiesName$N') |
1705 // The argument to reflectionDataParser is assigned to a temporary | 1720 // The argument to reflectionDataParser is assigned to a temporary |
1706 // 'dart' so that 'dart.' will appear as the prefix to dart methods | 1721 // 'dart' so that 'dart.' will appear as the prefix to dart methods |
1707 // in stack traces and profile entries. | 1722 // in stack traces and profile entries. |
1708 ..add('var dart = [$n ') | 1723 ..add('var dart = [$n ') |
1709 ..addBuffer(libraryDescriptorBuffer) | 1724 ..addBuffer(libraryDescriptorBuffer) |
1710 ..add(']$N'); | 1725 ..add(']$N'); |
1711 | 1726 |
1712 if (compiler.useContentSecurityPolicy) { | 1727 if (compiler.useContentSecurityPolicy) { |
1713 jsAst.Statement precompiledFunctionAst = | 1728 jsAst.Statement precompiledFunctionAst = |
1714 buildCspPrecompiledFunctionFor(outputUnit); | 1729 buildCspPrecompiledFunctionFor(outputUnit); |
1715 | 1730 |
1716 output.addBuffer( | 1731 output.addBuffer( |
1717 jsAst.prettyPrint( | 1732 jsAst.prettyPrint( |
1718 precompiledFunctionAst, compiler, | 1733 precompiledFunctionAst, compiler, |
1719 monitor: compiler.dumpInfoTask, | 1734 monitor: compiler.dumpInfoTask, |
1720 allowVariableMinification: false)); | 1735 allowVariableMinification: false)); |
1721 output.add(N); | 1736 output.add(N); |
1722 } | 1737 } |
1723 output.add('$setupProgramName(dart)$N'); | 1738 output.add('$setupProgramName(dart, ${typesAccess}.length)$N'); |
1739 } | |
1740 | |
1741 if (task.metadataCollector.types[outputUnit] != null) { | |
1742 emitMetadata(program, output, outputUnit); | |
1743 output.add('${typesAccess}.' | |
1744 'push.apply(${typesAccess},$_${namer.deferredTypesName})$N'); | |
1724 } | 1745 } |
1725 | 1746 |
1726 // Set the currentIsolate variable to the current isolate (which is | 1747 // Set the currentIsolate variable to the current isolate (which is |
1727 // provided as second argument). | 1748 // provided as second argument). |
1728 // We need to do this, because we use the same variable for setting up | 1749 // We need to do this, because we use the same variable for setting up |
1729 // the isolate-properties and for storing the current isolate. During | 1750 // the isolate-properties and for storing the current isolate. During |
1730 // the setup (the code above this lines) we must set the variable to | 1751 // the setup (the code above this lines) we must set the variable to |
1731 // the isolate-properties. | 1752 // the isolate-properties. |
1732 // After we have done the setup it must point to the current Isolate. | 1753 // After we have done the setup it must point to the current Isolate. |
1733 // Otherwise all methods/functions accessing isolate variables will | 1754 // Otherwise all methods/functions accessing isolate variables will |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1823 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 1844 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
1824 if (element.isInstanceMember) { | 1845 if (element.isInstanceMember) { |
1825 cachedClassBuilders.remove(element.enclosingClass); | 1846 cachedClassBuilders.remove(element.enclosingClass); |
1826 | 1847 |
1827 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 1848 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
1828 | 1849 |
1829 } | 1850 } |
1830 } | 1851 } |
1831 } | 1852 } |
1832 } | 1853 } |
OLD | NEW |