| 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 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2933 buffer.write( | 2933 buffer.write( |
| 2934 jsAst.prettyPrint(generateDispatchPropertyInitialization(), | 2934 jsAst.prettyPrint(generateDispatchPropertyInitialization(), |
| 2935 compiler)); | 2935 compiler)); |
| 2936 buffer.write(N); | 2936 buffer.write(N); |
| 2937 } | 2937 } |
| 2938 addComment('BEGIN invoke [main].', buffer); | 2938 addComment('BEGIN invoke [main].', buffer); |
| 2939 // This code finds the currently executing script by listening to the | 2939 // This code finds the currently executing script by listening to the |
| 2940 // onload event of all script tags and getting the first script which | 2940 // onload event of all script tags and getting the first script which |
| 2941 // finishes. Since onload is called immediately after execution this should | 2941 // finishes. Since onload is called immediately after execution this should |
| 2942 // not substantially change execution order. | 2942 // not substantially change execution order. |
| 2943 buffer.write(""" | 2943 buffer.write(''' |
| 2944 ;(function (callback) { | 2944 ;(function (callback) { |
| 2945 if (typeof document === 'undefined') { | 2945 if (typeof document === "undefined") { |
| 2946 callback(null); | 2946 callback(null); |
| 2947 return; | 2947 return; |
| 2948 } | 2948 } |
| 2949 if (document.currentScript) { | 2949 if (document.currentScript) { |
| 2950 callback(document.currentScript); | 2950 callback(document.currentScript); |
| 2951 return; | 2951 return; |
| 2952 } | 2952 } |
| 2953 | 2953 |
| 2954 var scripts = document.scripts; | 2954 var scripts = document.scripts; |
| 2955 function onLoad(event) { | 2955 function onLoad(event) { |
| 2956 for (var i = 0; i < scripts.length; ++i) { | 2956 for (var i = 0; i < scripts.length; ++i) { |
| 2957 scripts[i].removeEventListener('load', onLoad, false); | 2957 scripts[i].removeEventListener("load", onLoad, false); |
| 2958 } | 2958 } |
| 2959 callback(event.target); | 2959 callback(event.target); |
| 2960 } | 2960 } |
| 2961 for (var i = 0; i < scripts.length; ++i) { | 2961 for (var i = 0; i < scripts.length; ++i) { |
| 2962 scripts[i].addEventListener('load', onLoad, false); | 2962 scripts[i].addEventListener("load", onLoad, false); |
| 2963 } | 2963 } |
| 2964 })(function(currentScript) { | 2964 })(function(currentScript) { |
| 2965 ${namer.isolateName}.${namer.isolatePropertiesName}.\$currentScript = | 2965 ${namer.isolateName}.${namer.isolatePropertiesName}.\$currentScript = |
| 2966 currentScript; | 2966 currentScript; |
| 2967 | 2967 |
| 2968 if (typeof console !== 'undefined' && typeof document !== 'undefined' && | 2968 if (typeof console !== "undefined" && typeof document !== "undefined" && |
| 2969 document.readyState == "loading") { | 2969 document.readyState == "loading") { |
| 2970 console.warn("Dart script executed synchronously, use <script src='" + | 2970 console.warn("Dart script executed synchronously, use <script src='" + |
| 2971 currentScript.src + "' defer></scr" + "ipt> to execute after parsing " + | 2971 currentScript.src + "' defer></scr" + "ipt> to execute after parsing " + |
| 2972 "has completed. See also http://dartbug.com/12281."); | 2972 "has completed. See also http://dartbug.com/12281."); |
| 2973 } | 2973 } |
| 2974 if (typeof dartMainRunner === "function") { | 2974 if (typeof dartMainRunner === "function") { |
| 2975 dartMainRunner(function() { ${mainCall}; }); | 2975 dartMainRunner(function() { ${mainCall}; }); |
| 2976 } else { | 2976 } else { |
| 2977 ${mainCall}; | 2977 ${mainCall}; |
| 2978 } | 2978 } |
| 2979 })$N"""); | 2979 })$N'''); |
| 2980 addComment('END invoke [main].', buffer); | 2980 addComment('END invoke [main].', buffer); |
| 2981 } | 2981 } |
| 2982 | 2982 |
| 2983 void emitGetInterceptorMethod(CodeBuffer buffer, | 2983 void emitGetInterceptorMethod(CodeBuffer buffer, |
| 2984 String key, | 2984 String key, |
| 2985 Set<ClassElement> classes) { | 2985 Set<ClassElement> classes) { |
| 2986 jsAst.Statement buildReturnInterceptor(ClassElement cls) { | 2986 jsAst.Statement buildReturnInterceptor(ClassElement cls) { |
| 2987 return js.return_(js(namer.isolateAccess(cls))['prototype']); | 2987 return js.return_(js(namer.isolateAccess(cls))['prototype']); |
| 2988 } | 2988 } |
| 2989 | 2989 |
| (...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4113 | 4113 |
| 4114 const String HOOKS_API_USAGE = """ | 4114 const String HOOKS_API_USAGE = """ |
| 4115 // The code supports the following hooks: | 4115 // The code supports the following hooks: |
| 4116 // dartPrint(message) - if this function is defined it is called | 4116 // dartPrint(message) - if this function is defined it is called |
| 4117 // instead of the Dart [print] method. | 4117 // instead of the Dart [print] method. |
| 4118 // dartMainRunner(main) - if this function is defined, the Dart [main] | 4118 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 4119 // method will not be invoked directly. | 4119 // method will not be invoked directly. |
| 4120 // Instead, a closure that will invoke [main] is | 4120 // Instead, a closure that will invoke [main] is |
| 4121 // passed to [dartMainRunner]. | 4121 // passed to [dartMainRunner]. |
| 4122 """; | 4122 """; |
| OLD | NEW |