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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
« frog/gen.dart ('K') | « frog/minfrog ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/emitter.dart
===================================================================
--- lib/compiler/implementation/emitter.dart (revision 5935)
+++ lib/compiler/implementation/emitter.dart (working copy)
@@ -662,7 +662,9 @@
});
}
- String buildIsolateSetup(Element appMain, Element isolateMain) {
+ String buildIsolateSetup(StringBuffer buffer,
+ Element appMain,
+ Element isolateMain) {
String mainAccess = "${namer.isolateAccess(appMain)}";
String currentIsolate = "${namer.CURRENT_ISOLATE}";
String mainEnsureGetter = '';
@@ -677,7 +679,7 @@
// TODO(ngeoffray): These globals are currently required by the isolate
// library, but since leg already generates code on an Isolate object, they
// are not really needed. We should remove them once Leg replaces Frog.
- return """
+ buffer.add("""
var \$globalThis = $currentIsolate;
var \$globalState;
var \$globals;
@@ -691,19 +693,30 @@
\$globalThis = $currentIsolate;
}
$mainEnsureGetter
-${namer.isolateAccess(isolateMain)}($mainAccess);""";
+""");
+ return "${namer.isolateAccess(isolateMain)}($mainAccess)";
}
emitMain(StringBuffer buffer) {
if (compiler.isMockCompilation) return;
Element main = compiler.mainApp.find(Compiler.MAIN);
+ String mainCall = null;
if (compiler.isolateLibrary != null) {
Element isolateMain =
compiler.isolateLibrary.find(Compiler.START_ROOT_ISOLATE);
- buffer.add(buildIsolateSetup(main, isolateMain));
+ mainCall = buildIsolateSetup(buffer, main, isolateMain);
} else {
- buffer.add('${namer.isolateAccess(main)}();\n');
+ mainCall = '${namer.isolateAccess(main)}()';
}
+ buffer.add("""
+if (typeof window != 'undefined' && window.addEventListener) {
+ window.addEventListener('DOMContentLoaded', function(e) {
+ ${mainCall};
+ });
+} else {
+ ${mainCall};
+}
+""");
}
String assembleProgram() {
« frog/gen.dart ('K') | « frog/minfrog ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698