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

Side by Side Diff: lib/compiler/implementation/emitter.dart

Issue 9877008: Move the DOMContentLoaded logic into the generated JavaScript (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
« frog/gen.dart ('K') | « frog/minfrog ('k') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * A function element that represents a closure call. The signature is copied 6 * A function element that represents a closure call. The signature is copied
7 * from the given element. 7 * from the given element.
8 */ 8 */
9 class ClosureInvocationElement extends FunctionElement { 9 class ClosureInvocationElement extends FunctionElement {
10 ClosureInvocationElement(SourceString name, 10 ClosureInvocationElement(SourceString name,
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 Selector.SETTER); 655 Selector.SETTER);
656 } 656 }
657 } else { 657 } else {
658 String jsName = namer.setterName(null, setterName); 658 String jsName = namer.setterName(null, setterName);
659 generateMethod('set ${setterName.slowToString()}', jsName, 659 generateMethod('set ${setterName.slowToString()}', jsName,
660 Selector.SETTER); 660 Selector.SETTER);
661 } 661 }
662 }); 662 });
663 } 663 }
664 664
665 String buildIsolateSetup(Element appMain, Element isolateMain) { 665 String buildIsolateSetup(StringBuffer buffer,
666 Element appMain,
667 Element isolateMain) {
666 String mainAccess = "${namer.isolateAccess(appMain)}"; 668 String mainAccess = "${namer.isolateAccess(appMain)}";
667 String currentIsolate = "${namer.CURRENT_ISOLATE}"; 669 String currentIsolate = "${namer.CURRENT_ISOLATE}";
668 String mainEnsureGetter = ''; 670 String mainEnsureGetter = '';
669 // Since we pass the closurized version of the main method to 671 // Since we pass the closurized version of the main method to
670 // the isolate method, we must make sure that it exists. 672 // the isolate method, we must make sure that it exists.
671 if (!compiler.universe.staticFunctionsNeedingGetter.contains(appMain)) { 673 if (!compiler.universe.staticFunctionsNeedingGetter.contains(appMain)) {
672 String invocationName = 674 String invocationName =
673 "${namer.closureInvocationName(Selector.INVOCATION_0)}"; 675 "${namer.closureInvocationName(Selector.INVOCATION_0)}";
674 mainEnsureGetter = "$mainAccess.$invocationName = $mainAccess"; 676 mainEnsureGetter = "$mainAccess.$invocationName = $mainAccess";
675 } 677 }
676 678
677 // TODO(ngeoffray): These globals are currently required by the isolate 679 // TODO(ngeoffray): These globals are currently required by the isolate
678 // library, but since leg already generates code on an Isolate object, they 680 // library, but since leg already generates code on an Isolate object, they
679 // are not really needed. We should remove them once Leg replaces Frog. 681 // are not really needed. We should remove them once Leg replaces Frog.
680 return """ 682 buffer.add("""
681 var \$globalThis = $currentIsolate; 683 var \$globalThis = $currentIsolate;
682 var \$globalState; 684 var \$globalState;
683 var \$globals; 685 var \$globals;
684 function \$static_init(){}; 686 function \$static_init(){};
685 687
686 function \$initGlobals(context) { 688 function \$initGlobals(context) {
687 context.isolateStatics = new ${namer.ISOLATE}(); 689 context.isolateStatics = new ${namer.ISOLATE}();
688 } 690 }
689 function \$setGlobals(context) { 691 function \$setGlobals(context) {
690 $currentIsolate = context.isolateStatics; 692 $currentIsolate = context.isolateStatics;
691 \$globalThis = $currentIsolate; 693 \$globalThis = $currentIsolate;
692 } 694 }
693 $mainEnsureGetter 695 $mainEnsureGetter
694 ${namer.isolateAccess(isolateMain)}($mainAccess);"""; 696 """);
697 return "${namer.isolateAccess(isolateMain)}($mainAccess)";
695 } 698 }
696 699
697 emitMain(StringBuffer buffer) { 700 emitMain(StringBuffer buffer) {
698 if (compiler.isMockCompilation) return; 701 if (compiler.isMockCompilation) return;
699 Element main = compiler.mainApp.find(Compiler.MAIN); 702 Element main = compiler.mainApp.find(Compiler.MAIN);
703 String mainCall = null;
700 if (compiler.isolateLibrary != null) { 704 if (compiler.isolateLibrary != null) {
701 Element isolateMain = 705 Element isolateMain =
702 compiler.isolateLibrary.find(Compiler.START_ROOT_ISOLATE); 706 compiler.isolateLibrary.find(Compiler.START_ROOT_ISOLATE);
703 buffer.add(buildIsolateSetup(main, isolateMain)); 707 mainCall = buildIsolateSetup(buffer, main, isolateMain);
704 } else { 708 } else {
705 buffer.add('${namer.isolateAccess(main)}();\n'); 709 mainCall = '${namer.isolateAccess(main)}()';
706 } 710 }
711 buffer.add("""
712 if (typeof window != 'undefined' && window.addEventListener) {
713 window.addEventListener('DOMContentLoaded', function(e) {
714 ${mainCall};
715 });
716 } else {
717 ${mainCall};
718 }
719 """);
707 } 720 }
708 721
709 String assembleProgram() { 722 String assembleProgram() {
710 measure(() { 723 measure(() {
711 mainBuffer.add('function ${namer.ISOLATE}() {'); 724 mainBuffer.add('function ${namer.ISOLATE}() {');
712 emitStaticNonFinalFieldInitializations(mainBuffer); 725 emitStaticNonFinalFieldInitializations(mainBuffer);
713 mainBuffer.add('}\n\n'); 726 mainBuffer.add('}\n\n');
714 emitClasses(mainBuffer); 727 emitClasses(mainBuffer);
715 emitStaticFunctions(mainBuffer); 728 emitStaticFunctions(mainBuffer);
716 emitStaticFunctionGetters(mainBuffer); 729 emitStaticFunctionGetters(mainBuffer);
717 emitCompileTimeConstants(mainBuffer); 730 emitCompileTimeConstants(mainBuffer);
718 emitStaticFinalFieldInitializations(mainBuffer); 731 emitStaticFinalFieldInitializations(mainBuffer);
719 nativeEmitter.emitDynamicDispatchMetadata(); 732 nativeEmitter.emitDynamicDispatchMetadata();
720 mainBuffer.add( 733 mainBuffer.add(
721 'var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); 734 'var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n');
722 nativeEmitter.assembleCode(mainBuffer); 735 nativeEmitter.assembleCode(mainBuffer);
723 emitMain(mainBuffer); 736 emitMain(mainBuffer);
724 compiler.assembledCode = mainBuffer.toString(); 737 compiler.assembledCode = mainBuffer.toString();
725 }); 738 });
726 return compiler.assembledCode; 739 return compiler.assembledCode;
727 } 740 }
728 } 741 }
OLDNEW
« frog/gen.dart ('K') | « frog/minfrog ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698