Chromium Code Reviews| Index: pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart |
| diff --git a/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart b/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart |
| index b16379f5465ca7a8aa2e072146d7a0ab08a2734e..00e187dcc5bd94db0a6b65fa85cca21c6ebd691f 100644 |
| --- a/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart |
| +++ b/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart |
| @@ -674,13 +674,12 @@ class Emitter implements js_emitter.Emitter { |
| return new jsAst.Block(parts); |
| } |
| - jsAst.Statement buildLazilyInitializedStaticFields() { |
| - JavaScriptConstantCompiler handler = backend.constants; |
| - List<VariableElement> lazyFields = |
| - handler.getLazilyInitializedFieldsForEmission(); |
| + jsAst.Statement buildLazilyInitializedStaticFields(Fragment fragment) { |
| + List<StaticField> lazyFields = fragment.staticLazilyInitializedFields; |
| if (lazyFields.isNotEmpty) { |
| needsLazyInitializer = true; |
| - List<jsAst.Expression> laziesInfo = buildLaziesInfo(lazyFields); |
| + List<jsAst.Expression> laziesInfo = |
| + buildLaziesInfo(lazyFields, fragment.isMainFragment); |
| return js.statement(''' |
| (function(lazies) { |
| for (var i = 0; i < lazies.length; ) { |
| @@ -690,40 +689,51 @@ class Emitter implements js_emitter.Emitter { |
| var staticName = lazies[i++]; |
| } |
| var lazyValue = lazies[i++]; |
| - |
| + if (#isDeferredFragment) { |
| + var fieldHolder = lazies[i++]; |
| + } |
| // We build the lazy-check here: |
| // lazyInitializer(fieldName, getterName, lazyValue, staticName); |
| // 'staticName' is used for error reporting in non-minified mode. |
| // 'lazyValue' must be a closure that constructs the initial value. |
| - if (#notMinified) { |
| - #lazy(fieldName, getterName, lazyValue, staticName); |
| + if (#isMainFragment) { |
|
floitsch
2016/01/12 13:38:38
Do we do the right thing for "if / else" when the
Harry Terkelsen
2016/01/12 18:37:52
From examining the output, it looks like it is doi
|
| + if (#notMinified) { |
| + #lazy(fieldName, getterName, lazyValue, staticName); |
| + } else { |
| + #lazy(fieldName, getterName, lazyValue); |
| + } |
| } else { |
| - #lazy(fieldName, getterName, lazyValue); |
| + if (#notMinified) { |
|
floitsch
2016/01/12 13:38:38
ditto.
Harry Terkelsen
2016/01/12 18:37:52
Done.
|
| + #lazy(fieldName, getterName, lazyValue, staticName, fieldHolder); |
| + } else { |
| + #lazy(fieldName, getterName, lazyValue, null, fieldHolder); |
| + } |
| } |
| } |
| })(#laziesInfo) |
| ''', {'notMinified': !compiler.enableMinification, |
| 'laziesInfo': new jsAst.ArrayInitializer(laziesInfo), |
| - 'lazy': js(lazyInitializerName)}); |
| + 'lazy': js(lazyInitializerName), |
| + 'isMainFragment': fragment.isMainFragment, |
| + 'isDeferredFragment': !fragment.isMainFragment}); |
| } else { |
| return js.comment("No lazy statics."); |
| } |
| } |
| - List<jsAst.Expression> buildLaziesInfo(List<VariableElement> lazies) { |
| + List<jsAst.Expression> buildLaziesInfo( |
| + List<StaticField> lazies, bool isMainFragment) { |
| List<jsAst.Expression> laziesInfo = <jsAst.Expression>[]; |
| - for (VariableElement element in Elements.sortedByPosition(lazies)) { |
| - jsAst.Expression code = backend.generatedCode[element]; |
| - // The code is null if we ended up not needing the lazily |
| - // initialized field after all because of constant folding |
| - // before code generation. |
| - if (code == null) continue; |
| - laziesInfo.add(js.quoteName(namer.globalPropertyName(element))); |
| - laziesInfo.add(js.quoteName(namer.lazyInitializerName(element))); |
| + for (StaticField field in lazies) { |
|
floitsch
2016/01/12 13:38:38
Why don't you sort by position anymore?
Harry Terkelsen
2016/01/12 18:37:52
fragment.staticLazilyInitializedFields is already
|
| + laziesInfo.add(js.quoteName(field.name)); |
| + laziesInfo.add(js.quoteName(namer.deriveLazyInitializerName(field.name))); |
| if (!compiler.enableMinification) { |
|
floitsch
2016/01/12 13:38:38
maybe move the optional minification next to the o
Harry Terkelsen
2016/01/12 18:37:52
Done.
|
| - laziesInfo.add(js.string(element.name)); |
| + laziesInfo.add(js.quoteName(field.name)); |
| + } |
| + laziesInfo.add(field.code); |
| + if (!isMainFragment) { |
| + laziesInfo.add(js('#', field.holder.name)); |
|
floitsch
2016/01/12 13:38:38
I believe that the field.holder.name will always b
Harry Terkelsen
2016/01/12 18:37:52
I think you're right. I considered doing 'namer.st
|
| } |
| - laziesInfo.add(code); |
| } |
| return laziesInfo; |
| } |
| @@ -1570,7 +1580,7 @@ class Emitter implements js_emitter.Emitter { |
| mainOutputUnit), |
| "typeToInterceptorMap": |
| interceptorEmitter.buildTypeToInterceptorMap(program), |
| - "lazyStaticFields": buildLazilyInitializedStaticFields(), |
| + "lazyStaticFields": buildLazilyInitializedStaticFields(mainFragment), |
|
floitsch
2016/01/12 13:38:38
I'm ok with this, but I prefer, when we only send
Harry Terkelsen
2016/01/12 18:37:52
Done.
|
| "metadata": buildMetadata(program, mainOutputUnit), |
| "convertToFastObject": buildConvertToFastObjectFunction(), |
| "convertToSlowObject": buildConvertToSlowObjectFunction(), |
| @@ -1996,6 +2006,7 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| body.add(buildCompileTimeConstants(fragment.constants, |
| isMainFragment: false)); |
| body.add(buildStaticNonFinalFieldInitializations(outputUnit)); |
| + body.add(buildLazilyInitializedStaticFields(fragment)); |
| List<jsAst.Statement> statements = <jsAst.Statement>[]; |