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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 22488002: Tightening up dart2js load timing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
« no previous file with comments | « samples/third_party/dromaeo/generate_dart2js_tests.py ('k') | tools/testing/dart/browser_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
index 2302aec5576d8b4dd92cbe738a3cf234332b6724..b98d5a25fa27ddcfc6b4db8856d68b567026a8ec 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
@@ -857,11 +857,7 @@ class CodeEmitterTask extends CompilerTask {
return js.fun('oldIsolate', [
js('var isolateProperties = oldIsolate.${namer.isolatePropertiesName}'),
- js(r'isolateProperties.$currentScript ='
- 'typeof document == "object" ?'
- '(document.currentScript ||'
- 'document.scripts[document.scripts.length - 1]) :'
- 'null'),
+ js(r'isolateProperties.$currentScript = null'),
js('var isolatePrototype = oldIsolate.prototype'),
js('var str = "{\\n"'),
@@ -2942,23 +2938,42 @@ class CodeEmitterTask extends CompilerTask {
}
addComment('BEGIN invoke [main].', buffer);
buffer.write("""
-if (typeof document !== "undefined" && document.readyState !== "complete") {
- document.addEventListener("readystatechange", function () {
- if (document.readyState == "complete") {
- if (typeof dartMainRunner === "function") {
- dartMainRunner(function() { ${mainCall}; });
- } else {
- ${mainCall};
- }
+(function (callback) {
+ if (!self.document) {
ahe 2013/08/07 16:24:47 Just a quick note, sorry. This will break dart2js
blois 2013/08/07 17:39:50 Ah, thanks!
+ callback(null);
+ return;
+ }
+ if (document.currentScript) {
+ callback(document.currentScript);
+ return;
+ }
+
+ var scripts = document.scripts;
+ function onLoad() {
+ for (var i = 0; i < scripts.length; ++i) {
+ scripts[i].removeEventListener('load', onLoad, false);
vsm 2013/08/07 16:10:12 Can you add a comment here to explain what's going
blois 2013/08/07 17:39:50 Done.
}
- }, false);
-} else {
+ callback(event.target);
+ }
+ for (var i = 0; i < scripts.length; ++i) {
+ scripts[i].addEventListener('load', onLoad, false);
+ }
+})(function(currentScript) {
+ Isolate.\$isolateProperties.\$currentScript = currentScript;
+
+ if (self.console && self.document && document.readyState == "loading") {
+ // Bug dartbug.com/12281 this warning is to let users know how to match
+ // Dartium execution timing.
+ console.warn("Dart script executed synchronously, use <script src='" +
+ currentScript.src + "' defer></scr" + "ipt> to execute after parsing " +
+ "has completed.");
+ }
if (typeof dartMainRunner === "function") {
dartMainRunner(function() { ${mainCall}; });
} else {
${mainCall};
}
-}
+});
""");
addComment('END invoke [main].', buffer);
}
« no previous file with comments | « samples/third_party/dromaeo/generate_dart2js_tests.py ('k') | tools/testing/dart/browser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698