Chromium Code Reviews| 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 5c52a80282486c2729c99232a23d9b20f13c3851..25257855e1b64acf8350de85ed1cc1285f117f1a 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"'), |
| @@ -2978,24 +2974,47 @@ 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) { |
|
ahe
2013/08/15 22:20:27
Why the extra semicolon?
blois
2013/08/15 22:38:48
In minified mode, the preceeding lines look like:
ahe
2013/08/15 22:43:48
I think you should modify line 3865 instead. It sh
|
| + if (typeof document === 'undefined') { |
| + callback(null); |
| + return; |
| + } |
| + if (document.currentScript) { |
| + callback(document.currentScript); |
| + return; |
| + } |
| + |
| + var scripts = document.scripts; |
| + function onLoad() { |
|
ahe
2013/08/15 22:24:38
Shouldn't this function have a parameter named 'ev
blois
2013/08/15 22:38:48
Great catch- that must be the IE issue.
|
| + 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) { |
| + ${namer.isolateName}.${namer.isolatePropertiesName}.\$currentScript = |
| + currentScript; |
| + |
| + if (typeof console !== 'undefined' && typeof document !== 'undefined' && |
| + document.readyState == "loading") { |
| + console.warn("Dart script executed synchronously, use <script src='" + |
| + currentScript.src + "' defer></scr" + "ipt> to execute after parsing " + |
| + "has completed. See also http://dartbug.com/12281."); |
| + } |
| if (typeof dartMainRunner === "function") { |
| dartMainRunner(function() { ${mainCall}; }); |
| } else { |
| ${mainCall}; |
| } |
| -} |
| +}); |
|
ahe
2013/08/15 22:20:27
Use $N instead of semicolon-newline here.
blois
2013/08/15 22:38:48
Done.
|
| """); |
| addComment('END invoke [main].', buffer); |
| } |