| 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.program_builder; | 5 library dart2js.js_emitter.program_builder; |
| 6 | 6 |
| 7 import '../js_emitter.dart' show | 7 import '../js_emitter.dart' show |
| 8 ClassStubGenerator, | 8 ClassStubGenerator, |
| 9 CodeEmitterTask, | 9 CodeEmitterTask, |
| 10 computeMixinClass, | 10 computeMixinClass, |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 // building a static field. (Note that the static-state holder was | 303 // building a static field. (Note that the static-state holder was |
| 304 // already registered earlier, and that we just call the register to get | 304 // already registered earlier, and that we just call the register to get |
| 305 // the holder-instance. | 305 // the holder-instance. |
| 306 return new StaticField(element, | 306 return new StaticField(element, |
| 307 name, _registerStaticStateHolder(), code, | 307 name, _registerStaticStateHolder(), code, |
| 308 isFinal, isLazy); | 308 isFinal, isLazy); |
| 309 } | 309 } |
| 310 | 310 |
| 311 List<StaticField> _buildStaticLazilyInitializedFields( | 311 List<StaticField> _buildStaticLazilyInitializedFields( |
| 312 LibrariesMap librariesMap) { | 312 LibrariesMap librariesMap) { |
| 313 // TODO(floitsch): lazy fields should just be in their respective | |
| 314 // libraries. | |
| 315 if (librariesMap != _registry.mainLibrariesMap) { | |
| 316 return const <StaticField>[]; | |
| 317 } | |
| 318 | |
| 319 JavaScriptConstantCompiler handler = backend.constants; | 313 JavaScriptConstantCompiler handler = backend.constants; |
| 320 List<VariableElement> lazyFields = | 314 DeferredLoadTask loadTask = _compiler.deferredLoadTask; |
| 321 handler.getLazilyInitializedFieldsForEmission(); | 315 List<VariableElement> lazyFields = handler |
| 316 .getLazilyInitializedFieldsForEmission() |
| 317 .where((element) => |
| 318 loadTask.outputUnitForElement(element) == librariesMap.outputUnit); |
| 322 return Elements.sortedByPosition(lazyFields) | 319 return Elements.sortedByPosition(lazyFields) |
| 323 .map(_buildLazyField) | 320 .map(_buildLazyField) |
| 324 .where((field) => field != null) // Happens when the field was unused. | 321 .where((field) => field != null) // Happens when the field was unused. |
| 325 .toList(growable: false); | 322 .toList(growable: false); |
| 326 } | 323 } |
| 327 | 324 |
| 328 StaticField _buildLazyField(Element element) { | 325 StaticField _buildLazyField(Element element) { |
| 329 js.Expression code = backend.generatedCode[element]; | 326 js.Expression code = backend.generatedCode[element]; |
| 330 // The code is null if we ended up not needing the lazily | 327 // The code is null if we ended up not needing the lazily |
| 331 // initialized field after all because of constant folding | 328 // initialized field after all because of constant folding |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 Constant constant = new Constant(name, holder, constantValue); | 1011 Constant constant = new Constant(name, holder, constantValue); |
| 1015 _constants[constantValue] = constant; | 1012 _constants[constantValue] = constant; |
| 1016 } | 1013 } |
| 1017 } | 1014 } |
| 1018 | 1015 |
| 1019 Holder _registerStaticStateHolder() { | 1016 Holder _registerStaticStateHolder() { |
| 1020 return _registry.registerHolder( | 1017 return _registry.registerHolder( |
| 1021 namer.staticStateHolder, isStaticStateHolder: true); | 1018 namer.staticStateHolder, isStaticStateHolder: true); |
| 1022 } | 1019 } |
| 1023 } | 1020 } |
| OLD | NEW |