| OLD | NEW |
| 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; | 7 import '../../constants/values.dart' show ConstantValue; |
| 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; | 10 import '../../elements/elements.dart' show ClassElement; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 generateEmbeddedGlobalAccess(INTERCEPTORS_BY_TAG); | 166 generateEmbeddedGlobalAccess(INTERCEPTORS_BY_TAG); |
| 167 js.Expression leafTagsAccess = | 167 js.Expression leafTagsAccess = |
| 168 generateEmbeddedGlobalAccess(LEAF_TAGS); | 168 generateEmbeddedGlobalAccess(LEAF_TAGS); |
| 169 js.Statement nativeInfoHandler = nativeEmitter.buildNativeInfoHandler( | 169 js.Statement nativeInfoHandler = nativeEmitter.buildNativeInfoHandler( |
| 170 nativeInfoAccess, | 170 nativeInfoAccess, |
| 171 constructorAccess, | 171 constructorAccess, |
| 172 subclassReadGenerator, | 172 subclassReadGenerator, |
| 173 interceptorsByTagAccess, | 173 interceptorsByTagAccess, |
| 174 leafTagsAccess); | 174 leafTagsAccess); |
| 175 | 175 |
| 176 nativeHoles['hasNativeClasses'] = program.outputContainsNativeClasses; | 176 nativeHoles['needsNativeSupport'] = program.needsNativeSupport; |
| 177 nativeHoles['hasNoNativeClasses'] = !program.outputContainsNativeClasses; | 177 nativeHoles['needsNoNativeSupport'] = !program.needsNativeSupport; |
| 178 nativeHoles['nativeInfoHandler'] = nativeInfoHandler; | 178 nativeHoles['nativeInfoHandler'] = nativeInfoHandler; |
| 179 | 179 |
| 180 return nativeHoles; | 180 return nativeHoles; |
| 181 } | 181 } |
| 182 | 182 |
| 183 js.Block emitHolders(List<Holder> holders) { | 183 js.Block emitHolders(List<Holder> holders) { |
| 184 // The top-level variables for holders must *not* be renamed by the | 184 // The top-level variables for holders must *not* be renamed by the |
| 185 // JavaScript pretty printer because a lot of code already uses the | 185 // JavaScript pretty printer because a lot of code already uses the |
| 186 // non-renamed names. The generated code looks like this: | 186 // non-renamed names. The generated code looks like this: |
| 187 // | 187 // |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 js.js('function () { return $isolateName; }'))); | 230 js.js('function () { return $isolateName; }'))); |
| 231 // TODO(floitsch): add remaining isolate functions. | 231 // TODO(floitsch): add remaining isolate functions. |
| 232 } | 232 } |
| 233 | 233 |
| 234 globals.add(emitMangledGlobalNames()); | 234 globals.add(emitMangledGlobalNames()); |
| 235 | 235 |
| 236 globals.add(emitGetTypeFromName()); | 236 globals.add(emitGetTypeFromName()); |
| 237 | 237 |
| 238 globals.add(emitMetadata(program)); | 238 globals.add(emitMetadata(program)); |
| 239 | 239 |
| 240 if (program.outputContainsNativeClasses) { | 240 if (program.needsNativeSupport) { |
| 241 globals.add(new js.Property(js.string(INTERCEPTORS_BY_TAG), | 241 globals.add(new js.Property(js.string(INTERCEPTORS_BY_TAG), |
| 242 js.js('Object.create(null)', []))); | 242 js.js('Object.create(null)', []))); |
| 243 globals.add(new js.Property(js.string(LEAF_TAGS), | 243 globals.add(new js.Property(js.string(LEAF_TAGS), |
| 244 js.js('Object.create(null)', []))); | 244 js.js('Object.create(null)', []))); |
| 245 } | 245 } |
| 246 | 246 |
| 247 js.ObjectInitializer globalsObject = new js.ObjectInitializer(globals); | 247 js.ObjectInitializer globalsObject = new js.ObjectInitializer(globals); |
| 248 | 248 |
| 249 List<js.Statement> statements = | 249 List<js.Statement> statements = |
| 250 [new js.ExpressionStatement( | 250 [new js.ExpressionStatement( |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 for (var i = 0; i < statics.length; i += 3) { | 770 for (var i = 0; i < statics.length; i += 3) { |
| 771 var holderIndex = statics[i + 1]; | 771 var holderIndex = statics[i + 1]; |
| 772 setupStatic(statics[i], holders[holderIndex], statics[i + 2]); | 772 setupStatic(statics[i], holders[holderIndex], statics[i + 2]); |
| 773 } | 773 } |
| 774 | 774 |
| 775 var classes = library[1]; | 775 var classes = library[1]; |
| 776 for (var i = 0; i < classes.length; i += 3) { | 776 for (var i = 0; i < classes.length; i += 3) { |
| 777 var name = classes[i]; | 777 var name = classes[i]; |
| 778 var cls = classes[i + 1]; | 778 var cls = classes[i + 1]; |
| 779 | 779 |
| 780 if (#hasNativeClasses) { | 780 if (#needsNativeSupport) { |
| 781 // $nativeInfoDescription. | 781 // $nativeInfoDescription. |
| 782 var indexOrNativeInfo = classes[i + 2]; | 782 var indexOrNativeInfo = classes[i + 2]; |
| 783 if (typeof indexOrNativeInfo == "number") { | 783 if (typeof indexOrNativeInfo == "number") { |
| 784 var holderIndex = classes[i + 2]; | 784 var holderIndex = classes[i + 2]; |
| 785 } else { | 785 } else { |
| 786 nativeInfos[name] = indexOrNativeInfo; | 786 nativeInfos[name] = indexOrNativeInfo; |
| 787 holderIndex = classes[i + 3]; | 787 holderIndex = classes[i + 3]; |
| 788 i++; | 788 i++; |
| 789 } | 789 } |
| 790 } | 790 } |
| 791 | 791 |
| 792 if (#hasNoNativeClasses) { | 792 if (#needsNoNativeSupport) { |
| 793 var holderIndex = classes[i + 2]; | 793 var holderIndex = classes[i + 2]; |
| 794 } | 794 } |
| 795 | 795 |
| 796 holdersMap[name] = holders[holderIndex]; | 796 holdersMap[name] = holders[holderIndex]; |
| 797 setupClass(name, holders[holderIndex], cls); | 797 setupClass(name, holders[holderIndex], cls); |
| 798 } | 798 } |
| 799 } | 799 } |
| 800 | 800 |
| 801 function setupLazyStatics(statics) { | 801 function setupLazyStatics(statics) { |
| 802 for (var i = 0; i < statics.length; i += 4) { | 802 for (var i = 0; i < statics.length; i += 4) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 function makeConstList(list) { | 977 function makeConstList(list) { |
| 978 // By assigning a function to the properties they become part of the | 978 // By assigning a function to the properties they become part of the |
| 979 // hidden class. The actual values of the fields don't matter, since we | 979 // hidden class. The actual values of the fields don't matter, since we |
| 980 // only check if they exist. | 980 // only check if they exist. |
| 981 list.immutable\$list = Array; | 981 list.immutable\$list = Array; |
| 982 list.fixed\$length = Array; | 982 list.fixed\$length = Array; |
| 983 return list; | 983 return list; |
| 984 } | 984 } |
| 985 } | 985 } |
| 986 | 986 |
| 987 if (#hasNativeClasses) { | 987 if (#needsNativeSupport) { |
| 988 function handleNativeClassInfos() { | 988 function handleNativeClassInfos() { |
| 989 for (var nativeClass in nativeInfos) { | 989 for (var nativeClass in nativeInfos) { |
| 990 var constructor = holdersMap[nativeClass][nativeClass].ensureResolved(); | 990 var constructor = holdersMap[nativeClass][nativeClass].ensureResolved(); |
| 991 var nativeInfo = nativeInfos[nativeClass]; | 991 var nativeInfo = nativeInfos[nativeClass]; |
| 992 #nativeInfoHandler; | 992 #nativeInfoHandler; |
| 993 } | 993 } |
| 994 } | 994 } |
| 995 } | 995 } |
| 996 | 996 |
| 997 $setupProgramName(program); | 997 $setupProgramName(program); |
| 998 | 998 |
| 999 // Initialize constants. | 999 // Initialize constants. |
| 1000 #constants; | 1000 #constants; |
| 1001 | 1001 |
| 1002 // Initialize globals. | 1002 // Initialize globals. |
| 1003 #embeddedGlobals; | 1003 #embeddedGlobals; |
| 1004 | 1004 |
| 1005 // TODO(floitsch): this order means that native classes may not be | 1005 // TODO(floitsch): this order means that native classes may not be |
| 1006 // referenced from constants. I'm mostly afraid of things like using them as | 1006 // referenced from constants. I'm mostly afraid of things like using them as |
| 1007 // generic arguments (which should be fine, but maybe there are other | 1007 // generic arguments (which should be fine, but maybe there are other |
| 1008 // similar things). | 1008 // similar things). |
| 1009 // Initialize natives. | 1009 // Initialize natives. |
| 1010 if (#hasNativeClasses) handleNativeClassInfos(); | 1010 if (#needsNativeSupport) handleNativeClassInfos(); |
| 1011 | 1011 |
| 1012 // Initialize static non-final fields. | 1012 // Initialize static non-final fields. |
| 1013 #staticNonFinals; | 1013 #staticNonFinals; |
| 1014 | 1014 |
| 1015 // Add native boilerplate code. | 1015 // Add native boilerplate code. |
| 1016 #nativeIsolateAffinityTagInitialization; | 1016 #nativeIsolateAffinityTagInitialization; |
| 1017 | 1017 |
| 1018 // Initialize eager classes. | 1018 // Initialize eager classes. |
| 1019 #eagerClasses; | 1019 #eagerClasses; |
| 1020 | 1020 |
| 1021 var end = Date.now(); | 1021 var end = Date.now(); |
| 1022 // print('Setup: ' + (end - start) + ' ms.'); | 1022 // print('Setup: ' + (end - start) + ' ms.'); |
| 1023 | 1023 |
| 1024 #invokeMain; // Start main. | 1024 #invokeMain; // Start main. |
| 1025 | 1025 |
| 1026 }(Date.now(), #code) | 1026 }(Date.now(), #code) |
| 1027 }"""; | 1027 }"""; |
| 1028 | 1028 |
| 1029 } | 1029 } |
| OLD | NEW |