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 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 js.string(namer.globalPropertyName(element)), | 674 js.string(namer.globalPropertyName(element)), |
675 js.string(namer.lazyInitializerName(element)), | 675 js.string(namer.lazyInitializerName(element)), |
676 code, | 676 code, |
677 js.string(element.name)]); | 677 js.string(element.name)]); |
678 } | 678 } |
679 } | 679 } |
680 | 680 |
681 jsAst.Statement buildMetadata(Program program, OutputUnit outputUnit) { | 681 jsAst.Statement buildMetadata(Program program, OutputUnit outputUnit) { |
682 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 682 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
683 | 683 |
684 jsAst.Expression constructList(List<jsAst.Expression> list) { | 684 jsAst.Expression types = program.metadataTypesForOutputUnit(outputUnit); |
685 return new jsAst.ArrayInitializer(list == null ? [] : list); | |
686 } | |
687 | |
688 List<jsAst.Expression> types = program.metadataTypes[outputUnit]; | |
689 | 685 |
690 if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) { | 686 if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) { |
691 jsAst.Expression metadataAccess = | 687 jsAst.Expression metadataAccess = |
692 generateEmbeddedGlobalAccess(embeddedNames.METADATA); | 688 generateEmbeddedGlobalAccess(embeddedNames.METADATA); |
693 jsAst.Expression typesAccess = | 689 jsAst.Expression typesAccess = |
694 generateEmbeddedGlobalAccess(embeddedNames.TYPES); | 690 generateEmbeddedGlobalAccess(embeddedNames.TYPES); |
695 | 691 |
696 parts..add(js.statement('# = #;', [metadataAccess, | 692 parts..add(js.statement('# = #;', [metadataAccess, program.metadata])) |
karlklose
2015/05/28 09:39:53
Consider adding type arguments when changing this
herhut
2015/06/01 12:09:42
Acknowledged.
| |
697 constructList(program.metadata)])) | 693 ..add(js.statement('# = #;', [typesAccess, types])); |
698 ..add(js.statement('# = #;', [typesAccess, constructList(types)])); | |
699 } else if (types != null) { | 694 } else if (types != null) { |
700 parts.add(js.statement('var ${namer.deferredTypesName} = #;', | 695 parts.add(js.statement('var ${namer.deferredTypesName} = #;', |
701 constructList(types))); | 696 types)); |
702 } | 697 } |
703 return new jsAst.Block(parts); | 698 return new jsAst.Block(parts); |
704 } | 699 } |
705 | 700 |
706 jsAst.Statement buildCompileTimeConstants(List<Constant> constants, | 701 jsAst.Statement buildCompileTimeConstants(List<Constant> constants, |
707 {bool isMainFragment}) { | 702 {bool isMainFragment}) { |
708 assert(isMainFragment != null); | 703 assert(isMainFragment != null); |
709 | 704 |
710 if (constants.isEmpty) return js.comment("No constants in program."); | 705 if (constants.isEmpty) return js.comment("No constants in program."); |
711 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 706 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1002 ClassBuilder descriptor = elementDescriptors[fragment][library]; | 997 ClassBuilder descriptor = elementDescriptors[fragment][library]; |
1003 | 998 |
1004 jsAst.ObjectInitializer initializer; | 999 jsAst.ObjectInitializer initializer; |
1005 if (descriptor == null) { | 1000 if (descriptor == null) { |
1006 // Nothing of the library was emitted. | 1001 // Nothing of the library was emitted. |
1007 // TODO(floitsch): this should not happen. We currently have an example | 1002 // TODO(floitsch): this should not happen. We currently have an example |
1008 // with language/prefix6_negative_test.dart where we have an instance | 1003 // with language/prefix6_negative_test.dart where we have an instance |
1009 // method without its corresponding class. | 1004 // method without its corresponding class. |
1010 initializer = new jsAst.ObjectInitializer([]); | 1005 initializer = new jsAst.ObjectInitializer([]); |
1011 } else { | 1006 } else { |
1012 initializer = descriptor.toObjectInitializer(); | 1007 initializer = descriptor.toObjectInitializer(compiler); |
1013 } | 1008 } |
1014 | 1009 |
1015 compiler.dumpInfoTask.registerElementAst(library, metadata); | 1010 compiler.dumpInfoTask.registerElementAst(library, metadata); |
1016 compiler.dumpInfoTask.registerElementAst(library, initializer); | 1011 compiler.dumpInfoTask.registerElementAst(library, initializer); |
1017 | 1012 |
1018 List<jsAst.Expression> parts = <jsAst.Expression>[]; | 1013 List<jsAst.Expression> parts = <jsAst.Expression>[]; |
1019 parts..add(js.string(libraryName)) | 1014 parts..add(js.string(libraryName)) |
1020 ..add(js.string(uri.toString())) | 1015 ..add(js.string(uri.toString())) |
1021 ..add(metadata == null ? new jsAst.ArrayHole() : metadata) | 1016 ..add(metadata == null ? new jsAst.ArrayHole() : metadata) |
1022 ..add(js('#', namer.globalObjectFor(library))) | 1017 ..add(js('#', namer.globalObjectFor(library))) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1068 | 1063 |
1069 // Emit all required typedef declarations into the main output unit. | 1064 // Emit all required typedef declarations into the main output unit. |
1070 // TODO(karlklose): unify required classes and typedefs to declarations | 1065 // TODO(karlklose): unify required classes and typedefs to declarations |
1071 // and have builders for each kind. | 1066 // and have builders for each kind. |
1072 for (TypedefElement typedef in typedefsNeededForReflection) { | 1067 for (TypedefElement typedef in typedefsNeededForReflection) { |
1073 LibraryElement library = typedef.library; | 1068 LibraryElement library = typedef.library; |
1074 // TODO(karlklose): add a TypedefBuilder and move this code there. | 1069 // TODO(karlklose): add a TypedefBuilder and move this code there. |
1075 DartType type = typedef.alias; | 1070 DartType type = typedef.alias; |
1076 // TODO(zarah): reify type variables once reflection on type arguments of | 1071 // TODO(zarah): reify type variables once reflection on type arguments of |
1077 // typedefs is supported. | 1072 // typedefs is supported. |
1078 int typeIndex = | 1073 jsAst.Expression typeIndex = |
1079 task.metadataCollector.reifyType(type, ignoreTypeVariables: true); | 1074 task.metadataCollector.reifyType(type, ignoreTypeVariables: true); |
1080 ClassBuilder builder = new ClassBuilder(typedef, namer); | 1075 ClassBuilder builder = new ClassBuilder(typedef, namer); |
1081 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, | 1076 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, typeIndex); |
1082 js.number(typeIndex)); | |
1083 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, | 1077 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, |
1084 js.boolean(true)); | 1078 js.boolean(true)); |
1085 | 1079 |
1086 // We can be pretty sure that the objectClass is initialized, since | 1080 // We can be pretty sure that the objectClass is initialized, since |
1087 // typedefs are only emitted with reflection, which requires lots of | 1081 // typedefs are only emitted with reflection, which requires lots of |
1088 // classes. | 1082 // classes. |
1089 assert(compiler.objectClass != null); | 1083 assert(compiler.objectClass != null); |
1090 builder.superName = namer.className(compiler.objectClass); | 1084 builder.superName = namer.className(compiler.objectClass); |
1091 jsAst.Node declaration = builder.toObjectInitializer(); | 1085 jsAst.Node declaration = builder.toObjectInitializer(compiler); |
1092 String mangledName = namer.globalPropertyName(typedef); | 1086 String mangledName = namer.globalPropertyName(typedef); |
1093 String reflectionName = getReflectionName(typedef, mangledName); | 1087 String reflectionName = getReflectionName(typedef, mangledName); |
1094 getElementDescriptor(library, mainFragment) | 1088 getElementDescriptor(library, mainFragment) |
1095 ..addProperty(mangledName, declaration) | 1089 ..addProperty(mangledName, declaration) |
1096 ..addProperty("+$reflectionName", js.string('')); | 1090 ..addProperty("+$reflectionName", js.string('')); |
1097 // Also emit a trivial constructor for CSP mode. | 1091 // Also emit a trivial constructor for CSP mode. |
1098 String constructorName = mangledName; | 1092 String constructorName = mangledName; |
1099 jsAst.Expression constructorAst = js('function() {}'); | 1093 jsAst.Expression constructorAst = js('function() {}'); |
1100 List<String> fieldNames = []; | 1094 List<String> fieldNames = []; |
1101 assemblePrecompiledConstructor(mainOutputUnit, | 1095 assemblePrecompiledConstructor(mainOutputUnit, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1259 | 1253 |
1260 void assembleProgram(Program program) { | 1254 void assembleProgram(Program program) { |
1261 for (Fragment fragment in program.fragments) { | 1255 for (Fragment fragment in program.fragments) { |
1262 for (Library library in fragment.libraries) { | 1256 for (Library library in fragment.libraries) { |
1263 assembleLibrary(library, fragment); | 1257 assembleLibrary(library, fragment); |
1264 } | 1258 } |
1265 } | 1259 } |
1266 assembleTypedefs(program); | 1260 assembleTypedefs(program); |
1267 } | 1261 } |
1268 | 1262 |
1269 void emitMainOutputUnit(Program program, | 1263 jsAst.Program buildOutputAstForMain(Program program, |
1270 Map<OutputUnit, String> deferredLoadHashes) { | 1264 Map<OutputUnit, _DeferredOutputUnitHash> deferredLoadHashes) { |
1271 MainFragment mainFragment = program.fragments.first; | 1265 MainFragment mainFragment = program.mainFragment; |
1272 OutputUnit mainOutputUnit = mainFragment.outputUnit; | 1266 OutputUnit mainOutputUnit = mainFragment.outputUnit; |
1273 | |
1274 LineColumnCollector lineColumnCollector; | |
1275 List<CodeOutputListener> codeOutputListeners; | |
1276 if (generateSourceMap) { | |
1277 lineColumnCollector = new LineColumnCollector(); | |
1278 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; | |
1279 } | |
1280 | |
1281 CodeOutput mainOutput = | |
1282 new StreamCodeOutput(compiler.outputProvider('', 'js'), | |
1283 codeOutputListeners); | |
1284 outputBuffers[mainOutputUnit] = mainOutput; | |
1285 | |
1286 bool isProgramSplit = program.isSplit; | 1267 bool isProgramSplit = program.isSplit; |
1287 | 1268 |
1288 List<jsAst.Statement> statements = <jsAst.Statement>[]; | 1269 List<jsAst.Statement> statements = <jsAst.Statement>[]; |
1289 | 1270 |
1290 statements..add(buildGeneratedBy()) | 1271 statements..add(buildGeneratedBy()) |
1291 ..add(js.comment(HOOKS_API_USAGE)); | 1272 ..add(js.comment(HOOKS_API_USAGE)); |
karlklose
2015/05/28 09:39:53
Revert IDE's change. (also next two changes below)
herhut
2015/06/01 12:09:42
Done.
| |
1292 | 1273 |
1293 if (isProgramSplit) { | 1274 if (isProgramSplit) { |
1294 /// For deferred loading we communicate the initializers via this global | 1275 /// For deferred loading we communicate the initializers via this global |
1295 /// variable. The deferred hunks will add their initialization to this. | 1276 /// variable. The deferred hunks will add their initialization to this. |
1296 /// The semicolon is important in minified mode, without it the | 1277 /// The semicolon is important in minified mode, without it the |
1297 /// following parenthesis looks like a call to the object literal. | 1278 /// following parenthesis looks like a call to the object literal. |
1298 statements.add( | 1279 statements.add( |
1299 js.statement('self.#deferredInitializers = ' | 1280 js.statement('self.#deferredInitializers = ' |
1300 'self.#deferredInitializers || Object.create(null);', | 1281 'self.#deferredInitializers || Object.create(null);', |
1301 {'deferredInitializers': deferredInitializers})); | 1282 {'deferredInitializers': deferredInitializers})); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1468 "cspPrecompiledFunctions": buildCspPrecompiledFunctionFor(mainOutputUnit), | 1449 "cspPrecompiledFunctions": buildCspPrecompiledFunctionFor(mainOutputUnit), |
1469 "getInterceptorMethods": interceptorEmitter.buildGetInterceptorMethods(), | 1450 "getInterceptorMethods": interceptorEmitter.buildGetInterceptorMethods(), |
1470 "oneShotInterceptors": interceptorEmitter.buildOneShotInterceptors(), | 1451 "oneShotInterceptors": interceptorEmitter.buildOneShotInterceptors(), |
1471 "makeConstantList": buildMakeConstantList(), | 1452 "makeConstantList": buildMakeConstantList(), |
1472 "compileTimeConstants": buildCompileTimeConstants(mainFragment.constants, | 1453 "compileTimeConstants": buildCompileTimeConstants(mainFragment.constants, |
1473 isMainFragment: true), | 1454 isMainFragment: true), |
1474 "deferredBoilerPlate": buildDeferredBoilerPlate(deferredLoadHashes), | 1455 "deferredBoilerPlate": buildDeferredBoilerPlate(deferredLoadHashes), |
1475 "staticNonFinalInitializers": buildStaticNonFinalFieldInitializations( | 1456 "staticNonFinalInitializers": buildStaticNonFinalFieldInitializations( |
1476 mainOutputUnit), | 1457 mainOutputUnit), |
1477 "typeToInterceptorMap": | 1458 "typeToInterceptorMap": |
1478 interceptorEmitter.buildTypeToInterceptorMap(program), | 1459 interceptorEmitter.buildTypeToInterceptorMap(program), |
1479 "lazyStaticFields": buildLazilyInitializedStaticFields(), | 1460 "lazyStaticFields": buildLazilyInitializedStaticFields(), |
1480 "metadata": buildMetadata(program, mainOutputUnit), | 1461 "metadata": buildMetadata(program, mainOutputUnit), |
1481 "convertToFastObject": buildConvertToFastObjectFunction(), | 1462 "convertToFastObject": buildConvertToFastObjectFunction(), |
1482 "convertToSlowObject": buildConvertToSlowObjectFunction(), | 1463 "convertToSlowObject": buildConvertToSlowObjectFunction(), |
1483 "convertGlobalObjectsToFastObjects": | 1464 "convertGlobalObjectsToFastObjects": |
1484 buildConvertGlobalObjectToFastObjects(), | 1465 buildConvertGlobalObjectToFastObjects(), |
1485 "debugFastObjects": buildDebugFastObjectCode(), | 1466 "debugFastObjects": buildDebugFastObjectCode(), |
1486 "init": buildInitFunction(), | 1467 "init": buildInitFunction(), |
1487 "main": buildMain(mainFragment.invokeMain) | 1468 "main": buildMain(mainFragment.invokeMain) |
1488 })); | 1469 })); |
1489 | 1470 |
1490 mainOutput.addBuffer(jsAst.prettyPrint(new jsAst.Program(statements), | 1471 return new jsAst.Program(statements); |
1472 } | |
1473 | |
1474 void emitMainOutputUnit(OutputUnit mainOutputUnit, jsAst.Program program) { | |
1475 LineColumnCollector lineColumnCollector; | |
1476 List<CodeOutputListener> codeOutputListeners; | |
1477 if (generateSourceMap) { | |
1478 lineColumnCollector = new LineColumnCollector(); | |
1479 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; | |
1480 } | |
1481 | |
1482 CodeOutput mainOutput = | |
1483 new StreamCodeOutput(compiler.outputProvider('', 'js'), | |
1484 codeOutputListeners); | |
1485 outputBuffers[mainOutputUnit] = mainOutput; | |
1486 | |
1487 | |
1488 mainOutput.addBuffer(jsAst.prettyPrint(program, | |
1491 compiler, | 1489 compiler, |
1492 monitor: compiler.dumpInfoTask)); | 1490 monitor: compiler.dumpInfoTask)); |
1493 | 1491 |
1494 if (compiler.deferredMapUri != null) { | 1492 if (compiler.deferredMapUri != null) { |
1495 outputDeferredMap(); | 1493 outputDeferredMap(); |
1496 } | 1494 } |
1497 | 1495 |
1498 if (generateSourceMap) { | 1496 if (generateSourceMap) { |
1499 mainOutput.add( | 1497 mainOutput.add( |
1500 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); | 1498 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1647 descriptors.remove(library); | 1645 descriptors.remove(library); |
1648 } | 1646 } |
1649 | 1647 |
1650 outputs[outputUnit] = new jsAst.ArrayInitializer(parts); | 1648 outputs[outputUnit] = new jsAst.ArrayInitializer(parts); |
1651 } | 1649 } |
1652 } | 1650 } |
1653 | 1651 |
1654 return outputs; | 1652 return outputs; |
1655 } | 1653 } |
1656 | 1654 |
1655 void finalizeTokensInAst(jsAst.Program main, Iterable<jsAst.Program> parts) { | |
karlklose
2015/05/28 09:39:53
'parts' -> 'deferredParts'? I think it feels stran
herhut
2015/06/01 12:09:42
Done.
| |
1656 task.metadataCollector.countTokensInProgram(main); | |
1657 parts.forEach(task.metadataCollector.countTokensInProgram); | |
1658 task.metadataCollector.finalizeTokens(); | |
1659 } | |
1660 | |
1657 int emitProgram(ProgramBuilder programBuilder) { | 1661 int emitProgram(ProgramBuilder programBuilder) { |
1658 Program program = programBuilder.buildProgram( | 1662 Program program = programBuilder.buildProgram( |
1659 storeFunctionTypesInMetadata: true); | 1663 storeFunctionTypesInMetadata: true); |
1660 | 1664 |
1661 assembleProgram(program); | 1665 assembleProgram(program); |
1662 | 1666 |
1663 // Construct the ASTs for all deferred output units. | 1667 // Construct the ASTs for all deferred output units. |
1664 Map<OutputUnit, jsAst.Program> deferredParts = | 1668 Map<OutputUnit, jsAst.Program> deferredParts = |
1665 buildOutputAstForDeferredCode(program); | 1669 buildOutputAstForDeferredCode(program); |
1666 | 1670 |
1671 Map<OutputUnit, _DeferredOutputUnitHash> deferredHashTokens = | |
1672 new Map<OutputUnit, _DeferredOutputUnitHash>.fromIterables( | |
1673 deferredParts.keys, | |
1674 deferredParts.keys.map((OutputUnit unit) { | |
1675 return new _DeferredOutputUnitHash(unit); | |
1676 }) | |
1677 ); | |
1678 | |
1679 jsAst.Program mainOutput = | |
1680 buildOutputAstForMain(program, deferredHashTokens); | |
1681 | |
1682 finalizeTokensInAst(mainOutput, deferredParts.values); | |
1683 | |
1667 // Emit deferred units first, so we have their hashes. | 1684 // Emit deferred units first, so we have their hashes. |
1668 // Map from OutputUnit to a hash of its content. The hash uniquely | 1685 // Map from OutputUnit to a hash of its content. The hash uniquely |
1669 // identifies the code of the output-unit. It does not include | 1686 // identifies the code of the output-unit. It does not include |
1670 // boilerplate JS code, like the sourcemap directives or the hash | 1687 // boilerplate JS code, like the sourcemap directives or the hash |
1671 // itself. | 1688 // itself. |
1672 Map<OutputUnit, String> deferredLoadHashes = | 1689 Map<OutputUnit, String> deferredLoadHashes = |
1673 emitDeferredOutputUnits(deferredParts); | 1690 emitDeferredOutputUnits(deferredParts); |
1674 emitMainOutputUnit(program, deferredLoadHashes); | 1691 |
1692 deferredHashTokens.forEach((OutputUnit key, _DeferredOutputUnitHash token) { | |
1693 token.setHash(deferredLoadHashes[key]); | |
1694 }); | |
1695 emitMainOutputUnit(program.mainFragment.outputUnit, mainOutput); | |
1675 | 1696 |
1676 if (backend.requiresPreamble && | 1697 if (backend.requiresPreamble && |
1677 !backend.htmlLibraryIsLoaded) { | 1698 !backend.htmlLibraryIsLoaded) { |
1678 compiler.reportHint(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); | 1699 compiler.reportHint(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); |
1679 } | 1700 } |
1680 // Return the total program size. | 1701 // Return the total program size. |
1681 return outputBuffers.values.fold(0, (a, b) => a + b.length); | 1702 return outputBuffers.values.fold(0, (a, b) => a + b.length); |
1682 } | 1703 } |
1683 | 1704 |
1684 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) { | 1705 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) { |
(...skipping 25 matching lines...) Expand all Loading... | |
1710 if (owner == null) { | 1731 if (owner == null) { |
1711 compiler.internalError(element, 'Owner is null.'); | 1732 compiler.internalError(element, 'Owner is null.'); |
1712 } | 1733 } |
1713 return elementDescriptors | 1734 return elementDescriptors |
1714 .putIfAbsent(fragment, () => new Map<Element, ClassBuilder>()) | 1735 .putIfAbsent(fragment, () => new Map<Element, ClassBuilder>()) |
1715 .putIfAbsent(owner, () => new ClassBuilder(owner, namer)); | 1736 .putIfAbsent(owner, () => new ClassBuilder(owner, namer)); |
1716 } | 1737 } |
1717 | 1738 |
1718 /// Emits support-code for deferred loading into [output]. | 1739 /// Emits support-code for deferred loading into [output]. |
1719 jsAst.Statement buildDeferredBoilerPlate( | 1740 jsAst.Statement buildDeferredBoilerPlate( |
1720 Map<OutputUnit, String> deferredLoadHashes) { | 1741 Map<OutputUnit, _DeferredOutputUnitHash> deferredLoadHashes) { |
1721 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 1742 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
1722 | 1743 |
1723 parts.add(js.statement(''' | 1744 parts.add(js.statement(''' |
1724 { | 1745 { |
1725 // Function for checking if a hunk is loaded given its hash. | 1746 // Function for checking if a hunk is loaded given its hash. |
1726 #isHunkLoaded = function(hunkHash) { | 1747 #isHunkLoaded = function(hunkHash) { |
1727 return !!$deferredInitializers[hunkHash]; | 1748 return !!$deferredInitializers[hunkHash]; |
1728 }; | 1749 }; |
1729 #deferredInitialized = new Object(null); | 1750 #deferredInitialized = new Object(null); |
1730 // Function for checking if a hunk is initialized given its hash. | 1751 // Function for checking if a hunk is initialized given its hash. |
(...skipping 13 matching lines...) Expand all Loading... | |
1744 embeddedNames.IS_HUNK_INITIALIZED), | 1765 embeddedNames.IS_HUNK_INITIALIZED), |
1745 "initializeLoadedHunk": generateEmbeddedGlobalAccess( | 1766 "initializeLoadedHunk": generateEmbeddedGlobalAccess( |
1746 embeddedNames.INITIALIZE_LOADED_HUNK), | 1767 embeddedNames.INITIALIZE_LOADED_HUNK), |
1747 "deferredInitialized": generateEmbeddedGlobalAccess( | 1768 "deferredInitialized": generateEmbeddedGlobalAccess( |
1748 embeddedNames.DEFERRED_INITIALIZED)})); | 1769 embeddedNames.DEFERRED_INITIALIZED)})); |
1749 | 1770 |
1750 // Write a javascript mapping from Deferred import load ids (derrived | 1771 // Write a javascript mapping from Deferred import load ids (derrived |
1751 // from the import prefix.) to a list of lists of uris of hunks to load, | 1772 // from the import prefix.) to a list of lists of uris of hunks to load, |
1752 // and a corresponding mapping to a list of hashes used by | 1773 // and a corresponding mapping to a list of hashes used by |
1753 // INITIALIZE_LOADED_HUNK and IS_HUNK_LOADED. | 1774 // INITIALIZE_LOADED_HUNK and IS_HUNK_LOADED. |
1754 Map<String, List<String>> deferredLibraryUris = | 1775 Map<String, List<jsAst.LiteralString>> deferredLibraryUris = |
1755 new Map<String, List<String>>(); | 1776 new Map<String, List<jsAst.LiteralString>>(); |
1756 Map<String, List<String>> deferredLibraryHashes = | 1777 Map<String, List<_DeferredOutputUnitHash>> deferredLibraryHashes = |
1757 new Map<String, List<String>>(); | 1778 new Map<String, List<_DeferredOutputUnitHash>>(); |
1758 compiler.deferredLoadTask.hunksToLoad.forEach( | 1779 compiler.deferredLoadTask.hunksToLoad.forEach( |
1759 (String loadId, List<OutputUnit>outputUnits) { | 1780 (String loadId, List<OutputUnit>outputUnits) { |
1760 List<String> uris = new List<String>(); | 1781 List<jsAst.LiteralString> uris = new List<jsAst.LiteralString>(); |
1761 List<String> hashes = new List<String>(); | 1782 List<_DeferredOutputUnitHash> hashes = |
1762 deferredLibraryHashes[loadId] = new List<String>(); | 1783 new List<_DeferredOutputUnitHash>(); |
1784 deferredLibraryHashes[loadId] = new List<_DeferredOutputUnitHash>(); | |
1763 for (OutputUnit outputUnit in outputUnits) { | 1785 for (OutputUnit outputUnit in outputUnits) { |
1764 uris.add(backend.deferredPartFileName(outputUnit.name)); | 1786 uris.add(js.escapedString( |
1787 backend.deferredPartFileName(outputUnit.name))); | |
1765 hashes.add(deferredLoadHashes[outputUnit]); | 1788 hashes.add(deferredLoadHashes[outputUnit]); |
1766 } | 1789 } |
1767 | 1790 |
1768 deferredLibraryUris[loadId] = uris; | 1791 deferredLibraryUris[loadId] = uris; |
1769 deferredLibraryHashes[loadId] = hashes; | 1792 deferredLibraryHashes[loadId] = hashes; |
1770 }); | 1793 }); |
1771 | 1794 |
1772 void emitMapping(String name, Map<String, List<String>> mapping) { | 1795 void emitMapping(String name, Map<String, List<jsAst.Expression>> mapping) { |
1773 List<jsAst.Property> properties = new List<jsAst.Property>(); | 1796 List<jsAst.Property> properties = new List<jsAst.Property>(); |
1774 mapping.forEach((String key, List<String> values) { | 1797 mapping.forEach((String key, List<jsAst.Expression> values) { |
1775 properties.add(new jsAst.Property(js.escapedString(key), | 1798 properties.add(new jsAst.Property(js.escapedString(key), |
1776 new jsAst.ArrayInitializer( | 1799 new jsAst.ArrayInitializer(values))); |
1777 values.map(js.escapedString).toList()))); | |
1778 }); | 1800 }); |
1779 jsAst.Node initializer = | 1801 jsAst.Node initializer = |
1780 new jsAst.ObjectInitializer(properties, isOneLiner: true); | 1802 new jsAst.ObjectInitializer(properties, isOneLiner: true); |
1781 | 1803 |
1782 jsAst.Node globalName = generateEmbeddedGlobalAccess(name); | 1804 jsAst.Node globalName = generateEmbeddedGlobalAccess(name); |
1783 parts.add(js.statement("# = #", [globalName, initializer])); | 1805 parts.add(js.statement("# = #", [globalName, initializer])); |
1784 } | 1806 } |
1785 | 1807 |
1786 emitMapping(embeddedNames.DEFERRED_LIBRARY_URIS, deferredLibraryUris); | 1808 emitMapping(embeddedNames.DEFERRED_LIBRARY_URIS, deferredLibraryUris); |
1787 emitMapping(embeddedNames.DEFERRED_LIBRARY_HASHES, | 1809 emitMapping(embeddedNames.DEFERRED_LIBRARY_HASHES, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1826 // in stack traces and profile entries. | 1848 // in stack traces and profile entries. |
1827 body.add(js.statement('var dart = #', libraryDescriptor)); | 1849 body.add(js.statement('var dart = #', libraryDescriptor)); |
1828 | 1850 |
1829 if (compiler.useContentSecurityPolicy) { | 1851 if (compiler.useContentSecurityPolicy) { |
1830 body.add(buildCspPrecompiledFunctionFor(outputUnit)); | 1852 body.add(buildCspPrecompiledFunctionFor(outputUnit)); |
1831 } | 1853 } |
1832 body.add( | 1854 body.add( |
1833 js.statement('$setupProgramName(dart, ${typesAccess}.length);')); | 1855 js.statement('$setupProgramName(dart, ${typesAccess}.length);')); |
1834 } | 1856 } |
1835 | 1857 |
1836 if (task.metadataCollector.types[outputUnit] != null) { | 1858 body..add(buildMetadata(program, outputUnit)) |
1837 body..add(buildMetadata(program, outputUnit)) | 1859 ..add(js.statement('${typesAccess}.push.apply(${typesAccess}, ' |
1838 ..add(js.statement('${typesAccess}.push.apply(${typesAccess}, ' | 1860 '${namer.deferredTypesName});')); |
1839 '${namer.deferredTypesName});')); | |
1840 } | |
1841 | 1861 |
1842 // Set the currentIsolate variable to the current isolate (which is | 1862 // Set the currentIsolate variable to the current isolate (which is |
1843 // provided as second argument). | 1863 // provided as second argument). |
1844 body.add(js.statement("${namer.currentIsolate} = arguments[1];")); | 1864 body.add(js.statement("${namer.currentIsolate} = arguments[1];")); |
1845 | 1865 |
1846 body.add(buildCompileTimeConstants(fragment.constants, | 1866 body.add(buildCompileTimeConstants(fragment.constants, |
1847 isMainFragment: false)); | 1867 isMainFragment: false)); |
1848 body.add(buildStaticNonFinalFieldInitializations(outputUnit)); | 1868 body.add(buildStaticNonFinalFieldInitializations(outputUnit)); |
1849 | 1869 |
1850 List<jsAst.Statement> statements = <jsAst.Statement>[]; | 1870 List<jsAst.Statement> statements = <jsAst.Statement>[]; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1980 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2000 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
1981 if (element.isInstanceMember) { | 2001 if (element.isInstanceMember) { |
1982 cachedClassBuilders.remove(element.enclosingClass); | 2002 cachedClassBuilders.remove(element.enclosingClass); |
1983 | 2003 |
1984 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2004 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
1985 | 2005 |
1986 } | 2006 } |
1987 } | 2007 } |
1988 } | 2008 } |
1989 } | 2009 } |
OLD | NEW |