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:collection' show HashMap; | 7 import 'dart:collection' show HashMap; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 /// True if [ContainerBuilder.addMemberMethodFromInfo] used "structured info", | 117 /// True if [ContainerBuilder.addMemberMethodFromInfo] used "structured info", |
118 /// that is, some function was needed for reflection, had stubs, or had a | 118 /// that is, some function was needed for reflection, had stubs, or had a |
119 /// super alias. | 119 /// super alias. |
120 bool needsStructuredMemberInfo = false; | 120 bool needsStructuredMemberInfo = false; |
121 | 121 |
122 final Namer namer; | 122 final Namer namer; |
123 ConstantEmitter constantEmitter; | 123 ConstantEmitter constantEmitter; |
124 NativeEmitter get nativeEmitter => task.nativeEmitter; | 124 NativeEmitter get nativeEmitter => task.nativeEmitter; |
125 TypeTestRegistry get typeTestRegistry => task.typeTestRegistry; | 125 TypeTestRegistry get typeTestRegistry => task.typeTestRegistry; |
126 CommonElements get commonElements => compiler.commonElements; | 126 CommonElements get commonElements => _closedWorld.commonElements; |
127 ElementEnvironment get _elementEnvironment => compiler.elementEnvironment; | 127 ElementEnvironment get _elementEnvironment => compiler.elementEnvironment; |
128 | 128 |
129 // The full code that is written to each hunk part-file. | 129 // The full code that is written to each hunk part-file. |
130 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>(); | 130 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>(); |
131 | 131 |
132 String classesCollector; | 132 String classesCollector; |
133 final Map<jsAst.Name, String> mangledFieldNames = | 133 final Map<jsAst.Name, String> mangledFieldNames = |
134 new HashMap<jsAst.Name, String>(); | 134 new HashMap<jsAst.Name, String>(); |
135 final Map<jsAst.Name, String> mangledGlobalFieldNames = | 135 final Map<jsAst.Name, String> mangledGlobalFieldNames = |
136 new HashMap<jsAst.Name, String>(); | 136 new HashMap<jsAst.Name, String>(); |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 generateEmbeddedGlobalAccess(embeddedNames.ALL_CLASSES); | 802 generateEmbeddedGlobalAccess(embeddedNames.ALL_CLASSES); |
803 jsAst.Expression getTypeFromNameAccess = | 803 jsAst.Expression getTypeFromNameAccess = |
804 generateEmbeddedGlobalAccess(embeddedNames.GET_TYPE_FROM_NAME); | 804 generateEmbeddedGlobalAccess(embeddedNames.GET_TYPE_FROM_NAME); |
805 jsAst.Expression interceptorsByTagAccess = | 805 jsAst.Expression interceptorsByTagAccess = |
806 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); | 806 generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTORS_BY_TAG); |
807 jsAst.Expression leafTagsAccess = | 807 jsAst.Expression leafTagsAccess = |
808 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); | 808 generateEmbeddedGlobalAccess(embeddedNames.LEAF_TAGS); |
809 jsAst.Expression finishedClassesAccess = | 809 jsAst.Expression finishedClassesAccess = |
810 generateEmbeddedGlobalAccess(embeddedNames.FINISHED_CLASSES); | 810 generateEmbeddedGlobalAccess(embeddedNames.FINISHED_CLASSES); |
811 jsAst.Expression cyclicThrow = | 811 jsAst.Expression cyclicThrow = |
812 staticFunctionAccess(compiler.commonElements.cyclicThrowHelper); | 812 staticFunctionAccess(commonElements.cyclicThrowHelper); |
813 jsAst.Expression laziesAccess = | 813 jsAst.Expression laziesAccess = |
814 generateEmbeddedGlobalAccess(embeddedNames.LAZIES); | 814 generateEmbeddedGlobalAccess(embeddedNames.LAZIES); |
815 | 815 |
816 return js.statement( | 816 return js.statement( |
817 ''' | 817 ''' |
818 function init() { | 818 function init() { |
819 $isolatePropertiesName = Object.create(null); | 819 $isolatePropertiesName = Object.create(null); |
820 #allClasses = map(); | 820 #allClasses = map(); |
821 #getTypeFromName = function(name) {return #allClasses[name];}; | 821 #getTypeFromName = function(name) {return #allClasses[name];}; |
822 #interceptorsByTag = map(); | 822 #interceptorsByTag = map(); |
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1898 output.close(); | 1898 output.close(); |
1899 } | 1899 } |
1900 | 1900 |
1901 hunkHashes[outputUnit] = hash; | 1901 hunkHashes[outputUnit] = hash; |
1902 } | 1902 } |
1903 return hunkHashes; | 1903 return hunkHashes; |
1904 } | 1904 } |
1905 | 1905 |
1906 jsAst.Comment buildGeneratedBy() { | 1906 jsAst.Comment buildGeneratedBy() { |
1907 List<String> options = []; | 1907 List<String> options = []; |
1908 if (compiler.commonElements.mirrorsLibrary != null && | 1908 if (commonElements.mirrorsLibrary != null && |
1909 !compiler.options.loadFromDill) { | 1909 !compiler.options.loadFromDill) { |
1910 // TODO(johnniwinther): Add `isMirrorsUsed` to [BackendData] instead | 1910 // TODO(johnniwinther): Add `isMirrorsUsed` to [BackendData] instead |
1911 // of checking `mirrorsLibrary`. | 1911 // of checking `mirrorsLibrary`. |
1912 options.add('mirrors'); | 1912 options.add('mirrors'); |
1913 } | 1913 } |
1914 if (compiler.options.useContentSecurityPolicy) options.add("CSP"); | 1914 if (compiler.options.useContentSecurityPolicy) options.add("CSP"); |
1915 return new jsAst.Comment(generatedBy(compiler, flavor: options.join(", "))); | 1915 return new jsAst.Comment(generatedBy(compiler, flavor: options.join(", "))); |
1916 } | 1916 } |
1917 | 1917 |
1918 void outputDeferredMap() { | 1918 void outputDeferredMap() { |
1919 Map<String, dynamic> mapping = new Map<String, dynamic>(); | 1919 Map<String, dynamic> mapping = new Map<String, dynamic>(); |
1920 // Json does not support comments, so we embed the explanation in the | 1920 // Json does not support comments, so we embed the explanation in the |
1921 // data. | 1921 // data. |
1922 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 1922 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
1923 "needed for a given deferred library import."; | 1923 "needed for a given deferred library import."; |
1924 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 1924 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
1925 compiler.outputProvider( | 1925 compiler.outputProvider( |
1926 compiler.options.deferredMapUri.path, '', OutputType.info) | 1926 compiler.options.deferredMapUri.path, '', OutputType.info) |
1927 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 1927 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
1928 ..close(); | 1928 ..close(); |
1929 } | 1929 } |
1930 } | 1930 } |
OLD | NEW |