| 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 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 if (compiler.hasIncrementalSupport && isMainBuffer) { | 1155 if (compiler.hasIncrementalSupport && isMainBuffer) { |
| 1156 if (cachedEmittedConstants.contains(constant)) continue; | 1156 if (cachedEmittedConstants.contains(constant)) continue; |
| 1157 cachedEmittedConstants.add(constant); | 1157 cachedEmittedConstants.add(constant); |
| 1158 } | 1158 } |
| 1159 jsAst.Expression init = buildConstantInitializer(constant); | 1159 jsAst.Expression init = buildConstantInitializer(constant); |
| 1160 buffer.write(jsAst.prettyPrint(init, compiler, | 1160 buffer.write(jsAst.prettyPrint(init, compiler, |
| 1161 monitor: compiler.dumpInfoTask)); | 1161 monitor: compiler.dumpInfoTask)); |
| 1162 buffer.write('$N'); | 1162 buffer.write('$N'); |
| 1163 } | 1163 } |
| 1164 if (compiler.hasIncrementalSupport && isMainBuffer) { | 1164 if (compiler.hasIncrementalSupport && isMainBuffer) { |
| 1165 mainBuffer.add(cachedEmittedConstantsBuffer); | 1165 mainBuffer.write(cachedEmittedConstantsBuffer); |
| 1166 } | 1166 } |
| 1167 } | 1167 } |
| 1168 | 1168 |
| 1169 jsAst.Expression buildConstantInitializer(ConstantValue constant) { | 1169 jsAst.Expression buildConstantInitializer(ConstantValue constant) { |
| 1170 String name = namer.constantName(constant); | 1170 String name = namer.constantName(constant); |
| 1171 return js('#.# = #', | 1171 return js('#.# = #', |
| 1172 [namer.globalObjectForConstant(constant), name, | 1172 [namer.globalObjectForConstant(constant), name, |
| 1173 constantInitializerExpression(constant)]); | 1173 constantInitializerExpression(constant)]); |
| 1174 } | 1174 } |
| 1175 | 1175 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 function convertToFastObject(properties) { | 1379 function convertToFastObject(properties) { |
| 1380 // Create an instance that uses 'properties' as prototype. This should | 1380 // Create an instance that uses 'properties' as prototype. This should |
| 1381 // make 'properties' a fast object. | 1381 // make 'properties' a fast object. |
| 1382 function MyClass() {}; | 1382 function MyClass() {}; |
| 1383 MyClass.prototype = properties; | 1383 MyClass.prototype = properties; |
| 1384 new MyClass(); | 1384 new MyClass(); |
| 1385 #; | 1385 #; |
| 1386 return properties; | 1386 return properties; |
| 1387 }''', [debugCode]); | 1387 }''', [debugCode]); |
| 1388 | 1388 |
| 1389 mainBuffer.add(jsAst.prettyPrint(convertToFastObject, compiler)); | 1389 mainBuffer.write(jsAst.prettyPrint(convertToFastObject, compiler)); |
| 1390 mainBuffer.add(N); | 1390 mainBuffer.write(N); |
| 1391 } | 1391 } |
| 1392 | 1392 |
| 1393 void writeLibraryDescriptors(CodeBuffer buffer, LibraryElement library) { | 1393 void writeLibraryDescriptors(CodeBuffer buffer, LibraryElement library) { |
| 1394 var uri = ""; | 1394 var uri = ""; |
| 1395 if (!compiler.enableMinification || backend.mustPreserveUris) { | 1395 if (!compiler.enableMinification || backend.mustPreserveUris) { |
| 1396 uri = library.canonicalUri; | 1396 uri = library.canonicalUri; |
| 1397 if (uri.scheme == 'file' && compiler.outputUri != null) { | 1397 if (uri.scheme == 'file' && compiler.outputUri != null) { |
| 1398 uri = relativize(compiler.outputUri, library.canonicalUri, false); | 1398 uri = relativize(compiler.outputUri, library.canonicalUri, false); |
| 1399 } | 1399 } |
| 1400 } | 1400 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 compiler.internalError(pendingStatics.first, | 1599 compiler.internalError(pendingStatics.first, |
| 1600 'Pending statics (see above).'); | 1600 'Pending statics (see above).'); |
| 1601 } | 1601 } |
| 1602 } | 1602 } |
| 1603 | 1603 |
| 1604 void emitMainOutputUnit(Map<OutputUnit, String> deferredLoadHashes, | 1604 void emitMainOutputUnit(Map<OutputUnit, String> deferredLoadHashes, |
| 1605 CodeBuffer nativeBuffer) { | 1605 CodeBuffer nativeBuffer) { |
| 1606 bool isProgramSplit = compiler.deferredLoadTask.isProgramSplit; | 1606 bool isProgramSplit = compiler.deferredLoadTask.isProgramSplit; |
| 1607 OutputUnit mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; | 1607 OutputUnit mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; |
| 1608 | 1608 |
| 1609 mainBuffer.add(buildGeneratedBy()); | 1609 mainBuffer.write(buildGeneratedBy()); |
| 1610 addComment(HOOKS_API_USAGE, mainBuffer); | 1610 addComment(HOOKS_API_USAGE, mainBuffer); |
| 1611 | 1611 |
| 1612 if (isProgramSplit) { | 1612 if (isProgramSplit) { |
| 1613 /// For deferred loading we communicate the initializers via this global | 1613 /// For deferred loading we communicate the initializers via this global |
| 1614 /// variable. The deferred hunks will add their initialization to this. | 1614 /// variable. The deferred hunks will add their initialization to this. |
| 1615 /// The semicolon is important in minified mode, without it the | 1615 /// The semicolon is important in minified mode, without it the |
| 1616 /// following parenthesis looks like a call to the object literal. | 1616 /// following parenthesis looks like a call to the object literal. |
| 1617 mainBuffer..add( | 1617 mainBuffer..write( |
| 1618 'self.${deferredInitializers} = self.${deferredInitializers} || ' | 1618 'self.${deferredInitializers} = self.${deferredInitializers} || ' |
| 1619 'Object.create(null);$n'); | 1619 'Object.create(null);$n'); |
| 1620 } | 1620 } |
| 1621 | 1621 |
| 1622 // Using a named function here produces easier to read stack traces in | 1622 // Using a named function here produces easier to read stack traces in |
| 1623 // Chrome/V8. | 1623 // Chrome/V8. |
| 1624 mainBuffer.add('(function(${namer.currentIsolate})$_{\n'); | 1624 mainBuffer.write('(function(${namer.currentIsolate})$_{\n'); |
| 1625 if (compiler.hasIncrementalSupport) { | 1625 if (compiler.hasIncrementalSupport) { |
| 1626 mainBuffer.add(jsAst.prettyPrint(js.statement( | 1626 mainBuffer.write(jsAst.prettyPrint(js.statement( |
| 1627 """ | 1627 """ |
| 1628 { | 1628 { |
| 1629 #helper = #helper || Object.create(null); | 1629 #helper = #helper || Object.create(null); |
| 1630 #helper.patch = function(a) { eval(a)}; | 1630 #helper.patch = function(a) { eval(a)}; |
| 1631 #helper.schemaChange = #schemaChange; | 1631 #helper.schemaChange = #schemaChange; |
| 1632 #helper.addMethod = #addMethod; | 1632 #helper.addMethod = #addMethod; |
| 1633 #helper.extractStubs = function(array, name, isStatic, originalDescriptor) { | 1633 #helper.extractStubs = function(array, name, isStatic, originalDescriptor) { |
| 1634 var descriptor = Object.create(null); | 1634 var descriptor = Object.create(null); |
| 1635 this.addStubs(descriptor, array, name, isStatic, originalDescriptor, []); | 1635 this.addStubs(descriptor, array, name, isStatic, originalDescriptor, []); |
| 1636 return descriptor; | 1636 return descriptor; |
| 1637 }; | 1637 }; |
| 1638 }""", | 1638 }""", |
| 1639 { 'helper': js('this.#', [namer.incrementalHelperName]), | 1639 { 'helper': js('this.#', [namer.incrementalHelperName]), |
| 1640 'schemaChange': buildSchemaChangeFunction(), | 1640 'schemaChange': buildSchemaChangeFunction(), |
| 1641 'addMethod': buildIncrementalAddMethod() }), compiler)); | 1641 'addMethod': buildIncrementalAddMethod() }), compiler)); |
| 1642 } | 1642 } |
| 1643 if (isProgramSplit) { | 1643 if (isProgramSplit) { |
| 1644 /// We collect all the global state of the, so it can be passed to the | 1644 /// We collect all the global state of the, so it can be passed to the |
| 1645 /// initializer of deferred files. | 1645 /// initializer of deferred files. |
| 1646 mainBuffer.add('var ${globalsHolder}$_=${_}Object.create(null)$N'); | 1646 mainBuffer.write('var ${globalsHolder}$_=${_}Object.create(null)$N'); |
| 1647 } | 1647 } |
| 1648 mainBuffer.add('function dart()$_{$n' | 1648 mainBuffer.write('function dart()$_{$n' |
| 1649 '${_}${_}this.x$_=${_}0$N' | 1649 '${_}${_}this.x$_=${_}0$N' |
| 1650 '${_}${_}delete this.x$N' | 1650 '${_}${_}delete this.x$N' |
| 1651 '}$n'); | 1651 '}$n'); |
| 1652 for (String globalObject in Namer.reservedGlobalObjectNames) { | 1652 for (String globalObject in Namer.reservedGlobalObjectNames) { |
| 1653 // The global objects start as so-called "slow objects". For V8, this | 1653 // The global objects start as so-called "slow objects". For V8, this |
| 1654 // means that it won't try to make map transitions as we add properties | 1654 // means that it won't try to make map transitions as we add properties |
| 1655 // to these objects. Later on, we attempt to turn these objects into | 1655 // to these objects. Later on, we attempt to turn these objects into |
| 1656 // fast objects by calling "convertToFastObject" (see | 1656 // fast objects by calling "convertToFastObject" (see |
| 1657 // [emitConvertToFastObjectFunction]). | 1657 // [emitConvertToFastObjectFunction]). |
| 1658 mainBuffer.write('var ${globalObject}$_=${_}'); | 1658 mainBuffer.write('var ${globalObject}$_=${_}'); |
| 1659 if(isProgramSplit) { | 1659 if(isProgramSplit) { |
| 1660 mainBuffer.add('${globalsHolder}.$globalObject$_=${_}'); | 1660 mainBuffer.write('${globalsHolder}.$globalObject$_=${_}'); |
| 1661 } | 1661 } |
| 1662 mainBuffer.write('new dart$N'); | 1662 mainBuffer.write('new dart$N'); |
| 1663 } | 1663 } |
| 1664 | 1664 |
| 1665 mainBuffer.add('function ${namer.isolateName}()$_{}\n'); | 1665 mainBuffer.write('function ${namer.isolateName}()$_{}\n'); |
| 1666 if (isProgramSplit) { | 1666 if (isProgramSplit) { |
| 1667 mainBuffer | 1667 mainBuffer |
| 1668 .write('${globalsHolder}.${namer.isolateName}$_=$_' | 1668 .write('${globalsHolder}.${namer.isolateName}$_=$_' |
| 1669 '${namer.isolateName}$N' | 1669 '${namer.isolateName}$N' |
| 1670 '${globalsHolder}.$initName$_=${_}$initName$N'); | 1670 '${globalsHolder}.$initName$_=${_}$initName$N'); |
| 1671 } | 1671 } |
| 1672 mainBuffer.add('init()$N$n'); | 1672 mainBuffer.write('init()$N$n'); |
| 1673 mainBuffer.add('$isolateProperties$_=$_$isolatePropertiesName$N'); | 1673 mainBuffer.write('$isolateProperties$_=$_$isolatePropertiesName$N'); |
| 1674 | 1674 |
| 1675 emitStaticFunctions(task.outputStaticLists[mainOutputUnit]); | 1675 emitStaticFunctions(task.outputStaticLists[mainOutputUnit]); |
| 1676 | 1676 |
| 1677 // Only output the classesCollector if we actually have any classes. | 1677 // Only output the classesCollector if we actually have any classes. |
| 1678 if (needsDefineClass || | 1678 if (needsDefineClass || |
| 1679 !(nativeClasses.isEmpty && | 1679 !(nativeClasses.isEmpty && |
| 1680 compiler.codegenWorld.staticFunctionsNeedingGetter.isEmpty && | 1680 compiler.codegenWorld.staticFunctionsNeedingGetter.isEmpty && |
| 1681 outputClassLists.values.every((classList) => classList.isEmpty) && | 1681 outputClassLists.values.every((classList) => classList.isEmpty) && |
| 1682 typedefsNeededForReflection.isEmpty)) { | 1682 typedefsNeededForReflection.isEmpty)) { |
| 1683 // Shorten the code by using "$$" as temporary. | 1683 // Shorten the code by using "$$" as temporary. |
| 1684 classesCollector = r"$$"; | 1684 classesCollector = r"$$"; |
| 1685 mainBuffer.add('var $classesCollector$_=${_}Object.create(null)$N$n'); | 1685 mainBuffer.write('var $classesCollector$_=${_}Object.create(null)$N$n'); |
| 1686 } | 1686 } |
| 1687 | 1687 |
| 1688 if (!nativeClasses.isEmpty) { | 1688 if (!nativeClasses.isEmpty) { |
| 1689 addComment('Native classes', mainBuffer); | 1689 addComment('Native classes', mainBuffer); |
| 1690 } | 1690 } |
| 1691 | 1691 |
| 1692 List<ClassElement> classes = task.outputClassLists[mainOutputUnit]; | 1692 List<ClassElement> classes = task.outputClassLists[mainOutputUnit]; |
| 1693 if (classes != null) { | 1693 if (classes != null) { |
| 1694 for (ClassElement element in classes) { | 1694 for (ClassElement element in classes) { |
| 1695 generateClass(element, getElementDescriptor(element)); | 1695 generateClass(element, getElementDescriptor(element)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1717 } | 1717 } |
| 1718 | 1718 |
| 1719 mainBuffer | 1719 mainBuffer |
| 1720 ..write('(') | 1720 ..write('(') |
| 1721 ..write( | 1721 ..write( |
| 1722 jsAst.prettyPrint( | 1722 jsAst.prettyPrint( |
| 1723 getReflectionDataParser(classesCollector, backend), | 1723 getReflectionDataParser(classesCollector, backend), |
| 1724 compiler)) | 1724 compiler)) |
| 1725 ..write(')') | 1725 ..write(')') |
| 1726 ..write('([$n') | 1726 ..write('([$n') |
| 1727 ..add(libraryBuffer) | 1727 ..write(libraryBuffer) |
| 1728 ..write('])$N'); | 1728 ..write('])$N'); |
| 1729 | 1729 |
| 1730 emitFinishClassesInvocationIfNecessary(mainBuffer); | 1730 emitFinishClassesInvocationIfNecessary(mainBuffer); |
| 1731 } | 1731 } |
| 1732 | 1732 |
| 1733 interceptorEmitter.emitGetInterceptorMethods(mainBuffer); | 1733 interceptorEmitter.emitGetInterceptorMethods(mainBuffer); |
| 1734 interceptorEmitter.emitOneShotInterceptors(mainBuffer); | 1734 interceptorEmitter.emitOneShotInterceptors(mainBuffer); |
| 1735 | 1735 |
| 1736 if (task.outputContainsConstantList) { | 1736 if (task.outputContainsConstantList) { |
| 1737 emitMakeConstantList(mainBuffer); | 1737 emitMakeConstantList(mainBuffer); |
| 1738 } | 1738 } |
| 1739 | 1739 |
| 1740 // Constants in checked mode call into RTI code to set type information | 1740 // Constants in checked mode call into RTI code to set type information |
| 1741 // which may need getInterceptor (and one-shot interceptor) methods, so | 1741 // which may need getInterceptor (and one-shot interceptor) methods, so |
| 1742 // we have to make sure that [emitGetInterceptorMethods] and | 1742 // we have to make sure that [emitGetInterceptorMethods] and |
| 1743 // [emitOneShotInterceptors] have been called. | 1743 // [emitOneShotInterceptors] have been called. |
| 1744 emitCompileTimeConstants(mainBuffer, mainOutputUnit); | 1744 emitCompileTimeConstants(mainBuffer, mainOutputUnit); |
| 1745 | 1745 |
| 1746 emitDeferredBoilerPlate(mainBuffer, deferredLoadHashes); | 1746 emitDeferredBoilerPlate(mainBuffer, deferredLoadHashes); |
| 1747 | 1747 |
| 1748 // Static field initializations require the classes and compile-time | 1748 // Static field initializations require the classes and compile-time |
| 1749 // constants to be set up. | 1749 // constants to be set up. |
| 1750 emitStaticNonFinalFieldInitializations(mainBuffer, mainOutputUnit); | 1750 emitStaticNonFinalFieldInitializations(mainBuffer, mainOutputUnit); |
| 1751 interceptorEmitter.emitInterceptedNames(mainBuffer); | 1751 interceptorEmitter.emitInterceptedNames(mainBuffer); |
| 1752 interceptorEmitter.emitMapTypeToInterceptor(mainBuffer); | 1752 interceptorEmitter.emitMapTypeToInterceptor(mainBuffer); |
| 1753 emitLazilyInitializedStaticFields(mainBuffer); | 1753 emitLazilyInitializedStaticFields(mainBuffer); |
| 1754 | 1754 |
| 1755 mainBuffer.writeln(); | 1755 mainBuffer.writeln(); |
| 1756 mainBuffer.add(nativeBuffer); | 1756 mainBuffer.write(nativeBuffer); |
| 1757 | 1757 |
| 1758 metadataEmitter.emitMetadata(mainBuffer); | 1758 metadataEmitter.emitMetadata(mainBuffer); |
| 1759 | 1759 |
| 1760 isolateProperties = isolatePropertiesName; | 1760 isolateProperties = isolatePropertiesName; |
| 1761 // The following code should not use the short-hand for the | 1761 // The following code should not use the short-hand for the |
| 1762 // initialStatics. | 1762 // initialStatics. |
| 1763 mainBuffer.add('${namer.currentIsolate}$_=${_}null$N'); | 1763 mainBuffer.write('${namer.currentIsolate}$_=${_}null$N'); |
| 1764 | 1764 |
| 1765 emitFinishIsolateConstructorInvocation(mainBuffer); | 1765 emitFinishIsolateConstructorInvocation(mainBuffer); |
| 1766 mainBuffer.add( | 1766 mainBuffer.write( |
| 1767 '${namer.currentIsolate}$_=${_}new ${namer.isolateName}()$N'); | 1767 '${namer.currentIsolate}$_=${_}new ${namer.isolateName}()$N'); |
| 1768 | 1768 |
| 1769 emitConvertToFastObjectFunction(); | 1769 emitConvertToFastObjectFunction(); |
| 1770 for (String globalObject in Namer.reservedGlobalObjectNames) { | 1770 for (String globalObject in Namer.reservedGlobalObjectNames) { |
| 1771 mainBuffer.add('$globalObject = convertToFastObject($globalObject)$N'); | 1771 mainBuffer.write('$globalObject = convertToFastObject($globalObject)$N'); |
| 1772 } | 1772 } |
| 1773 if (DEBUG_FAST_OBJECTS) { | 1773 if (DEBUG_FAST_OBJECTS) { |
| 1774 mainBuffer.add(r''' | 1774 mainBuffer.write(r''' |
| 1775 // The following only works on V8 when run with option | 1775 // The following only works on V8 when run with option |
| 1776 // "--allow-natives-syntax". We use'new Function' because the | 1776 // "--allow-natives-syntax". We use'new Function' because the |
| 1777 // miniparser does not understand V8 native syntax. | 1777 // miniparser does not understand V8 native syntax. |
| 1778 if (typeof print === "function") { | 1778 if (typeof print === "function") { |
| 1779 var HasFastProperties = | 1779 var HasFastProperties = |
| 1780 new Function("a", "return %HasFastProperties(a)"); | 1780 new Function("a", "return %HasFastProperties(a)"); |
| 1781 print("Size of global helper object: " | 1781 print("Size of global helper object: " |
| 1782 + String(Object.getOwnPropertyNames(H).length) | 1782 + String(Object.getOwnPropertyNames(H).length) |
| 1783 + ", fast properties " + HasFastProperties(H)); | 1783 + ", fast properties " + HasFastProperties(H)); |
| 1784 print("Size of global platform object: " | 1784 print("Size of global platform object: " |
| 1785 + String(Object.getOwnPropertyNames(P).length) | 1785 + String(Object.getOwnPropertyNames(P).length) |
| 1786 + ", fast properties " + HasFastProperties(P)); | 1786 + ", fast properties " + HasFastProperties(P)); |
| 1787 print("Size of global dart:html object: " | 1787 print("Size of global dart:html object: " |
| 1788 + String(Object.getOwnPropertyNames(W).length) | 1788 + String(Object.getOwnPropertyNames(W).length) |
| 1789 + ", fast properties " + HasFastProperties(W)); | 1789 + ", fast properties " + HasFastProperties(W)); |
| 1790 print("Size of isolate properties object: " | 1790 print("Size of isolate properties object: " |
| 1791 + String(Object.getOwnPropertyNames($).length) | 1791 + String(Object.getOwnPropertyNames($).length) |
| 1792 + ", fast properties " + HasFastProperties($)); | 1792 + ", fast properties " + HasFastProperties($)); |
| 1793 print("Size of constant object: " | 1793 print("Size of constant object: " |
| 1794 + String(Object.getOwnPropertyNames(C).length) | 1794 + String(Object.getOwnPropertyNames(C).length) |
| 1795 + ", fast properties " + HasFastProperties(C)); | 1795 + ", fast properties " + HasFastProperties(C)); |
| 1796 var names = Object.getOwnPropertyNames($); | 1796 var names = Object.getOwnPropertyNames($); |
| 1797 for (var i = 0; i < names.length; i++) { | 1797 for (var i = 0; i < names.length; i++) { |
| 1798 print("$." + names[i]); | 1798 print("$." + names[i]); |
| 1799 } | 1799 } |
| 1800 } | 1800 } |
| 1801 '''); | 1801 '''); |
| 1802 for (String object in Namer.userGlobalObjects) { | 1802 for (String object in Namer.userGlobalObjects) { |
| 1803 mainBuffer.add(''' | 1803 mainBuffer.write(''' |
| 1804 if (typeof print === "function") { | 1804 if (typeof print === "function") { |
| 1805 print("Size of $object: " | 1805 print("Size of $object: " |
| 1806 + String(Object.getOwnPropertyNames($object).length) | 1806 + String(Object.getOwnPropertyNames($object).length) |
| 1807 + ", fast properties " + HasFastProperties($object)); | 1807 + ", fast properties " + HasFastProperties($object)); |
| 1808 } | 1808 } |
| 1809 '''); | 1809 '''); |
| 1810 } | 1810 } |
| 1811 } | 1811 } |
| 1812 | 1812 |
| 1813 jsAst.FunctionDeclaration precompiledFunctionAst = | 1813 jsAst.FunctionDeclaration precompiledFunctionAst = |
| 1814 buildCspPrecompiledFunctionFor(mainOutputUnit); | 1814 buildCspPrecompiledFunctionFor(mainOutputUnit); |
| 1815 emitInitFunction(mainBuffer); | 1815 emitInitFunction(mainBuffer); |
| 1816 emitMain(mainBuffer); | 1816 emitMain(mainBuffer); |
| 1817 mainBuffer.add('})()\n'); | 1817 mainBuffer.write('})()\n'); |
| 1818 | 1818 |
| 1819 if (compiler.useContentSecurityPolicy) { | 1819 if (compiler.useContentSecurityPolicy) { |
| 1820 mainBuffer.write( | 1820 mainBuffer.write( |
| 1821 jsAst.prettyPrint( | 1821 jsAst.prettyPrint( |
| 1822 precompiledFunctionAst, | 1822 precompiledFunctionAst, |
| 1823 compiler, | 1823 compiler, |
| 1824 monitor: compiler.dumpInfoTask, | 1824 monitor: compiler.dumpInfoTask, |
| 1825 allowVariableMinification: false).getText()); | 1825 allowVariableMinification: false).getText()); |
| 1826 } | 1826 } |
| 1827 | 1827 |
| 1828 String assembledCode = mainBuffer.getText(); | 1828 String assembledCode = mainBuffer.getText(); |
| 1829 if (generateSourceMap) { | 1829 if (generateSourceMap) { |
| 1830 outputSourceMap(assembledCode, mainBuffer, '', | 1830 outputSourceMap(assembledCode, mainBuffer, '', |
| 1831 compiler.sourceMapUri, compiler.outputUri); | 1831 compiler.sourceMapUri, compiler.outputUri); |
| 1832 mainBuffer.add( | 1832 mainBuffer.write( |
| 1833 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); | 1833 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); |
| 1834 assembledCode = mainBuffer.getText(); | 1834 assembledCode = mainBuffer.getText(); |
| 1835 } | 1835 } |
| 1836 | 1836 |
| 1837 compiler.outputProvider('', 'js') | 1837 compiler.outputProvider('', 'js') |
| 1838 ..add(assembledCode) | 1838 ..add(assembledCode) |
| 1839 ..close(); | 1839 ..close(); |
| 1840 compiler.assembledCode = assembledCode; | 1840 compiler.assembledCode = assembledCode; |
| 1841 } | 1841 } |
| 1842 | 1842 |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2214 precompiledFunctionAst, compiler, | 2214 precompiledFunctionAst, compiler, |
| 2215 monitor: compiler.dumpInfoTask, | 2215 monitor: compiler.dumpInfoTask, |
| 2216 allowVariableMinification: false).getText()); | 2216 allowVariableMinification: false).getText()); |
| 2217 } | 2217 } |
| 2218 | 2218 |
| 2219 // Make a unique hash of the code (before the sourcemaps are added) | 2219 // Make a unique hash of the code (before the sourcemaps are added) |
| 2220 // This will be used to retrieve the initializing function from the global | 2220 // This will be used to retrieve the initializing function from the global |
| 2221 // variable. | 2221 // variable. |
| 2222 String hash = hashOfString(outputBuffer.getText()); | 2222 String hash = hashOfString(outputBuffer.getText()); |
| 2223 | 2223 |
| 2224 outputBuffer.add('${deferredInitializers}["$hash"]$_=$_' | 2224 outputBuffer.write('${deferredInitializers}["$hash"]$_=$_' |
| 2225 '${deferredInitializers}.current$N'); | 2225 '${deferredInitializers}.current$N'); |
| 2226 | 2226 |
| 2227 String partPrefix = deferredPartFileName(outputUnit, addExtension: false); | 2227 String partPrefix = deferredPartFileName(outputUnit, addExtension: false); |
| 2228 if (generateSourceMap) { | 2228 if (generateSourceMap) { |
| 2229 Uri mapUri, partUri; | 2229 Uri mapUri, partUri; |
| 2230 Uri sourceMapUri = compiler.sourceMapUri; | 2230 Uri sourceMapUri = compiler.sourceMapUri; |
| 2231 Uri outputUri = compiler.outputUri; | 2231 Uri outputUri = compiler.outputUri; |
| 2232 | 2232 |
| 2233 String partName = "$partPrefix.part"; | 2233 String partName = "$partPrefix.part"; |
| 2234 | 2234 |
| 2235 if (sourceMapUri != null) { | 2235 if (sourceMapUri != null) { |
| 2236 String mapFileName = partName + ".js.map"; | 2236 String mapFileName = partName + ".js.map"; |
| 2237 List<String> mapSegments = sourceMapUri.pathSegments.toList(); | 2237 List<String> mapSegments = sourceMapUri.pathSegments.toList(); |
| 2238 mapSegments[mapSegments.length - 1] = mapFileName; | 2238 mapSegments[mapSegments.length - 1] = mapFileName; |
| 2239 mapUri = compiler.sourceMapUri.replace(pathSegments: mapSegments); | 2239 mapUri = compiler.sourceMapUri.replace(pathSegments: mapSegments); |
| 2240 } | 2240 } |
| 2241 | 2241 |
| 2242 if (outputUri != null) { | 2242 if (outputUri != null) { |
| 2243 String partFileName = partName + ".js"; | 2243 String partFileName = partName + ".js"; |
| 2244 List<String> partSegments = outputUri.pathSegments.toList(); | 2244 List<String> partSegments = outputUri.pathSegments.toList(); |
| 2245 partSegments[partSegments.length - 1] = partFileName; | 2245 partSegments[partSegments.length - 1] = partFileName; |
| 2246 partUri = compiler.outputUri.replace(pathSegments: partSegments); | 2246 partUri = compiler.outputUri.replace(pathSegments: partSegments); |
| 2247 } | 2247 } |
| 2248 | 2248 |
| 2249 outputSourceMap(outputBuffer.getText(), outputBuffer, partName, | 2249 outputSourceMap(outputBuffer.getText(), outputBuffer, partName, |
| 2250 mapUri, partUri); | 2250 mapUri, partUri); |
| 2251 outputBuffer.add(generateSourceMapTag(mapUri, partUri)); | 2251 outputBuffer.write(generateSourceMapTag(mapUri, partUri)); |
| 2252 } | 2252 } |
| 2253 | 2253 |
| 2254 outputBuffers[outputUnit] = outputBuffer; | 2254 outputBuffers[outputUnit] = outputBuffer; |
| 2255 compiler.outputProvider(partPrefix, 'part.js') | 2255 compiler.outputProvider(partPrefix, 'part.js') |
| 2256 ..add(outputBuffer.getText()) | 2256 ..add(outputBuffer.getText()) |
| 2257 ..close(); | 2257 ..close(); |
| 2258 | 2258 |
| 2259 hunkHashes[outputUnit] = hash; | 2259 hunkHashes[outputUnit] = hash; |
| 2260 } | 2260 } |
| 2261 return hunkHashes; | 2261 return hunkHashes; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2288 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2288 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2289 if (element.isInstanceMember) { | 2289 if (element.isInstanceMember) { |
| 2290 cachedClassBuilders.remove(element.enclosingClass); | 2290 cachedClassBuilders.remove(element.enclosingClass); |
| 2291 | 2291 |
| 2292 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2292 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2293 | 2293 |
| 2294 } | 2294 } |
| 2295 } | 2295 } |
| 2296 } | 2296 } |
| 2297 } | 2297 } |
| OLD | NEW |