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 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2952 } else { | 2948 } else { |
2953 mainCall = '${namer.isolateAccess(main)}()'; | 2949 mainCall = '${namer.isolateAccess(main)}()'; |
2954 } | 2950 } |
2955 if (backend.needToInitializeDispatchProperty) { | 2951 if (backend.needToInitializeDispatchProperty) { |
2956 buffer.write( | 2952 buffer.write( |
2957 jsAst.prettyPrint(generateDispatchPropertyInitialization(), | 2953 jsAst.prettyPrint(generateDispatchPropertyInitialization(), |
2958 compiler)); | 2954 compiler)); |
2959 buffer.write(N); | 2955 buffer.write(N); |
2960 } | 2956 } |
2961 addComment('BEGIN invoke [main].', buffer); | 2957 addComment('BEGIN invoke [main].', buffer); |
2958 // This code finds the currently executing script by listening to the | |
2959 // onload event of all script tags and getting the first script which | |
2960 // finishes. Since onload is called immediately after execution this should | |
2961 // not substantially change execution order. | |
2962 buffer.write(""" | 2962 buffer.write(""" |
2963 if (typeof document !== "undefined" && document.readyState !== "complete") { | 2963 (function (callback) { |
2964 document.addEventListener("readystatechange", function () { | 2964 if (typeof document === 'undefined') { |
2965 if (document.readyState == "complete") { | 2965 callback(null); |
2966 if (typeof dartMainRunner === "function") { | 2966 return; |
2967 dartMainRunner(function() { ${mainCall}; }); | 2967 } |
2968 } else { | 2968 if (document.currentScript) { |
2969 ${mainCall}; | 2969 callback(document.currentScript); |
2970 } | 2970 return; |
2971 } | |
2972 | |
2973 var scripts = document.scripts; | |
2974 function onLoad() { | |
2975 for (var i = 0; i < scripts.length; ++i) { | |
2976 scripts[i].removeEventListener('load', onLoad, false); | |
2971 } | 2977 } |
2972 }, false); | 2978 callback(event.target); |
2973 } else { | 2979 } |
2980 for (var i = 0; i < scripts.length; ++i) { | |
2981 scripts[i].addEventListener('load', onLoad, false); | |
2982 } | |
2983 })(function(currentScript) { | |
2984 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!
| |
2985 | |
2986 if (typeof console !== 'undefined' && typeof document !== 'undefined' && | |
2987 document.readyState == "loading") { | |
2988 // 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
| |
2989 // Dartium execution timing. | |
2990 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!
| |
2991 currentScript.src + "' defer></scr" + "ipt> to execute after parsing " + | |
2992 "has completed."); | |
2993 } | |
2974 if (typeof dartMainRunner === "function") { | 2994 if (typeof dartMainRunner === "function") { |
2975 dartMainRunner(function() { ${mainCall}; }); | 2995 dartMainRunner(function() { ${mainCall}; }); |
2976 } else { | 2996 } else { |
2977 ${mainCall}; | 2997 ${mainCall}; |
2978 } | 2998 } |
2979 } | 2999 }); |
2980 """); | 3000 """); |
2981 addComment('END invoke [main].', buffer); | 3001 addComment('END invoke [main].', buffer); |
2982 } | 3002 } |
2983 | 3003 |
2984 void emitGetInterceptorMethod(CodeBuffer buffer, | 3004 void emitGetInterceptorMethod(CodeBuffer buffer, |
2985 String key, | 3005 String key, |
2986 Iterable<ClassElement> classes) { | 3006 Iterable<ClassElement> classes) { |
2987 jsAst.Statement buildReturnInterceptor(ClassElement cls) { | 3007 jsAst.Statement buildReturnInterceptor(ClassElement cls) { |
2988 return js.return_(js(namer.isolateAccess(cls))['prototype']); | 3008 return js.return_(js(namer.isolateAccess(cls))['prototype']); |
2989 } | 3009 } |
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4061 | 4081 |
4062 const String HOOKS_API_USAGE = """ | 4082 const String HOOKS_API_USAGE = """ |
4063 // The code supports the following hooks: | 4083 // The code supports the following hooks: |
4064 // dartPrint(message) - if this function is defined it is called | 4084 // dartPrint(message) - if this function is defined it is called |
4065 // instead of the Dart [print] method. | 4085 // instead of the Dart [print] method. |
4066 // dartMainRunner(main) - if this function is defined, the Dart [main] | 4086 // dartMainRunner(main) - if this function is defined, the Dart [main] |
4067 // method will not be invoked directly. | 4087 // method will not be invoked directly. |
4068 // Instead, a closure that will invoke [main] is | 4088 // Instead, a closure that will invoke [main] is |
4069 // passed to [dartMainRunner]. | 4089 // passed to [dartMainRunner]. |
4070 """; | 4090 """; |
OLD | NEW |