| 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 library dart2js.js_emitter.full_emitter; | 5 library dart2js.js_emitter.full_emitter; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:collection' show HashMap; | 8 import 'dart:collection' show HashMap; |
| 9 | 9 |
| 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 containerBuilder.addMemberMethod(method, builder); | 603 containerBuilder.addMemberMethod(method, builder); |
| 604 getElementDescriptor(element, fragment).properties | 604 getElementDescriptor(element, fragment).properties |
| 605 .addAll(builder.properties); | 605 .addAll(builder.properties); |
| 606 } | 606 } |
| 607 } | 607 } |
| 608 | 608 |
| 609 jsAst.Statement buildStaticNonFinalFieldInitializations( | 609 jsAst.Statement buildStaticNonFinalFieldInitializations( |
| 610 OutputUnit outputUnit) { | 610 OutputUnit outputUnit) { |
| 611 jsAst.Statement buildInitialization(Element element, | 611 jsAst.Statement buildInitialization(Element element, |
| 612 jsAst.Expression initialValue) { | 612 jsAst.Expression initialValue) { |
| 613 // Note: `namer.currentIsolate` refers to the isolate properties here. | 613 return js.statement('${namer.staticStateHolder}.# = #', |
| 614 return js.statement('${namer.currentIsolate}.# = #', | |
| 615 [namer.globalPropertyName(element), initialValue]); | 614 [namer.globalPropertyName(element), initialValue]); |
| 616 } | 615 } |
| 617 | 616 |
| 618 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); | 617 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); |
| 619 JavaScriptConstantCompiler handler = backend.constants; | 618 JavaScriptConstantCompiler handler = backend.constants; |
| 620 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 619 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
| 621 | 620 |
| 622 Iterable<Element> fields = outputStaticNonFinalFieldLists[outputUnit]; | 621 Iterable<Element> fields = outputStaticNonFinalFieldLists[outputUnit]; |
| 623 // If the outputUnit does not contain any static non-final fields, then | 622 // If the outputUnit does not contain any static non-final fields, then |
| 624 // [fields] is `null`. | 623 // [fields] is `null`. |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 #setupProgramName(dart, 0); | 1458 #setupProgramName(dart, 0); |
| 1460 | 1459 |
| 1461 #getInterceptorMethods; | 1460 #getInterceptorMethods; |
| 1462 #oneShotInterceptors; | 1461 #oneShotInterceptors; |
| 1463 | 1462 |
| 1464 #makeConstantList; | 1463 #makeConstantList; |
| 1465 | 1464 |
| 1466 // We abuse the short name used for the isolate here to store | 1465 // We abuse the short name used for the isolate here to store |
| 1467 // the isolate properties. This is safe as long as the real isolate | 1466 // the isolate properties. This is safe as long as the real isolate |
| 1468 // object does not exist yet. | 1467 // object does not exist yet. |
| 1469 var ${namer.currentIsolate} = #isolatePropertiesName; | 1468 var ${namer.staticStateHolder} = #isolatePropertiesName; |
| 1470 | 1469 |
| 1471 // Constants in checked mode call into RTI code to set type information | 1470 // Constants in checked mode call into RTI code to set type information |
| 1472 // which may need getInterceptor (and one-shot interceptor) methods, so | 1471 // which may need getInterceptor (and one-shot interceptor) methods, so |
| 1473 // we have to make sure that [emitGetInterceptorMethods] and | 1472 // we have to make sure that [emitGetInterceptorMethods] and |
| 1474 // [emitOneShotInterceptors] have been called. | 1473 // [emitOneShotInterceptors] have been called. |
| 1475 #compileTimeConstants; | 1474 #compileTimeConstants; |
| 1476 | 1475 |
| 1477 // Static field initializations require the classes and compile-time | 1476 // Static field initializations require the classes and compile-time |
| 1478 // constants to be set up. | 1477 // constants to be set up. |
| 1479 #staticNonFinalInitializers; | 1478 #staticNonFinalInitializers; |
| 1480 | 1479 |
| 1481 ${namer.currentIsolate} = null; | 1480 ${namer.staticStateHolder} = null; |
| 1482 | 1481 |
| 1483 #deferredBoilerPlate; | 1482 #deferredBoilerPlate; |
| 1484 | 1483 |
| 1485 #typeToInterceptorMap; | 1484 #typeToInterceptorMap; |
| 1486 | 1485 |
| 1487 #lazyStaticFields; | 1486 #lazyStaticFields; |
| 1488 | 1487 |
| 1489 #isolateName = $finishIsolateConstructorName(#isolateName); | 1488 #isolateName = $finishIsolateConstructorName(#isolateName); |
| 1490 | 1489 |
| 1491 ${namer.currentIsolate} = new #isolateName(); | 1490 ${namer.staticStateHolder} = new #isolateName(); |
| 1492 | 1491 |
| 1493 #metadata; | 1492 #metadata; |
| 1494 | 1493 |
| 1495 #convertToFastObject; | 1494 #convertToFastObject; |
| 1496 #convertToSlowObject; | 1495 #convertToSlowObject; |
| 1497 | 1496 |
| 1498 #convertGlobalObjectsToFastObjects; | 1497 #convertGlobalObjectsToFastObjects; |
| 1499 #debugFastObjects; | 1498 #debugFastObjects; |
| 1500 | 1499 |
| 1501 #init; | 1500 #init; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 return !!$deferredInitializers[hunkHash]; | 1835 return !!$deferredInitializers[hunkHash]; |
| 1837 }; | 1836 }; |
| 1838 #deferredInitialized = new Object(null); | 1837 #deferredInitialized = new Object(null); |
| 1839 // Function for checking if a hunk is initialized given its hash. | 1838 // Function for checking if a hunk is initialized given its hash. |
| 1840 #isHunkInitialized = function(hunkHash) { | 1839 #isHunkInitialized = function(hunkHash) { |
| 1841 return #deferredInitialized[hunkHash]; | 1840 return #deferredInitialized[hunkHash]; |
| 1842 }; | 1841 }; |
| 1843 // Function for initializing a loaded hunk, given its hash. | 1842 // Function for initializing a loaded hunk, given its hash. |
| 1844 #initializeLoadedHunk = function(hunkHash) { | 1843 #initializeLoadedHunk = function(hunkHash) { |
| 1845 $deferredInitializers[hunkHash]( | 1844 $deferredInitializers[hunkHash]( |
| 1846 #globalsHolder, ${namer.currentIsolate}); | 1845 #globalsHolder, ${namer.staticStateHolder}); |
| 1847 #deferredInitialized[hunkHash] = true; | 1846 #deferredInitialized[hunkHash] = true; |
| 1848 }; | 1847 }; |
| 1849 } | 1848 } |
| 1850 ''', {"globalsHolder": globalsHolder, | 1849 ''', {"globalsHolder": globalsHolder, |
| 1851 "isHunkLoaded": generateEmbeddedGlobalAccess( | 1850 "isHunkLoaded": generateEmbeddedGlobalAccess( |
| 1852 embeddedNames.IS_HUNK_LOADED), | 1851 embeddedNames.IS_HUNK_LOADED), |
| 1853 "isHunkInitialized": generateEmbeddedGlobalAccess( | 1852 "isHunkInitialized": generateEmbeddedGlobalAccess( |
| 1854 embeddedNames.IS_HUNK_INITIALIZED), | 1853 embeddedNames.IS_HUNK_INITIALIZED), |
| 1855 "initializeLoadedHunk": generateEmbeddedGlobalAccess( | 1854 "initializeLoadedHunk": generateEmbeddedGlobalAccess( |
| 1856 embeddedNames.INITIALIZE_LOADED_HUNK), | 1855 embeddedNames.INITIALIZE_LOADED_HUNK), |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1945 body.add(buildCspPrecompiledFunctionFor(outputUnit)); | 1944 body.add(buildCspPrecompiledFunctionFor(outputUnit)); |
| 1946 } | 1945 } |
| 1947 body.add( | 1946 body.add( |
| 1948 js.statement('$setupProgramName(dart, ${typesAccess}.length);')); | 1947 js.statement('$setupProgramName(dart, ${typesAccess}.length);')); |
| 1949 } | 1948 } |
| 1950 | 1949 |
| 1951 body..add(buildMetadata(program, outputUnit)) | 1950 body..add(buildMetadata(program, outputUnit)) |
| 1952 ..add(js.statement('${typesAccess}.push.apply(${typesAccess}, ' | 1951 ..add(js.statement('${typesAccess}.push.apply(${typesAccess}, ' |
| 1953 '${namer.deferredTypesName});')); | 1952 '${namer.deferredTypesName});')); |
| 1954 | 1953 |
| 1955 // Set the currentIsolate variable to the current isolate (which is | 1954 // Sets the static state variable to the state of the current isolate |
| 1956 // provided as second argument). | 1955 // (which is provided as second argument). |
| 1957 body.add(js.statement("${namer.currentIsolate} = arguments[1];")); | 1956 body.add(js.statement("${namer.staticStateHolder} = arguments[1];")); |
| 1958 | 1957 |
| 1959 body.add(buildCompileTimeConstants(fragment.constants, | 1958 body.add(buildCompileTimeConstants(fragment.constants, |
| 1960 isMainFragment: false)); | 1959 isMainFragment: false)); |
| 1961 body.add(buildStaticNonFinalFieldInitializations(outputUnit)); | 1960 body.add(buildStaticNonFinalFieldInitializations(outputUnit)); |
| 1962 | 1961 |
| 1963 List<jsAst.Statement> statements = <jsAst.Statement>[]; | 1962 List<jsAst.Statement> statements = <jsAst.Statement>[]; |
| 1964 | 1963 |
| 1965 statements | 1964 statements |
| 1966 ..add(buildGeneratedBy()) | 1965 ..add(buildGeneratedBy()) |
| 1967 ..add(js.statement('${deferredInitializers}.current = ' | 1966 ..add(js.statement('${deferredInitializers}.current = ' |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2092 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2094 if (element.isInstanceMember) { | 2093 if (element.isInstanceMember) { |
| 2095 cachedClassBuilders.remove(element.enclosingClass); | 2094 cachedClassBuilders.remove(element.enclosingClass); |
| 2096 | 2095 |
| 2097 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2096 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2098 | 2097 |
| 2099 } | 2098 } |
| 2100 } | 2099 } |
| 2101 } | 2100 } |
| 2102 } | 2101 } |
| OLD | NEW |