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

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

Powered by Google App Engine
This is Rietveld 408576698