| 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 = null'), | 860 js(r'isolateProperties.$currentScript =' |
| 861 'typeof document == "object" ?' |
| 862 '(document.currentScript ||' |
| 863 'document.scripts[document.scripts.length - 1]) :' |
| 864 'null'), |
| 861 | 865 |
| 862 js('var isolatePrototype = oldIsolate.prototype'), | 866 js('var isolatePrototype = oldIsolate.prototype'), |
| 863 js('var str = "{\\n"'), | 867 js('var str = "{\\n"'), |
| 864 js('str += "var properties = ' | 868 js('str += "var properties = ' |
| 865 'arguments.callee.${namer.isolatePropertiesName};\\n"'), | 869 'arguments.callee.${namer.isolatePropertiesName};\\n"'), |
| 866 js('var hasOwnProperty = Object.prototype.hasOwnProperty'), | 870 js('var hasOwnProperty = Object.prototype.hasOwnProperty'), |
| 867 | 871 |
| 868 // for (var staticName in isolateProperties) { | 872 // for (var staticName in isolateProperties) { |
| 869 js.forIn('staticName', 'isolateProperties', [ | 873 js.forIn('staticName', 'isolateProperties', [ |
| 870 js.if_('hasOwnProperty.call(isolateProperties, staticName)', [ | 874 js.if_('hasOwnProperty.call(isolateProperties, staticName)', [ |
| (...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2961 } else { | 2965 } else { |
| 2962 mainCall = '${namer.isolateAccess(main)}()'; | 2966 mainCall = '${namer.isolateAccess(main)}()'; |
| 2963 } | 2967 } |
| 2964 if (backend.needToInitializeDispatchProperty) { | 2968 if (backend.needToInitializeDispatchProperty) { |
| 2965 buffer.write( | 2969 buffer.write( |
| 2966 jsAst.prettyPrint(generateDispatchPropertyInitialization(), | 2970 jsAst.prettyPrint(generateDispatchPropertyInitialization(), |
| 2967 compiler)); | 2971 compiler)); |
| 2968 buffer.write(N); | 2972 buffer.write(N); |
| 2969 } | 2973 } |
| 2970 addComment('BEGIN invoke [main].', buffer); | 2974 addComment('BEGIN invoke [main].', buffer); |
| 2971 // This code finds the currently executing script by listening to the | |
| 2972 // onload event of all script tags and getting the first script which | |
| 2973 // finishes. Since onload is called immediately after execution this should | |
| 2974 // not substantially change execution order. | |
| 2975 buffer.write(""" | 2975 buffer.write(""" |
| 2976 ;(function (callback) { | 2976 if (typeof document !== "undefined" && document.readyState !== "complete") { |
| 2977 if (typeof document === 'undefined') { | 2977 document.addEventListener("readystatechange", function () { |
| 2978 callback(null); | 2978 if (document.readyState == "complete") { |
| 2979 return; | 2979 if (typeof dartMainRunner === "function") { |
| 2980 } | 2980 dartMainRunner(function() { ${mainCall}; }); |
| 2981 if (document.currentScript) { | 2981 } else { |
| 2982 callback(document.currentScript); | 2982 ${mainCall}; |
| 2983 return; | 2983 } |
| 2984 } | |
| 2985 | |
| 2986 var scripts = document.scripts; | |
| 2987 function onLoad() { | |
| 2988 for (var i = 0; i < scripts.length; ++i) { | |
| 2989 scripts[i].removeEventListener('load', onLoad, false); | |
| 2990 } | 2984 } |
| 2991 callback(event.target); | 2985 }, false); |
| 2992 } | 2986 } else { |
| 2993 for (var i = 0; i < scripts.length; ++i) { | |
| 2994 scripts[i].addEventListener('load', onLoad, false); | |
| 2995 } | |
| 2996 })(function(currentScript) { | |
| 2997 ${namer.isolateName}.${namer.isolatePropertiesName}.\$currentScript = | |
| 2998 currentScript; | |
| 2999 | |
| 3000 if (typeof console !== 'undefined' && typeof document !== 'undefined' && | |
| 3001 document.readyState == "loading") { | |
| 3002 console.warn("Dart script executed synchronously, use <script src='" + | |
| 3003 currentScript.src + "' defer></scr" + "ipt> to execute after parsing " + | |
| 3004 "has completed. See also http://dartbug.com/12281."); | |
| 3005 } | |
| 3006 if (typeof dartMainRunner === "function") { | 2987 if (typeof dartMainRunner === "function") { |
| 3007 dartMainRunner(function() { ${mainCall}; }); | 2988 dartMainRunner(function() { ${mainCall}; }); |
| 3008 } else { | 2989 } else { |
| 3009 ${mainCall}; | 2990 ${mainCall}; |
| 3010 } | 2991 } |
| 3011 }); | 2992 } |
| 3012 """); | 2993 """); |
| 3013 addComment('END invoke [main].', buffer); | 2994 addComment('END invoke [main].', buffer); |
| 3014 } | 2995 } |
| 3015 | 2996 |
| 3016 void emitGetInterceptorMethod(CodeBuffer buffer, | 2997 void emitGetInterceptorMethod(CodeBuffer buffer, |
| 3017 String key, | 2998 String key, |
| 3018 Iterable<ClassElement> classes) { | 2999 Iterable<ClassElement> classes) { |
| 3019 jsAst.Statement buildReturnInterceptor(ClassElement cls) { | 3000 jsAst.Statement buildReturnInterceptor(ClassElement cls) { |
| 3020 return js.return_(js(namer.isolateAccess(cls))['prototype']); | 3001 return js.return_(js(namer.isolateAccess(cls))['prototype']); |
| 3021 } | 3002 } |
| (...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4093 | 4074 |
| 4094 const String HOOKS_API_USAGE = """ | 4075 const String HOOKS_API_USAGE = """ |
| 4095 // The code supports the following hooks: | 4076 // The code supports the following hooks: |
| 4096 // dartPrint(message) - if this function is defined it is called | 4077 // dartPrint(message) - if this function is defined it is called |
| 4097 // instead of the Dart [print] method. | 4078 // instead of the Dart [print] method. |
| 4098 // dartMainRunner(main) - if this function is defined, the Dart [main] | 4079 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 4099 // method will not be invoked directly. | 4080 // method will not be invoked directly. |
| 4100 // Instead, a closure that will invoke [main] is | 4081 // Instead, a closure that will invoke [main] is |
| 4101 // passed to [dartMainRunner]. | 4082 // passed to [dartMainRunner]. |
| 4102 """; | 4083 """; |
| OLD | NEW |