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 7c07ce10eb507bdd475166689632ead7479b03a7..caf74942cbba22da858d4009ba26be24867e062e 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"'), |
@@ -2959,24 +2955,48 @@ class CodeEmitterTask extends CompilerTask { |
buffer.write(N); |
} |
addComment('BEGIN invoke [main].', buffer); |
+ // This code finds the currently executing script by listening to the |
+ // onload event of all script tags and getting the first script which |
+ // finishes. Since onload is called immediately after execution this should |
+ // not substantially change execution order. |
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 (typeof document === 'undefined') { |
+ 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); |
} |
- }, 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; |
ahe
2013/08/12 15:58:39
Did you test this in minified mode? I think it nee
blois
2013/08/12 17:00:07
Fixed, thanks!
|
+ |
+ if (typeof console !== 'undefined' && typeof document !== 'undefined' && |
+ document.readyState == "loading") { |
+ // Bug dartbug.com/12281 this warning is to let users know how to match |
ahe
2013/08/12 15:58:39
I think you can avoid including this comment in th
blois
2013/08/12 17:00:07
I wanted this comment in the file for the near ter
ahe
2013/08/12 17:08:01
If you want devs to read this message, shouldn't i
blois
2013/08/12 17:43:46
Fixed. I was figuring that the code comment was su
|
+ // Dartium execution timing. |
+ console.warn("Dart script executed synchronously, use <script src='" + |
ahe
2013/08/12 15:58:39
Does this work on IE? I have heard that the consol
blois
2013/08/12 17:00:07
Console isn't defined on FF in this case either- t
ahe
2013/08/12 17:08:01
Doh!
|
+ 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); |
} |