Chromium Code Reviews| Index: lib/compiler/implementation/js_backend/emitter.dart |
| diff --git a/lib/compiler/implementation/js_backend/emitter.dart b/lib/compiler/implementation/js_backend/emitter.dart |
| index 43a43ae399641664fd5889888b53e383bbd88762..0b4852d72daeb736e8724ffe25c4c2ee679ff297 100644 |
| --- a/lib/compiler/implementation/js_backend/emitter.dart |
| +++ b/lib/compiler/implementation/js_backend/emitter.dart |
| @@ -656,7 +656,7 @@ function(collectedClasses) { |
| Map<Element, CodeBuffer> generatedCode, |
| String functionNamer(Element element)) { |
| generatedCode.forEach((Element element, CodeBuffer functionBuffer) { |
| - if (!element.isInstanceMember()) { |
| + if (!element.isInstanceMember() && element.kind != ElementKind.FIELD) { |
|
kasperl
2012/08/16 14:41:37
Don't we have an element.isField() tester?
floitsch
2012/08/16 22:52:33
Done.
|
| String functionName = functionNamer(element); |
| buffer.add('$isolateProperties.$functionName = '); |
| addMappings(functionBuffer, buffer.length); |
| @@ -834,6 +834,65 @@ $classesCollector.$mangledName = {'': |
| } |
| } |
| + void emitLazilyInitializedStaticFields(CodeBuffer buffer) { |
| + String nonBailoutElementNamer(Element element) { |
| + if (element.kind == ElementKind.FIELD) { |
|
kasperl
2012/08/16 14:41:37
isField
floitsch
2012/08/16 22:52:33
Done.
|
| + return namer.getLazyInitializerName(element); |
| + } else { |
| + return namer.getName(element); |
| + } |
| + } |
| + |
| + String bailoutElementNamer(Element element) { |
| + if (element.kind == ElementKind.FIELD) { |
|
kasperl
2012/08/16 14:41:37
isField
floitsch
2012/08/16 22:52:33
Done.
|
| + return namer.getLazyInitializerBailoutName(element); |
| + } else { |
| + return namer.getBailoutName(element); |
| + } |
| + } |
| + |
| + ConstantHandler handler = compiler.constantHandler; |
| + List<VariableElement> lazyFields = |
| + handler.getLazilyInitializedFieldsForEmission(); |
| + if (!lazyFields.isEmpty()) { |
| + JavaScriptBackend backend = compiler.backend; |
| + String isolatePropertiesSentinelAccess = |
| + '$isolateProperties.${namer.LAZY_INITIALIZATION_SENTINEL}'; |
| + buffer.add('$isolatePropertiesSentinelAccess = {};\n'); |
| + for (VariableElement element in lazyFields) { |
| + StringBuffer code = compiler.codegenWorld.generatedCode[element]; |
| + assert(code != null); |
| + // The code only computes the initial value. We build the lazy-check |
| + // here. |
| + String fieldName = namer.getName(element); |
| + String lazyGetterName = |
| + '$isolateProperties.${namer.getLazyInitializerName(element)}'; |
| + // We store the function that computes the initial value as field of |
| + // the lazy getter. |
| + // The lazy getter itself will be replaced at first access. |
| + String directFieldAccess = namer.isolateAccess(element); |
| + String sentinelAccess = |
| + '${namer.CURRENT_ISOLATE}.${namer.LAZY_INITIALIZATION_SENTINEL}'; |
| + buffer.add(''' |
| +$lazyGetterName = function() { |
|
kasperl
2012/08/16 14:41:37
As we discussed, I think this needs to do the try-
floitsch
2012/08/16 22:52:33
Done.
|
| + var value = $directFieldAccess; |
| + if (value === $sentinelAccess) { |
| + value = ${namer.isolateLazyInitializerAccess(element)}.lazy(); |
| + $directFieldAccess = value; |
| + } |
| + ${namer.isolateLazyInitializerAccess(element)} = function() { return $directFieldAccess; }; |
| + return value; |
| +}; |
| +'''); |
| + buffer.add('$lazyGetterName.lazy = '); |
| + buffer.add(code); |
| + buffer.add('\n$isolateProperties.${namer.getName(element)} = '); |
| + buffer.add(isolatePropertiesSentinelAccess); |
| + buffer.add(';\n'); |
| + } |
| + } |
| + } |
| + |
| void emitCompileTimeConstants(CodeBuffer buffer) { |
| ConstantHandler handler = compiler.constantHandler; |
| List<Constant> constants = handler.getConstantsForEmission(); |
| @@ -1128,6 +1187,7 @@ if (typeof document != 'undefined' && document.readyState != 'complete') { |
| // Static field initializations require the classes and compile-time |
| // constants to be set up. |
| emitStaticNonFinalFieldInitializations(mainBuffer); |
| + emitLazilyInitializedStaticFields(mainBuffer); |
| isolateProperties = isolatePropertiesName; |
| // The following code should not use the short-hand for the |