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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 throw compiler.internalError(element, | 711 throw compiler.internalError(element, |
712 'Do not know how to reflect on this $element.'); | 712 'Do not know how to reflect on this $element.'); |
713 } | 713 } |
714 | 714 |
715 String namedParametersAsReflectionNames(Selector selector) { | 715 String namedParametersAsReflectionNames(Selector selector) { |
716 if (selector.getOrderedNamedArguments().isEmpty) return ''; | 716 if (selector.getOrderedNamedArguments().isEmpty) return ''; |
717 String names = selector.getOrderedNamedArguments().join(':'); | 717 String names = selector.getOrderedNamedArguments().join(':'); |
718 return ':$names'; | 718 return ':$names'; |
719 } | 719 } |
720 | 720 |
721 jsAst.FunctionDeclaration buildCspPrecompiledFunctionFor( | 721 jsAst.Statement buildCspPrecompiledFunctionFor( |
722 OutputUnit outputUnit) { | 722 OutputUnit outputUnit) { |
723 // TODO(ahe): Compute a hash code. | 723 // TODO(ahe): Compute a hash code. |
| 724 // TODO(sigurdm): Avoid this precompiled function. Generated |
| 725 // constructor-functions and getter/setter functions can be stored in the |
| 726 // library-description table. Setting properties on these can be moved to |
| 727 // finishClasses. |
724 return js.statement(''' | 728 return js.statement(''' |
725 function dart_precompiled(\$collectedClasses) { | 729 # = function (\$collectedClasses) { |
726 var \$desc; | 730 var \$desc; |
727 #; | 731 #; |
728 return #; | 732 return #; |
729 }''', | 733 };''', |
730 [cspPrecompiledFunctionFor(outputUnit), | 734 [generateEmbeddedGlobalAccess(embeddedNames.PRECOMPILED), |
| 735 cspPrecompiledFunctionFor(outputUnit), |
731 new jsAst.ArrayInitializer( | 736 new jsAst.ArrayInitializer( |
732 cspPrecompiledConstructorNamesFor(outputUnit))]); | 737 cspPrecompiledConstructorNamesFor(outputUnit))]); |
733 } | 738 } |
734 | 739 |
735 void emitClass(Class cls, ClassBuilder enclosingBuilder) { | 740 void emitClass(Class cls, ClassBuilder enclosingBuilder) { |
736 ClassElement classElement = cls.element; | 741 ClassElement classElement = cls.element; |
737 compiler.withCurrentElement(classElement, () { | 742 compiler.withCurrentElement(classElement, () { |
738 if (compiler.hasIncrementalSupport) { | 743 if (compiler.hasIncrementalSupport) { |
739 ClassBuilder cachedBuilder = | 744 ClassBuilder cachedBuilder = |
740 cachedClassBuilders.putIfAbsent(classElement, () { | 745 cachedClassBuilders.putIfAbsent(classElement, () { |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 jsAst.prettyPrint( | 1440 jsAst.prettyPrint( |
1436 getReflectionDataParser(this, backend, hasNativeClasses), | 1441 getReflectionDataParser(this, backend, hasNativeClasses), |
1437 compiler)) | 1442 compiler)) |
1438 ..add(n); | 1443 ..add(n); |
1439 | 1444 |
1440 // The argument to reflectionDataParser is assigned to a temporary 'dart' | 1445 // The argument to reflectionDataParser is assigned to a temporary 'dart' |
1441 // so that 'dart.' will appear as the prefix to dart methods in stack | 1446 // so that 'dart.' will appear as the prefix to dart methods in stack |
1442 // traces and profile entries. | 1447 // traces and profile entries. |
1443 mainOutput..add('var dart = [$n') | 1448 mainOutput..add('var dart = [$n') |
1444 ..addBuffer(libraryBuffer) | 1449 ..addBuffer(libraryBuffer) |
1445 ..add(']$N') | 1450 ..add(']$N'); |
1446 ..add('$parseReflectionDataName(dart)$N'); | 1451 if (compiler.useContentSecurityPolicy) { |
| 1452 jsAst.Statement precompiledFunctionAst = |
| 1453 buildCspPrecompiledFunctionFor(mainOutputUnit); |
| 1454 mainOutput.addBuffer( |
| 1455 jsAst.prettyPrint( |
| 1456 precompiledFunctionAst, |
| 1457 compiler, |
| 1458 monitor: compiler.dumpInfoTask, |
| 1459 allowVariableMinification: false)); |
| 1460 } |
| 1461 |
| 1462 mainOutput.add('$parseReflectionDataName(dart)$N'); |
1447 | 1463 |
1448 interceptorEmitter.emitGetInterceptorMethods(mainOutput); | 1464 interceptorEmitter.emitGetInterceptorMethods(mainOutput); |
1449 interceptorEmitter.emitOneShotInterceptors(mainOutput); | 1465 interceptorEmitter.emitOneShotInterceptors(mainOutput); |
1450 | 1466 |
1451 if (task.outputContainsConstantList) { | 1467 if (task.outputContainsConstantList) { |
1452 emitMakeConstantList(mainOutput); | 1468 emitMakeConstantList(mainOutput); |
1453 } | 1469 } |
1454 | 1470 |
1455 // Constants in checked mode call into RTI code to set type information | 1471 // Constants in checked mode call into RTI code to set type information |
1456 // which may need getInterceptor (and one-shot interceptor) methods, so | 1472 // which may need getInterceptor (and one-shot interceptor) methods, so |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 mainOutput.add(''' | 1537 mainOutput.add(''' |
1522 if (typeof print === "function") { | 1538 if (typeof print === "function") { |
1523 print("Size of $object: " | 1539 print("Size of $object: " |
1524 + String(Object.getOwnPropertyNames($object).length) | 1540 + String(Object.getOwnPropertyNames($object).length) |
1525 + ", fast properties " + HasFastProperties($object)); | 1541 + ", fast properties " + HasFastProperties($object)); |
1526 } | 1542 } |
1527 '''); | 1543 '''); |
1528 } | 1544 } |
1529 } | 1545 } |
1530 | 1546 |
1531 jsAst.FunctionDeclaration precompiledFunctionAst = | |
1532 buildCspPrecompiledFunctionFor(mainOutputUnit); | |
1533 emitInitFunction(mainOutput); | 1547 emitInitFunction(mainOutput); |
1534 emitMain(mainOutput, mainFragment.invokeMain); | 1548 emitMain(mainOutput, mainFragment.invokeMain); |
| 1549 |
1535 mainOutput.add('})()\n'); | 1550 mainOutput.add('})()\n'); |
1536 | 1551 |
1537 if (compiler.useContentSecurityPolicy) { | |
1538 mainOutput.addBuffer( | |
1539 jsAst.prettyPrint( | |
1540 precompiledFunctionAst, | |
1541 compiler, | |
1542 monitor: compiler.dumpInfoTask, | |
1543 allowVariableMinification: false)); | |
1544 } | |
1545 | 1552 |
1546 if (generateSourceMap) { | 1553 if (generateSourceMap) { |
1547 mainOutput.add( | 1554 mainOutput.add( |
1548 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); | 1555 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); |
1549 } | 1556 } |
1550 | 1557 |
1551 mainOutput.close(); | 1558 mainOutput.close(); |
1552 | 1559 |
1553 if (generateSourceMap) { | 1560 if (generateSourceMap) { |
1554 outputSourceMap(mainOutput, lineColumnCollector, '', | 1561 outputSourceMap(mainOutput, lineColumnCollector, '', |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 // Isolate.prototype object. We know this will turn it into a | 1897 // Isolate.prototype object. We know this will turn it into a |
1891 // slow object in V8, so instead we should do something similar | 1898 // slow object in V8, so instead we should do something similar |
1892 // to Isolate.$finishIsolateConstructor. | 1899 // to Isolate.$finishIsolateConstructor. |
1893 output | 1900 output |
1894 ..add('var ${namer.currentIsolate}$_=$_$isolatePropertiesName$N') | 1901 ..add('var ${namer.currentIsolate}$_=$_$isolatePropertiesName$N') |
1895 // The argument to reflectionDataParser is assigned to a temporary | 1902 // The argument to reflectionDataParser is assigned to a temporary |
1896 // 'dart' so that 'dart.' will appear as the prefix to dart methods | 1903 // 'dart' so that 'dart.' will appear as the prefix to dart methods |
1897 // in stack traces and profile entries. | 1904 // in stack traces and profile entries. |
1898 ..add('var dart = [$n ') | 1905 ..add('var dart = [$n ') |
1899 ..addBuffer(libraryDescriptorBuffer) | 1906 ..addBuffer(libraryDescriptorBuffer) |
1900 ..add(']$N') | 1907 ..add(']$N'); |
1901 ..add('$parseReflectionDataName(dart)$N'); | 1908 |
| 1909 if (compiler.useContentSecurityPolicy) { |
| 1910 jsAst.Statement precompiledFunctionAst = |
| 1911 buildCspPrecompiledFunctionFor(outputUnit); |
| 1912 |
| 1913 output.addBuffer( |
| 1914 jsAst.prettyPrint( |
| 1915 precompiledFunctionAst, compiler, |
| 1916 monitor: compiler.dumpInfoTask, |
| 1917 allowVariableMinification: false)); |
| 1918 } |
| 1919 output.add('$parseReflectionDataName(dart)$N'); |
1902 } | 1920 } |
1903 | 1921 |
1904 // Set the currentIsolate variable to the current isolate (which is | 1922 // Set the currentIsolate variable to the current isolate (which is |
1905 // provided as second argument). | 1923 // provided as second argument). |
1906 // We need to do this, because we use the same variable for setting up | 1924 // We need to do this, because we use the same variable for setting up |
1907 // the isolate-properties and for storing the current isolate. During | 1925 // the isolate-properties and for storing the current isolate. During |
1908 // the setup (the code above this lines) we must set the variable to | 1926 // the setup (the code above this lines) we must set the variable to |
1909 // the isolate-properties. | 1927 // the isolate-properties. |
1910 // After we have done the setup it must point to the current Isolate. | 1928 // After we have done the setup it must point to the current Isolate. |
1911 // Otherwise all methods/functions accessing isolate variables will | 1929 // Otherwise all methods/functions accessing isolate variables will |
1912 // access the wrong object. | 1930 // access the wrong object. |
1913 output.add("${namer.currentIsolate}$_=${_}arguments[1]$N"); | 1931 output.add("${namer.currentIsolate}$_=${_}arguments[1]$N"); |
1914 | 1932 |
1915 emitCompileTimeConstants( | 1933 emitCompileTimeConstants( |
1916 output, fragment.constants, isMainFragment: false); | 1934 output, fragment.constants, isMainFragment: false); |
1917 emitStaticNonFinalFieldInitializations(output, outputUnit); | 1935 emitStaticNonFinalFieldInitializations(output, outputUnit); |
| 1936 |
1918 output.add('}$N'); | 1937 output.add('}$N'); |
1919 | |
1920 if (compiler.useContentSecurityPolicy) { | |
1921 jsAst.FunctionDeclaration precompiledFunctionAst = | |
1922 buildCspPrecompiledFunctionFor(outputUnit); | |
1923 | |
1924 output.addBuffer( | |
1925 jsAst.prettyPrint( | |
1926 precompiledFunctionAst, compiler, | |
1927 monitor: compiler.dumpInfoTask, | |
1928 allowVariableMinification: false)); | |
1929 } | |
1930 | |
1931 // Make a unique hash of the code (before the sourcemaps are added) | 1938 // Make a unique hash of the code (before the sourcemaps are added) |
1932 // This will be used to retrieve the initializing function from the global | 1939 // This will be used to retrieve the initializing function from the global |
1933 // variable. | 1940 // variable. |
1934 String hash = hasher.getHash(); | 1941 String hash = hasher.getHash(); |
1935 | 1942 |
1936 output.add('${deferredInitializers}["$hash"]$_=$_' | 1943 output.add('${deferredInitializers}["$hash"]$_=$_' |
1937 '${deferredInitializers}.current$N'); | 1944 '${deferredInitializers}.current$N'); |
1938 | 1945 |
1939 if (generateSourceMap) { | 1946 if (generateSourceMap) { |
1940 | 1947 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2019 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
2013 if (element.isInstanceMember) { | 2020 if (element.isInstanceMember) { |
2014 cachedClassBuilders.remove(element.enclosingClass); | 2021 cachedClassBuilders.remove(element.enclosingClass); |
2015 | 2022 |
2016 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2023 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
2017 | 2024 |
2018 } | 2025 } |
2019 } | 2026 } |
2020 } | 2027 } |
2021 } | 2028 } |
OLD | NEW |