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