| 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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 | 7 |
| 8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 jsAst.Expression code = backend.generatedCode[element]; | 868 jsAst.Expression code = backend.generatedCode[element]; |
| 869 // The code is null if we ended up not needing the lazily | 869 // The code is null if we ended up not needing the lazily |
| 870 // initialized field after all because of constant folding | 870 // initialized field after all because of constant folding |
| 871 // before code generation. | 871 // before code generation. |
| 872 if (code == null) return null; | 872 if (code == null) return null; |
| 873 // The code only computes the initial value. We build the lazy-check | 873 // The code only computes the initial value. We build the lazy-check |
| 874 // here: | 874 // here: |
| 875 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); | 875 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); |
| 876 // The name is used for error reporting. The 'initial' must be a | 876 // The name is used for error reporting. The 'initial' must be a |
| 877 // closure that constructs the initial value. | 877 // closure that constructs the initial value. |
| 878 return js('#(#,#,#,#)', | 878 return js('#(#,#,#,#,#)', |
| 879 [js(lazyInitializerName), | 879 [js(lazyInitializerName), |
| 880 js(isolateProperties), |
| 880 js.string(element.name), | 881 js.string(element.name), |
| 881 js.string(namer.globalPropertyName(element)), | 882 js.string(namer.globalPropertyName(element)), |
| 882 js.string(namer.lazyInitializerName(element)), | 883 js.string(namer.lazyInitializerName(element)), |
| 883 code]); | 884 code]); |
| 884 } | 885 } |
| 885 | 886 |
| 886 void emitMetadata(Program program, CodeOutput output) { | 887 void emitMetadata(Program program, CodeOutput output) { |
| 887 | 888 |
| 888 addMetadataGlobal(List<String> list, String global) { | 889 addMetadataGlobal(List<String> list, String global) { |
| 889 String globalAccess = generateEmbeddedGlobalAccessString(global); | 890 String globalAccess = generateEmbeddedGlobalAccessString(global); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 jsAst.FunctionDeclaration decl = js.statement(''' | 1017 jsAst.FunctionDeclaration decl = js.statement(''' |
| 1017 function init() { | 1018 function init() { |
| 1018 $isolateProperties = Object.create(null); | 1019 $isolateProperties = Object.create(null); |
| 1019 #allClasses = Object.create(null); | 1020 #allClasses = Object.create(null); |
| 1020 #getTypeFromName = function(name) {return #allClasses[name];}; | 1021 #getTypeFromName = function(name) {return #allClasses[name];}; |
| 1021 #interceptorsByTag = Object.create(null); | 1022 #interceptorsByTag = Object.create(null); |
| 1022 #leafTags = Object.create(null); | 1023 #leafTags = Object.create(null); |
| 1023 #finishedClasses = Object.create(null); | 1024 #finishedClasses = Object.create(null); |
| 1024 | 1025 |
| 1025 if (#needsLazyInitializer) { | 1026 if (#needsLazyInitializer) { |
| 1026 $lazyInitializerName = function (staticName, fieldName, | 1027 $lazyInitializerName = function (prototype, staticName, fieldName, |
| 1027 getterName, lazyValue) { | 1028 getterName, lazyValue) { |
| 1028 if (!#lazies) #lazies = Object.create(null); | 1029 if (!#lazies) #lazies = Object.create(null); |
| 1029 #lazies[fieldName] = getterName; | 1030 #lazies[fieldName] = getterName; |
| 1030 | 1031 |
| 1031 var sentinelUndefined = {}; | 1032 var sentinelUndefined = {}; |
| 1032 var sentinelInProgress = {}; | 1033 var sentinelInProgress = {}; |
| 1033 $isolateProperties[fieldName] = sentinelUndefined; | 1034 prototype[fieldName] = sentinelUndefined; |
| 1034 | 1035 |
| 1035 $isolateProperties[getterName] = function () { | 1036 prototype[getterName] = function () { |
| 1036 var result = this[fieldName]; | 1037 var result = $isolate[fieldName]; |
| 1037 try { | 1038 try { |
| 1038 if (result === sentinelUndefined) { | 1039 if (result === sentinelUndefined) { |
| 1039 this[fieldName] = sentinelInProgress; | 1040 $isolate[fieldName] = sentinelInProgress; |
| 1040 | 1041 |
| 1041 try { | 1042 try { |
| 1042 result = this[fieldName] = lazyValue(); | 1043 result = $isolate[fieldName] = lazyValue(); |
| 1043 } finally { | 1044 } finally { |
| 1044 // Use try-finally, not try-catch/throw as it destroys the | 1045 // Use try-finally, not try-catch/throw as it destroys the |
| 1045 // stack trace. | 1046 // stack trace. |
| 1046 if (result === sentinelUndefined) | 1047 if (result === sentinelUndefined) |
| 1047 this[fieldName] = null; | 1048 $isolate[fieldName] = null; |
| 1048 } | 1049 } |
| 1049 } else { | 1050 } else { |
| 1050 if (result === sentinelInProgress) | 1051 if (result === sentinelInProgress) |
| 1051 #cyclicThrow(staticName); | 1052 #cyclicThrow(staticName); |
| 1052 } | 1053 } |
| 1053 | 1054 |
| 1054 return result; | 1055 return result; |
| 1055 } finally { | 1056 } finally { |
| 1056 this[getterName] = function() { return this[fieldName]; }; | 1057 $isolate[getterName] = function() { return this[fieldName]; }; |
| 1057 } | 1058 } |
| 1058 } | 1059 } |
| 1059 } | 1060 } |
| 1060 } | 1061 } |
| 1061 | 1062 |
| 1062 // We replace the old Isolate function with a new one that initializes | 1063 // We replace the old Isolate function with a new one that initializes |
| 1063 // all its fields with the initial (and often final) value of all | 1064 // all its fields with the initial (and often final) value of all |
| 1064 // globals. | 1065 // globals. |
| 1065 // | 1066 // |
| 1066 // We also copy over old values like the prototype, and the | 1067 // We also copy over old values like the prototype, and the |
| (...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2127 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2128 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2128 if (element.isInstanceMember) { | 2129 if (element.isInstanceMember) { |
| 2129 cachedClassBuilders.remove(element.enclosingClass); | 2130 cachedClassBuilders.remove(element.enclosingClass); |
| 2130 | 2131 |
| 2131 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2132 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2132 | 2133 |
| 2133 } | 2134 } |
| 2134 } | 2135 } |
| 2135 } | 2136 } |
| 2136 } | 2137 } |
| OLD | NEW |