Index: pkg/compiler/lib/src/js_backend/backend_serialization.dart |
diff --git a/pkg/compiler/lib/src/js_backend/backend_serialization.dart b/pkg/compiler/lib/src/js_backend/backend_serialization.dart |
index 97da2f5a2d2a8cf30bfbbe5acaca1a35511243f3..471456cbce6ba48865a1a56ca0a0fb5373bae3c9 100644 |
--- a/pkg/compiler/lib/src/js_backend/backend_serialization.dart |
+++ b/pkg/compiler/lib/src/js_backend/backend_serialization.dart |
@@ -18,8 +18,10 @@ import 'js_backend.dart'; |
const String _BACKEND_DATA_TAG = 'jsBackendData'; |
const Key DART_TYPES_RETURNED = const Key('dartTypesReturned'); |
+const Key THIS_TYPES_RETURNED = const Key('thisTypesReturned'); |
const Key SPECIAL_TYPES_RETURNED = const Key('specialTypesReturned'); |
const Key DART_TYPES_INSTANTIATED = const Key('dartTypesInstantiated'); |
+const Key THIS_TYPES_INSTANTIATED = const Key('thisTypesInstantiated'); |
const Key SPECIAL_TYPES_INSTANTIATED = const Key('specialTypesInstantiated'); |
const Key CODE_TEMPLATE = const Key('codeTemplate'); |
const Key SIDE_EFFECTS = const Key('sideEffects'); |
@@ -150,15 +152,43 @@ class JavaScriptBackendDeserializer implements DeserializerPlugin { |
} |
class NativeBehaviorSerialization { |
- /// Returns a list of the [DartType]s in [types]. |
+ static const int NORMAL_TYPE = 0; |
+ static const int THIS_TYPE = 1; |
+ static const int SPECIAL_TYPE = 2; |
+ |
+ static int getTypeKind(var type) { |
+ if (type is DartType) { |
+ // TODO(johnniwinther): Remove this when annotation are no longer resolved |
+ // to this-types. |
+ if (type is GenericType && |
+ type.isGeneric && |
+ type == type.element.thisType) { |
+ return THIS_TYPE; |
+ } |
+ return NORMAL_TYPE; |
+ } |
+ return SPECIAL_TYPE; |
+ } |
+ |
+ /// Returns a list of the non-this-type [DartType]s in [types]. |
static List<DartType> filterDartTypes(List types) { |
- return types.where((type) => type is DartType).toList(); |
+ return types.where((type) => getTypeKind(type) == NORMAL_TYPE).toList(); |
+ } |
+ |
+ // TODO(johnniwinther): Remove this when annotation are no longer resolved |
+ // to this-types. |
+ /// Returns a list of the classes of this-types in [types]. |
+ static List<Element> filterThisTypes(List types) { |
+ return types |
+ .where((type) => getTypeKind(type) == THIS_TYPE) |
+ .map((type) => type.element) |
+ .toList(); |
} |
/// Returns a list of the names of the [SpecialType]s in [types]. |
static List<String> filterSpecialTypes(List types) { |
return types |
- .where((type) => type is SpecialType) |
+ .where((type) => getTypeKind(type) == SPECIAL_TYPE) |
.map((SpecialType type) => type.name) |
.toList(); |
} |
@@ -167,11 +197,15 @@ class NativeBehaviorSerialization { |
NativeBehavior behavior, ObjectEncoder encoder) { |
encoder.setTypes( |
DART_TYPES_RETURNED, filterDartTypes(behavior.typesReturned)); |
+ encoder.setElements( |
+ THIS_TYPES_RETURNED, filterThisTypes(behavior.typesReturned)); |
encoder.setStrings( |
SPECIAL_TYPES_RETURNED, filterSpecialTypes(behavior.typesReturned)); |
encoder.setTypes( |
DART_TYPES_INSTANTIATED, filterDartTypes(behavior.typesInstantiated)); |
+ encoder.setElements( |
+ THIS_TYPES_INSTANTIATED, filterThisTypes(behavior.typesInstantiated)); |
encoder.setStrings(SPECIAL_TYPES_INSTANTIATED, |
filterSpecialTypes(behavior.typesInstantiated)); |
@@ -193,12 +227,20 @@ class NativeBehaviorSerialization { |
behavior.typesReturned |
.addAll(decoder.getTypes(DART_TYPES_RETURNED, isOptional: true)); |
behavior.typesReturned.addAll(decoder |
+ .getElements(THIS_TYPES_RETURNED, isOptional: true) |
+ .map((element) => element.thisType) |
+ .toList()); |
+ behavior.typesReturned.addAll(decoder |
.getStrings(SPECIAL_TYPES_RETURNED, isOptional: true) |
.map(SpecialType.fromName)); |
behavior.typesInstantiated |
.addAll(decoder.getTypes(DART_TYPES_INSTANTIATED, isOptional: true)); |
behavior.typesInstantiated.addAll(decoder |
+ .getElements(THIS_TYPES_INSTANTIATED, isOptional: true) |
+ .map((element) => element.thisType) |
+ .toList()); |
+ behavior.typesInstantiated.addAll(decoder |
.getStrings(SPECIAL_TYPES_INSTANTIATED, isOptional: true) |
.map(SpecialType.fromName)); |