Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart |
| index 2b4d152cf5b7a733fdfe80a5d18f9694c3b4fa97..f9228ba73f546ae7e6121db4acdd0c55749531cf 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart |
| @@ -209,11 +209,12 @@ class ConstantInitializerEmitter implements ConstantVisitor<jsAst.Expression> { |
| } |
| jsAst.Expression visitList(ListConstant constant) { |
| - return new jsAst.Call( |
| + jsAst.Expression value = new jsAst.Call( |
| new jsAst.PropertyAccess.field( |
| new jsAst.VariableUse(namer.isolateName), |
| 'makeConstantList'), |
| [new jsAst.ArrayInitializer.from(_array(constant.entries))]); |
| + return maybeAddTypeArguments(constant.type, value); |
| } |
| String getJsConstructor(ClassElement element) { |
| @@ -276,23 +277,27 @@ class ConstantInitializerEmitter implements ConstantVisitor<jsAst.Expression> { |
| badFieldCountError(); |
| } |
| - return new jsAst.New( |
| + jsAst.Expression value = new jsAst.New( |
| new jsAst.VariableUse(getJsConstructor(classElement)), |
| arguments); |
| + return maybeAddTypeArguments(constant.type, value); |
| } |
| - jsAst.Expression visitType(TypeConstant constant) { |
| - JavaScriptBackend backend = compiler.backend; |
| - Element helper = backend.getCreateRuntimeType(); |
| + JavaScriptBackend get backend => compiler.backend; |
| + |
| + jsAst.PropertyAccess getHelperProperty(Element helper) { |
| String helperName = backend.namer.getName(helper); |
| + return new jsAst.PropertyAccess.field( |
| + new jsAst.VariableUse(namer.CURRENT_ISOLATE), |
| + helperName); |
| + } |
| + |
| + jsAst.Expression visitType(TypeConstant constant) { |
| DartType type = constant.representedType; |
| String name = namer.getRuntimeTypeName(type.element); |
| jsAst.Expression typeName = new jsAst.LiteralString("'$name'"); |
| - return new jsAst.Call( |
| - new jsAst.PropertyAccess.field( |
| - new jsAst.VariableUse(namer.CURRENT_ISOLATE), |
| - helperName), |
| - [typeName]); |
| + return new jsAst.Call(getHelperProperty(backend.getCreateRuntimeType()), |
| + [typeName]); |
| } |
| jsAst.Expression visitInterceptor(InterceptorConstant constant) { |
| @@ -303,9 +308,10 @@ class ConstantInitializerEmitter implements ConstantVisitor<jsAst.Expression> { |
| } |
| jsAst.Expression visitConstructed(ConstructedConstant constant) { |
| - return new jsAst.New( |
| + jsAst.New instantiation = new jsAst.New( |
| new jsAst.VariableUse(getJsConstructor(constant.type.element)), |
| _array(constant.fields)); |
| + return maybeAddTypeArguments(constant.type, instantiation); |
| } |
| List<jsAst.Expression> _array(List<Constant> values) { |
| @@ -315,4 +321,21 @@ class ConstantInitializerEmitter implements ConstantVisitor<jsAst.Expression> { |
| } |
| return valueList; |
| } |
| + |
| + jsAst.Expression maybeAddTypeArguments(InterfaceType type, |
| + jsAst.Expression value) { |
| + if (type is! InterfaceType || type.isRaw) { |
| + return value; |
| + } else { |
|
ngeoffray
2013/06/17 09:15:03
Same comment as in compile_time_constants: you don
karlklose
2013/06/19 15:29:05
Done.
|
| + InterfaceType interface = type; |
| + RuntimeTypes rti = backend.rti; |
| + Iterable<String> arguments = interface.typeArguments |
| + .toList(growable: false) |
| + .map((DartType type) => rti.getTypeRepresentation(type, (_){})); |
| + jsAst.Expression argumentList = |
| + new jsAst.LiteralString('[${arguments.join(', ')}]'); |
| + return new jsAst.Call(getHelperProperty(backend.getSetRuntimeTypeInfo()), |
| + [value, argumentList]); |
| + } |
| + } |
| } |