| Index: sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart b/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
|
| index f46526766fe5542a8136f4a43091a28d6ddf4522..cb4e509d5d91e9510b4699cb491457e946fd8441 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/js_backend/runtime_types.dart
|
| @@ -13,6 +13,7 @@ abstract class TypeChecks {
|
| }
|
|
|
| typedef jsAst.Expression OnVariableCallback(TypeVariableType variable);
|
| +typedef bool ShouldEncodeTypedefCallback(TypedefType variable);
|
|
|
| class RuntimeTypes {
|
| final Compiler compiler;
|
| @@ -560,9 +561,12 @@ class RuntimeTypes {
|
| return jsAst.prettyPrint(representation, compiler).buffer.toString();
|
| }
|
|
|
| - jsAst.Expression getTypeRepresentation(DartType type,
|
| - OnVariableCallback onVariable) {
|
| - return representationGenerator.getTypeRepresentation(type, onVariable);
|
| + jsAst.Expression getTypeRepresentation(
|
| + DartType type,
|
| + OnVariableCallback onVariable,
|
| + [ShouldEncodeTypedefCallback shouldEncodeTypedef]) {
|
| + return representationGenerator.getTypeRepresentation(
|
| + type, onVariable, shouldEncodeTypedef);
|
| }
|
|
|
| bool isSimpleFunctionType(FunctionType type) {
|
| @@ -606,6 +610,7 @@ class RuntimeTypes {
|
| class TypeRepresentationGenerator extends DartTypeVisitor {
|
| final Compiler compiler;
|
| OnVariableCallback onVariable;
|
| + ShouldEncodeTypedefCallback shouldEncodeTypedef;
|
|
|
| JavaScriptBackend get backend => compiler.backend;
|
| Namer get namer => backend.namer;
|
| @@ -616,11 +621,16 @@ class TypeRepresentationGenerator extends DartTypeVisitor {
|
| * Creates a type representation for [type]. [onVariable] is called to provide
|
| * the type representation for type variables.
|
| */
|
| - jsAst.Expression getTypeRepresentation(DartType type,
|
| - OnVariableCallback onVariable) {
|
| + jsAst.Expression getTypeRepresentation(
|
| + DartType type,
|
| + OnVariableCallback onVariable,
|
| + ShouldEncodeTypedefCallback encodeTypedef) {
|
| this.onVariable = onVariable;
|
| + this.shouldEncodeTypedef =
|
| + (encodeTypedef != null) ? encodeTypedef : (TypedefType type) => false;
|
| jsAst.Expression representation = visit(type);
|
| this.onVariable = null;
|
| + this.shouldEncodeTypedef = null;
|
| return representation;
|
| }
|
|
|
| @@ -629,7 +639,7 @@ class TypeRepresentationGenerator extends DartTypeVisitor {
|
| }
|
|
|
| visit(DartType type) {
|
| - return type.unalias(compiler).accept(this, null);
|
| + return type.accept(this, null);
|
| }
|
|
|
| visitTypeVariableType(TypeVariableType type, _) {
|
| @@ -705,6 +715,25 @@ class TypeRepresentationGenerator extends DartTypeVisitor {
|
| return js('null');
|
| }
|
|
|
| + visitTypedefType(TypedefType type, _) {
|
| + bool shouldEncode = shouldEncodeTypedef(type);
|
| + DartType unaliasedType = type.unalias(compiler);
|
| + if (shouldEncode) {
|
| + jsAst.ObjectInitializer initializer = unaliasedType.accept(this, null);
|
| + // We have to encode the aliased type.
|
| + jsAst.Expression name = getJavaScriptClassName(type.element);
|
| + jsAst.Expression encodedTypedef =
|
| + type.treatAsRaw ? name : visitList(type.typeArguments, head: name);
|
| +
|
| + // Add it to the function-type object.
|
| + jsAst.LiteralString tag = js.string(namer.typedefTag());
|
| + initializer.properties.add(new jsAst.Property(tag, encodedTypedef));
|
| + return initializer;
|
| + } else {
|
| + return unaliasedType.accept(this, null);
|
| + }
|
| + }
|
| +
|
| visitType(DartType type, _) {
|
| compiler.internalError(NO_LOCATION_SPANNABLE,
|
| 'Unexpected type: $type (${type.kind}).');
|
|
|