Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 22488002: Tightening up dart2js load timing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 2060 matching lines...) Expand 10 before | Expand all | Expand 10 after
2935 mainCall = '${namer.isolateAccess(main)}()'; 2931 mainCall = '${namer.isolateAccess(main)}()';
2936 } 2932 }
2937 if (backend.needToInitializeDispatchProperty) { 2933 if (backend.needToInitializeDispatchProperty) {
2938 buffer.write( 2934 buffer.write(
2939 jsAst.prettyPrint(generateDispatchPropertyInitialization(), 2935 jsAst.prettyPrint(generateDispatchPropertyInitialization(),
2940 compiler)); 2936 compiler));
2941 buffer.write(N); 2937 buffer.write(N);
2942 } 2938 }
2943 addComment('BEGIN invoke [main].', buffer); 2939 addComment('BEGIN invoke [main].', buffer);
2944 buffer.write(""" 2940 buffer.write("""
2945 if (typeof document !== "undefined" && document.readyState !== "complete") { 2941 (function (callback) {
2946 document.addEventListener("readystatechange", function () { 2942 if (!self.document) {
ahe 2013/08/07 16:24:47 Just a quick note, sorry. This will break dart2js
blois 2013/08/07 17:39:50 Ah, thanks!
2947 if (document.readyState == "complete") { 2943 callback(null);
2948 if (typeof dartMainRunner === "function") { 2944 return;
2949 dartMainRunner(function() { ${mainCall}; }); 2945 }
2950 } else { 2946 if (document.currentScript) {
2951 ${mainCall}; 2947 callback(document.currentScript);
2952 } 2948 return;
2949 }
2950
2951 var scripts = document.scripts;
2952 function onLoad() {
2953 for (var i = 0; i < scripts.length; ++i) {
2954 scripts[i].removeEventListener('load', onLoad, false);
vsm 2013/08/07 16:10:12 Can you add a comment here to explain what's going
blois 2013/08/07 17:39:50 Done.
2953 } 2955 }
2954 }, false); 2956 callback(event.target);
2955 } else { 2957 }
2958 for (var i = 0; i < scripts.length; ++i) {
2959 scripts[i].addEventListener('load', onLoad, false);
2960 }
2961 })(function(currentScript) {
2962 Isolate.\$isolateProperties.\$currentScript = currentScript;
2963
2964 if (self.console && self.document && document.readyState == "loading") {
2965 // Bug dartbug.com/12281 this warning is to let users know how to match
2966 // Dartium execution timing.
2967 console.warn("Dart script executed synchronously, use <script src='" +
2968 currentScript.src + "' defer></scr" + "ipt> to execute after parsing " +
2969 "has completed.");
2970 }
2956 if (typeof dartMainRunner === "function") { 2971 if (typeof dartMainRunner === "function") {
2957 dartMainRunner(function() { ${mainCall}; }); 2972 dartMainRunner(function() { ${mainCall}; });
2958 } else { 2973 } else {
2959 ${mainCall}; 2974 ${mainCall};
2960 } 2975 }
2961 } 2976 });
2962 """); 2977 """);
2963 addComment('END invoke [main].', buffer); 2978 addComment('END invoke [main].', buffer);
2964 } 2979 }
2965 2980
2966 void emitGetInterceptorMethod(CodeBuffer buffer, 2981 void emitGetInterceptorMethod(CodeBuffer buffer,
2967 String key, 2982 String key,
2968 Iterable<ClassElement> classes) { 2983 Iterable<ClassElement> classes) {
2969 jsAst.Statement buildReturnInterceptor(ClassElement cls) { 2984 jsAst.Statement buildReturnInterceptor(ClassElement cls) {
2970 return js.return_(js(namer.isolateAccess(cls))['prototype']); 2985 return js.return_(js(namer.isolateAccess(cls))['prototype']);
2971 } 2986 }
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
4043 4058
4044 const String HOOKS_API_USAGE = """ 4059 const String HOOKS_API_USAGE = """
4045 // The code supports the following hooks: 4060 // The code supports the following hooks:
4046 // dartPrint(message) - if this function is defined it is called 4061 // dartPrint(message) - if this function is defined it is called
4047 // instead of the Dart [print] method. 4062 // instead of the Dart [print] method.
4048 // dartMainRunner(main) - if this function is defined, the Dart [main] 4063 // dartMainRunner(main) - if this function is defined, the Dart [main]
4049 // method will not be invoked directly. 4064 // method will not be invoked directly.
4050 // Instead, a closure that will invoke [main] is 4065 // Instead, a closure that will invoke [main] is
4051 // passed to [dartMainRunner]. 4066 // passed to [dartMainRunner].
4052 """; 4067 """;
OLDNEW
« no previous file with comments | « samples/third_party/dromaeo/generate_dart2js_tests.py ('k') | tools/testing/dart/browser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698