Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart

Issue 1022103002: Do not include names of lazy globals in minified mode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebased Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 533
534 jsAst.Expression buildLazilyInitializedStaticField( 534 jsAst.Expression buildLazilyInitializedStaticField(
535 VariableElement element, {String isolateProperties}) { 535 VariableElement element, {String isolateProperties}) {
536 jsAst.Expression code = backend.generatedCode[element]; 536 jsAst.Expression code = backend.generatedCode[element];
537 // The code is null if we ended up not needing the lazily 537 // The code is null if we ended up not needing the lazily
538 // initialized field after all because of constant folding 538 // initialized field after all because of constant folding
539 // before code generation. 539 // before code generation.
540 if (code == null) return null; 540 if (code == null) return null;
541 // The code only computes the initial value. We build the lazy-check 541 // The code only computes the initial value. We build the lazy-check
542 // here: 542 // here:
543 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); 543 // lazyInitializer(fieldName, getterName, initial, name, prototype);
544 // The name is used for error reporting. The 'initial' must be a 544 // The name is used for error reporting. The 'initial' must be a
545 // closure that constructs the initial value. 545 // closure that constructs the initial value.
546 if (isolateProperties != null) { 546 if (isolateProperties != null) {
547 // This is currently only used in incremental compilation to patch
548 // in new lazy values.
547 return js('#(#,#,#,#,#)', 549 return js('#(#,#,#,#,#)',
548 [js(lazyInitializerName), 550 [js(lazyInitializerName),
549 js.string(element.name),
550 js.string(namer.globalPropertyName(element)), 551 js.string(namer.globalPropertyName(element)),
551 js.string(namer.lazyInitializerName(element)), 552 js.string(namer.lazyInitializerName(element)),
552 code, 553 code,
554 js.string(element.name),
553 isolateProperties]); 555 isolateProperties]);
554 } 556 }
555 557
556 return js('#(#,#,#,#)', 558 if (compiler.enableMinification) {
557 [js(lazyInitializerName), 559 return js('#(#,#,#)',
558 js.string(element.name), 560 [js(lazyInitializerName),
559 js.string(namer.globalPropertyName(element)), 561 js.string(namer.globalPropertyName(element)),
560 js.string(namer.lazyInitializerName(element)), 562 js.string(namer.lazyInitializerName(element)),
561 code]); 563 code]);
564 } else {
565 return js('#(#,#,#,#)',
566 [js(lazyInitializerName),
567 js.string(namer.globalPropertyName(element)),
568 js.string(namer.lazyInitializerName(element)),
569 code,
570 js.string(element.name)]);
571 }
562 } 572 }
563 573
564 void emitMetadata(Program program, CodeOutput output) { 574 void emitMetadata(Program program, CodeOutput output) {
565 575
566 addMetadataGlobal(List<String> list, String global) { 576 addMetadataGlobal(List<String> list, String global) {
567 String globalAccess = generateEmbeddedGlobalAccessString(global); 577 String globalAccess = generateEmbeddedGlobalAccessString(global);
568 output.add('$globalAccess$_=$_['); 578 output.add('$globalAccess$_=$_[');
569 for (String data in list) { 579 for (String data in list) {
570 if (data is String) { 580 if (data is String) {
571 if (data != 'null') { 581 if (data != 'null') {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 jsAst.FunctionDeclaration decl = js.statement(''' 703 jsAst.FunctionDeclaration decl = js.statement('''
694 function init() { 704 function init() {
695 $isolateProperties = Object.create(null); 705 $isolateProperties = Object.create(null);
696 #allClasses = Object.create(null); 706 #allClasses = Object.create(null);
697 #getTypeFromName = function(name) {return #allClasses[name];}; 707 #getTypeFromName = function(name) {return #allClasses[name];};
698 #interceptorsByTag = Object.create(null); 708 #interceptorsByTag = Object.create(null);
699 #leafTags = Object.create(null); 709 #leafTags = Object.create(null);
700 #finishedClasses = Object.create(null); 710 #finishedClasses = Object.create(null);
701 711
702 if (#needsLazyInitializer) { 712 if (#needsLazyInitializer) {
703 $lazyInitializerName = function (staticName, fieldName, getterName, 713 // [staticName] is only provided in non-minified mode. If missing, we
704 lazyValue, prototype) { 714 // fall back to [fieldName]. Likewise, [prototype] is optional and
715 // defaults to the isolateProperties object.
716 $lazyInitializerName = function (fieldName, getterName, lazyValue,
717 staticName, prototype) {
705 if (!#lazies) #lazies = Object.create(null); 718 if (!#lazies) #lazies = Object.create(null);
706 #lazies[fieldName] = getterName; 719 #lazies[fieldName] = getterName;
707 720
708 // 'prototype' will be undefined except if we are doing an update 721 // 'prototype' will be undefined except if we are doing an update
709 // during incremental compilation. In this case we put the lazy 722 // during incremental compilation. In this case we put the lazy
710 // field directly on the isolate instead of the isolateProperties. 723 // field directly on the isolate instead of the isolateProperties.
711 prototype = prototype || $isolateProperties; 724 prototype = prototype || $isolateProperties;
712 var sentinelUndefined = {}; 725 var sentinelUndefined = {};
713 var sentinelInProgress = {}; 726 var sentinelInProgress = {};
714 prototype[fieldName] = sentinelUndefined; 727 prototype[fieldName] = sentinelUndefined;
715 728
716 prototype[getterName] = function () { 729 prototype[getterName] = function () {
717 var result = this[fieldName]; 730 var result = this[fieldName];
718 try { 731 try {
719 if (result === sentinelUndefined) { 732 if (result === sentinelUndefined) {
720 this[fieldName] = sentinelInProgress; 733 this[fieldName] = sentinelInProgress;
721 734
722 try { 735 try {
723 result = this[fieldName] = lazyValue(); 736 result = this[fieldName] = lazyValue();
724 } finally { 737 } finally {
725 // Use try-finally, not try-catch/throw as it destroys the 738 // Use try-finally, not try-catch/throw as it destroys the
726 // stack trace. 739 // stack trace.
727 if (result === sentinelUndefined) 740 if (result === sentinelUndefined)
728 this[fieldName] = null; 741 this[fieldName] = null;
729 } 742 }
730 } else { 743 } else {
731 if (result === sentinelInProgress) 744 if (result === sentinelInProgress)
732 #cyclicThrow(staticName); 745 // In minified mode, static name might not have been
746 // provided, so fall back to the minified fieldName.
747 #cyclicThrow(staticName || fieldName);
733 } 748 }
734 749
735 return result; 750 return result;
736 } finally { 751 } finally {
737 this[getterName] = function() { return this[fieldName]; }; 752 this[getterName] = function() { return this[fieldName]; };
738 } 753 }
739 } 754 }
740 } 755 }
741 } 756 }
742 757
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 1823 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
1809 if (element.isInstanceMember) { 1824 if (element.isInstanceMember) {
1810 cachedClassBuilders.remove(element.enclosingClass); 1825 cachedClassBuilders.remove(element.enclosingClass);
1811 1826
1812 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 1827 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
1813 1828
1814 } 1829 }
1815 } 1830 }
1816 } 1831 }
1817 } 1832 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698