OLD | NEW |
---|---|
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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 /** | 7 /** |
8 * A function element that represents a closure call. The signature is copied | 8 * A function element that represents a closure call. The signature is copied |
9 * from the given element. | 9 * from the given element. |
10 */ | 10 */ |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
850 if (needsDefineClass) { | 850 if (needsDefineClass) { |
851 copyFinishClasses.add( | 851 copyFinishClasses.add( |
852 js('newIsolate.$finishClassesProperty = ' | 852 js('newIsolate.$finishClassesProperty = ' |
853 ' oldIsolate.$finishClassesProperty')); | 853 ' oldIsolate.$finishClassesProperty')); |
854 } | 854 } |
855 | 855 |
856 // function(oldIsolate) { | 856 // function(oldIsolate) { |
857 return js.fun('oldIsolate', [ | 857 return js.fun('oldIsolate', [ |
858 js('var isolateProperties = oldIsolate.${namer.isolatePropertiesName}'), | 858 js('var isolateProperties = oldIsolate.${namer.isolatePropertiesName}'), |
859 | 859 |
860 js(r'isolateProperties.$currentScript =' | 860 js(r'isolateProperties.$currentScript = null'), |
861 'typeof document == "object" ?' | |
862 '(document.currentScript ||' | |
863 'document.scripts[document.scripts.length - 1]) :' | |
864 'null'), | |
865 | 861 |
866 js('var isolatePrototype = oldIsolate.prototype'), | 862 js('var isolatePrototype = oldIsolate.prototype'), |
867 js('var str = "{\\n"'), | 863 js('var str = "{\\n"'), |
868 js('str += "var properties = ' | 864 js('str += "var properties = ' |
869 'arguments.callee.${namer.isolatePropertiesName};\\n"'), | 865 'arguments.callee.${namer.isolatePropertiesName};\\n"'), |
870 js('var hasOwnProperty = Object.prototype.hasOwnProperty'), | 866 js('var hasOwnProperty = Object.prototype.hasOwnProperty'), |
871 | 867 |
872 // for (var staticName in isolateProperties) { | 868 // for (var staticName in isolateProperties) { |
873 js.forIn('staticName', 'isolateProperties', [ | 869 js.forIn('staticName', 'isolateProperties', [ |
874 js.if_('hasOwnProperty.call(isolateProperties, staticName)', [ | 870 js.if_('hasOwnProperty.call(isolateProperties, staticName)', [ |
(...skipping 2096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2971 } else { | 2967 } else { |
2972 mainCall = '${namer.isolateAccess(main)}()'; | 2968 mainCall = '${namer.isolateAccess(main)}()'; |
2973 } | 2969 } |
2974 if (backend.needToInitializeDispatchProperty) { | 2970 if (backend.needToInitializeDispatchProperty) { |
2975 buffer.write( | 2971 buffer.write( |
2976 jsAst.prettyPrint(generateDispatchPropertyInitialization(), | 2972 jsAst.prettyPrint(generateDispatchPropertyInitialization(), |
2977 compiler)); | 2973 compiler)); |
2978 buffer.write(N); | 2974 buffer.write(N); |
2979 } | 2975 } |
2980 addComment('BEGIN invoke [main].', buffer); | 2976 addComment('BEGIN invoke [main].', buffer); |
2977 // This code finds the currently executing script by listening to the | |
2978 // onload event of all script tags and getting the first script which | |
2979 // finishes. Since onload is called immediately after execution this should | |
2980 // not substantially change execution order. | |
2981 buffer.write(""" | 2981 buffer.write(""" |
2982 if (typeof document !== "undefined" && document.readyState !== "complete") { | 2982 ;(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
| |
2983 document.addEventListener("readystatechange", function () { | 2983 if (typeof document === 'undefined') { |
2984 if (document.readyState == "complete") { | 2984 callback(null); |
2985 if (typeof dartMainRunner === "function") { | 2985 return; |
2986 dartMainRunner(function() { ${mainCall}; }); | 2986 } |
2987 } else { | 2987 if (document.currentScript) { |
2988 ${mainCall}; | 2988 callback(document.currentScript); |
2989 } | 2989 return; |
2990 } | |
2991 | |
2992 var scripts = document.scripts; | |
2993 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.
| |
2994 for (var i = 0; i < scripts.length; ++i) { | |
2995 scripts[i].removeEventListener('load', onLoad, false); | |
2990 } | 2996 } |
2991 }, false); | 2997 callback(event.target); |
2992 } else { | 2998 } |
2999 for (var i = 0; i < scripts.length; ++i) { | |
3000 scripts[i].addEventListener('load', onLoad, false); | |
3001 } | |
3002 })(function(currentScript) { | |
3003 ${namer.isolateName}.${namer.isolatePropertiesName}.\$currentScript = | |
3004 currentScript; | |
3005 | |
3006 if (typeof console !== 'undefined' && typeof document !== 'undefined' && | |
3007 document.readyState == "loading") { | |
3008 console.warn("Dart script executed synchronously, use <script src='" + | |
3009 currentScript.src + "' defer></scr" + "ipt> to execute after parsing " + | |
3010 "has completed. See also http://dartbug.com/12281."); | |
3011 } | |
2993 if (typeof dartMainRunner === "function") { | 3012 if (typeof dartMainRunner === "function") { |
2994 dartMainRunner(function() { ${mainCall}; }); | 3013 dartMainRunner(function() { ${mainCall}; }); |
2995 } else { | 3014 } else { |
2996 ${mainCall}; | 3015 ${mainCall}; |
2997 } | 3016 } |
2998 } | 3017 }); |
ahe
2013/08/15 22:20:27
Use $N instead of semicolon-newline here.
blois
2013/08/15 22:38:48
Done.
| |
2999 """); | 3018 """); |
3000 addComment('END invoke [main].', buffer); | 3019 addComment('END invoke [main].', buffer); |
3001 } | 3020 } |
3002 | 3021 |
3003 void emitGetInterceptorMethod(CodeBuffer buffer, | 3022 void emitGetInterceptorMethod(CodeBuffer buffer, |
3004 String key, | 3023 String key, |
3005 Iterable<ClassElement> classes) { | 3024 Iterable<ClassElement> classes) { |
3006 jsAst.Statement buildReturnInterceptor(ClassElement cls) { | 3025 jsAst.Statement buildReturnInterceptor(ClassElement cls) { |
3007 return js.return_(js(namer.isolateAccess(cls))['prototype']); | 3026 return js.return_(js(namer.isolateAccess(cls))['prototype']); |
3008 } | 3027 } |
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4089 | 4108 |
4090 const String HOOKS_API_USAGE = """ | 4109 const String HOOKS_API_USAGE = """ |
4091 // The code supports the following hooks: | 4110 // The code supports the following hooks: |
4092 // dartPrint(message) - if this function is defined it is called | 4111 // dartPrint(message) - if this function is defined it is called |
4093 // instead of the Dart [print] method. | 4112 // instead of the Dart [print] method. |
4094 // dartMainRunner(main) - if this function is defined, the Dart [main] | 4113 // dartMainRunner(main) - if this function is defined, the Dart [main] |
4095 // method will not be invoked directly. | 4114 // method will not be invoked directly. |
4096 // Instead, a closure that will invoke [main] is | 4115 // Instead, a closure that will invoke [main] is |
4097 // passed to [dartMainRunner]. | 4116 // passed to [dartMainRunner]. |
4098 """; | 4117 """; |
OLD | NEW |