Index: sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart b/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
index ada5b1b0c76e21f08e063e362536f3efa975b075..017f3bec3f313dbd7b9a5685be64fde9a8cb8328 100644 |
--- a/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
@@ -709,6 +709,25 @@ class Namer implements ClosureNamer { |
String operatorAsPrefix() => r'$as'; |
+ String operatorSignature() => r'$signature'; |
+ |
+ Map<FunctionType,String> functionTypeNameMap = new Map<FunctionType,String>(); |
+ FunctionTypeNamer functionTypeNamer = new FunctionTypeNamer(); |
+ |
+ String getFunctionTypeName(FunctionType functionType) { |
+ return functionTypeNameMap.putIfAbsent(functionType, () { |
+ String proposedName = functionTypeNamer.computeName(functionType); |
+ String freshName = getFreshName(proposedName, usedInstanceNames, |
+ suggestedInstanceNames, ensureSafe: true); |
+ return freshName; |
+ }); |
+ } |
+ |
+ String operatorIsFunctionType(FunctionType type) { |
+ // TODO(erikcorry): Reduce from $isx to ix when we are minifying. |
+ return '${operatorIsPrefix()}${getFunctionTypeName(type)}'; |
+ } |
+ |
String operatorIs(Element element) { |
// TODO(erikcorry): Reduce from $isx to ix when we are minifying. |
return '${operatorIsPrefix()}${getName(element)}'; |
@@ -730,6 +749,16 @@ class Namer implements ClosureNamer { |
return '${operatorAsPrefix()}${getName(element)}'; |
} |
+ String signatureName(FunctionType type) { |
+ ClassElement classElement = Types.getClassContext(type); |
+ String signature = '${operatorSignature()}_${getFunctionTypeName(type)}'; |
+ if (classElement != null) { |
+ return '${isolateAccess(classElement)}.$signature'; |
+ } else { |
+ return '${CURRENT_ISOLATE}.$signature'; |
+ } |
+ } |
+ |
String safeName(String name) => _safeName(name, jsReserved); |
String safeVariableName(String name) => _safeName(name, jsVariableReserved); |
@@ -783,3 +812,47 @@ class Namer implements ClosureNamer { |
} |
} |
} |
+ |
+class FunctionTypeNamer extends DartTypeVisitor { |
+ StringBuffer sb; |
+ |
+ String computeName(DartType type) { |
+ sb = new StringBuffer(); |
+ visit(type); |
+ return sb.toString(); |
+ } |
+ |
+ visit(DartType type) { |
+ type.accept(this, null); |
+ } |
+ |
+ visitType(DartType type, _) { |
+ sb.write(type.name.slowToString()); |
+ } |
+ |
+ visitFunctionType(FunctionType type, _) { |
+ visit(type.returnType); |
+ sb.write('_'); |
+ for (Link<DartType> link = type.parameterTypes; |
+ !link.isEmpty; |
+ link = link.tail) { |
+ sb.write('_'); |
+ visit(link.head); |
+ } |
+ for (Link<DartType> link = type.optionalParameterTypes; |
+ !link.isEmpty; |
+ link = link.tail) { |
+ sb.write('_'); |
+ visit(link.head); |
+ } |
+ if (!type.namedParameterTypes.isEmpty) { |
+ for (Link<DartType> link = type.namedParameterTypes; |
+ !link.isEmpty; |
+ link = link.tail) { |
+ sb.write('_'); |
+ visit(link.head); |
+ } |
+ } |
+ } |
+ |
+} |