| 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 569 |
| 570 jsAst.Statement buildLazilyInitializedStaticFields() { | 570 jsAst.Statement buildLazilyInitializedStaticFields() { |
| 571 JavaScriptConstantCompiler handler = backend.constants; | 571 JavaScriptConstantCompiler handler = backend.constants; |
| 572 List<VariableElement> lazyFields = | 572 List<VariableElement> lazyFields = |
| 573 handler.getLazilyInitializedFieldsForEmission(); | 573 handler.getLazilyInitializedFieldsForEmission(); |
| 574 if (lazyFields.isNotEmpty) { | 574 if (lazyFields.isNotEmpty) { |
| 575 needsLazyInitializer = true; | 575 needsLazyInitializer = true; |
| 576 List<jsAst.Expression> laziesInfo = buildLaziesInfo(lazyFields); | 576 List<jsAst.Expression> laziesInfo = buildLaziesInfo(lazyFields); |
| 577 return js.statement(''' | 577 return js.statement(''' |
| 578 (function(lazies) { | 578 (function(lazies) { |
| 579 if (#notInMinifiedMode) { | 579 for (var i = 0; i < lazies.length; ) { |
| 580 var descriptorLength = 4; | 580 var fieldName = lazies[i++]; |
| 581 } else { | 581 var getterName = lazies[i++]; |
| 582 var descriptorLength = 3; | 582 if (#notMinified) { |
| 583 } | 583 var staticName = lazies[i++]; |
| 584 | |
| 585 for (var i = 0; i < lazies.length; i += descriptorLength) { | |
| 586 var fieldName = lazies [i]; | |
| 587 var getterName = lazies[i + 1]; | |
| 588 var lazyValue = lazies[i + 2]; | |
| 589 if (#notInMinifiedMode) { | |
| 590 var staticName = lazies[i + 3]; | |
| 591 } | 584 } |
| 585 var lazyValue = lazies[i++]; |
| 592 | 586 |
| 593 // We build the lazy-check here: | 587 // We build the lazy-check here: |
| 594 // lazyInitializer(fieldName, getterName, lazyValue, staticName); | 588 // lazyInitializer(fieldName, getterName, lazyValue, staticName); |
| 595 // 'staticName' is used for error reporting in non-minified mode. | 589 // 'staticName' is used for error reporting in non-minified mode. |
| 596 // 'lazyValue' must be a closure that constructs the initial value. | 590 // 'lazyValue' must be a closure that constructs the initial value. |
| 597 if (#notInMinifiedMode) { | 591 if (#notMinified) { |
| 598 #lazy(fieldName, getterName, lazyValue, staticName); | 592 #lazy(fieldName, getterName, lazyValue, staticName); |
| 599 } else { | 593 } else { |
| 600 #lazy(fieldName, getterName, lazyValue); | 594 #lazy(fieldName, getterName, lazyValue); |
| 601 } | 595 } |
| 602 } | 596 } |
| 603 })(#laziesInfo) | 597 })(#laziesInfo) |
| 604 ''', {'notInMinifiedMode': !compiler.enableMinification, | 598 ''', {'notMinified': !compiler.enableMinification, |
| 605 'laziesInfo': new jsAst.ArrayInitializer(laziesInfo), | 599 'laziesInfo': new jsAst.ArrayInitializer(laziesInfo), |
| 606 'lazy': js(lazyInitializerName)}); | 600 'lazy': js(lazyInitializerName)}); |
| 607 } else { | 601 } else { |
| 608 return js.comment("No lazy statics."); | 602 return js.comment("No lazy statics."); |
| 609 } | 603 } |
| 610 } | 604 } |
| 611 | 605 |
| 612 List<jsAst.Expression> buildLaziesInfo(List<VariableElement> lazies) { | 606 List<jsAst.Expression> buildLaziesInfo(List<VariableElement> lazies) { |
| 613 List<jsAst.Expression> laziesInfo = <jsAst.Expression>[]; | 607 List<jsAst.Expression> laziesInfo = <jsAst.Expression>[]; |
| 614 for (VariableElement element in Elements.sortedByPosition(lazies)) { | 608 for (VariableElement element in Elements.sortedByPosition(lazies)) { |
| 615 jsAst.Expression code = backend.generatedCode[element]; | 609 jsAst.Expression code = backend.generatedCode[element]; |
| 616 // The code is null if we ended up not needing the lazily | 610 // The code is null if we ended up not needing the lazily |
| 617 // initialized field after all because of constant folding | 611 // initialized field after all because of constant folding |
| 618 // before code generation. | 612 // before code generation. |
| 619 if (code == null) continue; | 613 if (code == null) continue; |
| 620 if (compiler.enableMinification) { | 614 laziesInfo.add(js.quoteName(namer.globalPropertyName(element))); |
| 621 laziesInfo.addAll([js.quoteName(namer.globalPropertyName(element)), | 615 laziesInfo.add(js.quoteName(namer.lazyInitializerName(element))); |
| 622 js.quoteName(namer.lazyInitializerName(element)), | 616 if (!compiler.enableMinification) { |
| 623 code]); | 617 laziesInfo.add(js.string(element.name)); |
| 624 } else { | |
| 625 laziesInfo.addAll([js.quoteName(namer.globalPropertyName(element)), | |
| 626 js.quoteName(namer.lazyInitializerName(element)), | |
| 627 code, | |
| 628 js.string(element.name)]); | |
| 629 } | 618 } |
| 619 laziesInfo.add(code); |
| 630 } | 620 } |
| 631 return laziesInfo; | 621 return laziesInfo; |
| 632 } | 622 } |
| 633 | 623 |
| 624 // TODO(sra): Remove this unused function. |
| 634 jsAst.Expression buildLazilyInitializedStaticField( | 625 jsAst.Expression buildLazilyInitializedStaticField( |
| 635 VariableElement element, {String isolateProperties}) { | 626 VariableElement element, {String isolateProperties}) { |
| 636 jsAst.Expression code = backend.generatedCode[element]; | 627 jsAst.Expression code = backend.generatedCode[element]; |
| 637 // The code is null if we ended up not needing the lazily | 628 // The code is null if we ended up not needing the lazily |
| 638 // initialized field after all because of constant folding | 629 // initialized field after all because of constant folding |
| 639 // before code generation. | 630 // before code generation. |
| 640 if (code == null) return null; | 631 if (code == null) return null; |
| 641 // The code only computes the initial value. We build the lazy-check | 632 // The code only computes the initial value. We build the lazy-check |
| 642 // here: | 633 // here: |
| 643 // lazyInitializer(fieldName, getterName, initial, name, prototype); | 634 // lazyInitializer(fieldName, getterName, initial, name, prototype); |
| (...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2006 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 1997 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2007 if (element.isInstanceMember) { | 1998 if (element.isInstanceMember) { |
| 2008 cachedClassBuilders.remove(element.enclosingClass); | 1999 cachedClassBuilders.remove(element.enclosingClass); |
| 2009 | 2000 |
| 2010 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2001 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2011 | 2002 |
| 2012 } | 2003 } |
| 2013 } | 2004 } |
| 2014 } | 2005 } |
| 2015 } | 2006 } |
| OLD | NEW |