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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart

Issue 962853002: dart2js: Allow multiple invocations of type.ensureResolved in new emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanups Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library dart2js.new_js_emitter.model_emitter; 5 library dart2js.new_js_emitter.model_emitter;
6 6
7 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue; 7 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue;
8 import '../../dart2jslib.dart' show Compiler; 8 import '../../dart2jslib.dart' show Compiler;
9 import '../../dart_types.dart' show DartType; 9 import '../../dart_types.dart' show DartType;
10 import '../../elements/elements.dart' show ClassElement, FunctionElement; 10 import '../../elements/elements.dart' show ClassElement, FunctionElement;
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 var getterName = statics[i + 1]; 859 var getterName = statics[i + 1];
860 var holderIndex = statics[i + 2]; 860 var holderIndex = statics[i + 2];
861 var initializer = statics[i + 3]; 861 var initializer = statics[i + 3];
862 setupLazyStatic(name, getterName, holders[holderIndex], initializer); 862 setupLazyStatic(name, getterName, holders[holderIndex], initializer);
863 } 863 }
864 } 864 }
865 865
866 function setupStatic(name, holder, descriptor) { 866 function setupStatic(name, holder, descriptor) {
867 if (typeof descriptor == 'string') { 867 if (typeof descriptor == 'string') {
868 holder[name] = function() { 868 holder[name] = function() {
869 if (descriptor == null) {
870 // Already compiled. This happens when we have calls to the static as
871 // arguments to the static: `foo(foo(499))`;
872 return holder[name].apply(this, arguments);
873 }
869 var method = compile(name, descriptor); 874 var method = compile(name, descriptor);
870 holder[name] = method; 875 holder[name] = method;
876 descriptor = null; // GC the descriptor.
871 return method.apply(this, arguments); 877 return method.apply(this, arguments);
872 }; 878 };
873 } else { 879 } else {
874 // Parse the tear off information and generate compile handlers. 880 // Parse the tear off information and generate compile handlers.
875 // TODO(herhut): Share parser with instance methods. 881 // TODO(herhut): Share parser with instance methods.
876 function compileAllStubs() { 882 function compileAllStubs() {
877 var funs; 883 var funs;
878 var fun = compile(name, descriptor[0]); 884 var fun = compile(name, descriptor[0]);
879 fun[#callName] = descriptor[1]; 885 fun[#callName] = descriptor[1];
880 holder[name] = fun; 886 holder[name] = fun;
(...skipping 14 matching lines...) Expand all
895 tearOff(funs, descriptor[3], true, name, false); 901 tearOff(funs, descriptor[3], true, name, false);
896 } 902 }
897 if (pos < descriptor.length) { 903 if (pos < descriptor.length) {
898 fun[#argumentCount] = descriptor[pos]; 904 fun[#argumentCount] = descriptor[pos];
899 fun[#defaultArgumentValues] = descriptor[pos + 1]; 905 fun[#defaultArgumentValues] = descriptor[pos + 1];
900 } 906 }
901 } 907 }
902 908
903 function setupCompileAllAndDelegateStub(name) { 909 function setupCompileAllAndDelegateStub(name) {
904 holder[name] = function() { 910 holder[name] = function() {
905 compileAllStubs(); 911 // The descriptor is null if we already compiled this function. This
912 // happens when we have calls to the static as arguments to the
913 // static: `foo(foo(499))`;
914 if (descriptor != null) {
915 compileAllStubs();
916 descriptor = null; // GC the descriptor.
917 }
906 return holder[name].apply(this, arguments); 918 return holder[name].apply(this, arguments);
907 }; 919 };
908 } 920 }
909 921
910 setupCompileAllAndDelegateStub(name); 922 setupCompileAllAndDelegateStub(name);
911 for (var pos = 4; pos < descriptor.length; pos += 3) { 923 for (var pos = 4; pos < descriptor.length; pos += 3) {
912 setupCompileAllAndDelegateStub(descriptor[pos]); 924 setupCompileAllAndDelegateStub(descriptor[pos]);
913 } 925 }
914 if (descriptor[2] != null) { // tear-off name. 926 if (descriptor[2] != null) { // tear-off name.
915 setupCompileAllAndDelegateStub(descriptor[2]) 927 setupCompileAllAndDelegateStub(descriptor[2])
(...skipping 20 matching lines...) Expand all
936 holder[name] = null; 948 holder[name] = null;
937 } 949 }
938 holder[getterName] = function() { return this[name]; }; 950 holder[getterName] = function() { return this[name]; };
939 } 951 }
940 return result; 952 return result;
941 }; 953 };
942 } 954 }
943 955
944 function setupClass(name, holder, descriptor) { 956 function setupClass(name, holder, descriptor) {
945 var patch = function() { 957 var patch = function() {
946 var constructor = compileConstructor(name, descriptor); 958 if (patch.ensureResolved == patch) {
947 holder[name] = constructor; 959 // We have not yet been compiled.
948 constructor.ensureResolved = function() { return this; }; 960 var constructor = compileConstructor(name, descriptor);
949 if (this === patch) return constructor; // Was used as "ensureResolved". 961 holder[name] = constructor;
962 name = holder = descriptor = null; // GC the captured arguments.
963 // Make sure we can invoke 'ensureResolved' multiple times on the patch
964 // function.
965 patch.ensureResolved = function() { return constructor; };
966 constructor.ensureResolved = function() { return this; };
967 } else {
968 // This can happen when arguments to the constructor are of the same
969 // class, like in `new A(new A(null))`.
970 constructor = patch.ensureResolved();
971 }
972 // If the patch has been called as "ensureResolved" return.
973 if (this === patch) return constructor;
950 var object = new constructor(); 974 var object = new constructor();
951 constructor.apply(object, arguments); 975 constructor.apply(object, arguments);
952 return object; 976 return object;
953 }; 977 };
954 978
955 // We store the patch function on itself to make it 979 // We store the patch function on itself to make it
956 // possible to resolve superclass references without constructing instances. 980 // possible to resolve superclass references without constructing instances.
957 patch.ensureResolved = patch; 981 patch.ensureResolved = patch;
958 holder[name] = patch; 982 holder[name] = patch;
959 } 983 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 1099
1076 var end = Date.now(); 1100 var end = Date.now();
1077 // print('Setup: ' + (end - start) + ' ms.'); 1101 // print('Setup: ' + (end - start) + ' ms.');
1078 1102
1079 #invokeMain; // Start main. 1103 #invokeMain; // Start main.
1080 1104
1081 }(Date.now(), #code) 1105 }(Date.now(), #code)
1082 }"""; 1106 }""";
1083 1107
1084 } 1108 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698