| 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 c7c20395b55f8fc850a618043f6120d6da6e1732..ddd5c507ed898e0f403fb7e56be11724f735fdf4 100644
|
| --- a/pkg/compiler/lib/src/js_backend/backend_serialization.dart
|
| +++ b/pkg/compiler/lib/src/js_backend/backend_serialization.dart
|
| @@ -5,13 +5,26 @@
|
| library js_backend.serialization;
|
|
|
| import '../common/backend_api.dart' show BackendSerialization;
|
| +import '../dart_types.dart';
|
| import '../elements/elements.dart';
|
| +import '../js/js.dart' as js;
|
| +import '../native/native.dart';
|
| import '../serialization/serialization.dart'
|
| show DeserializerPlugin, ObjectDecoder, ObjectEncoder, SerializerPlugin;
|
| import '../serialization/keys.dart';
|
| +import '../universe/side_effects.dart';
|
| import 'js_backend.dart';
|
|
|
| const String _BACKEND_DATA_TAG = 'jsBackendData';
|
| +const Key DART_TYPES_RETURNED = const Key('dartTypesReturned');
|
| +const Key SPECIAL_TYPES_RETURNED = const Key('specialTypesReturned');
|
| +const Key DART_TYPES_INSTANTIATED = const Key('dartTypesInstantiated');
|
| +const Key SPECIAL_TYPES_INSTANTIATED = const Key('specialTypesInstantiated');
|
| +const Key CODE_TEMPLATE = const Key('codeTemplate');
|
| +const Key SIDE_EFFECTS = const Key('sideEffects');
|
| +const Key THROW_BEHAVIOR = const Key('throwBehavior');
|
| +const Key IS_ALLOCATION = const Key('isAllocation');
|
| +const Key USE_GVN = const Key('useGvn');
|
|
|
| class JavaScriptBackendSerialization implements BackendSerialization {
|
| final JavaScriptBackendSerializer serializer;
|
| @@ -37,6 +50,41 @@ class JavaScriptBackendSerializer implements SerializerPlugin {
|
| encoder.setString(Key.NAME, nativeName);
|
| }
|
| }
|
| +
|
| + /// Returns a list of the [DartType]s in [types].
|
| + static List<DartType> filterDartTypes(List types) {
|
| + return types.where((type) => type is DartType).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)
|
| + .map((SpecialType type) => type.name)
|
| + .toList();
|
| + }
|
| +
|
| + @override
|
| + void onData(NativeBehavior behavior, ObjectEncoder encoder) {
|
| + encoder.setTypes(
|
| + DART_TYPES_RETURNED, filterDartTypes(behavior.typesReturned));
|
| + encoder.setStrings(
|
| + SPECIAL_TYPES_RETURNED, filterSpecialTypes(behavior.typesReturned));
|
| +
|
| + encoder.setTypes(
|
| + DART_TYPES_INSTANTIATED, filterDartTypes(behavior.typesInstantiated));
|
| + encoder.setStrings(SPECIAL_TYPES_INSTANTIATED,
|
| + filterSpecialTypes(behavior.typesInstantiated));
|
| +
|
| + if (behavior.codeTemplateText != null) {
|
| + encoder.setString(CODE_TEMPLATE, behavior.codeTemplateText);
|
| + }
|
| +
|
| + encoder.setInt(SIDE_EFFECTS, behavior.sideEffects.flags);
|
| + encoder.setEnum(THROW_BEHAVIOR, behavior.throwBehavior);
|
| + encoder.setBool(IS_ALLOCATION, behavior.isAllocation);
|
| + encoder.setBool(USE_GVN, behavior.useGvn);
|
| + }
|
| }
|
|
|
| class JavaScriptBackendDeserializer implements DeserializerPlugin {
|
| @@ -52,4 +100,35 @@ class JavaScriptBackendDeserializer implements DeserializerPlugin {
|
| backend.nativeData.nativeMemberName[element] = nativeName;
|
| }
|
| }
|
| +
|
| + @override
|
| + NativeBehavior onData(ObjectDecoder decoder) {
|
| + SideEffects sideEffects =
|
| + new SideEffects.fromFlags(decoder.getInt(SIDE_EFFECTS));
|
| + NativeBehavior behavior = new NativeBehavior.internal(sideEffects);
|
| +
|
| + behavior.typesReturned
|
| + .addAll(decoder.getTypes(DART_TYPES_RETURNED, isOptional: true));
|
| + behavior.typesReturned.addAll(decoder
|
| + .getStrings(SPECIAL_TYPES_RETURNED, isOptional: true)
|
| + .map(SpecialType.fromName));
|
| +
|
| + behavior.typesReturned
|
| + .addAll(decoder.getTypes(DART_TYPES_INSTANTIATED, isOptional: true));
|
| + behavior.typesReturned.addAll(decoder
|
| + .getStrings(SPECIAL_TYPES_INSTANTIATED, isOptional: true)
|
| + .map(SpecialType.fromName));
|
| +
|
| + behavior.codeTemplateText =
|
| + decoder.getString(CODE_TEMPLATE, isOptional: true);
|
| + if (behavior.codeTemplateText != null) {
|
| + behavior.codeTemplate = js.js.parseForeignJS(behavior.codeTemplateText);
|
| + }
|
| +
|
| + behavior.throwBehavior =
|
| + decoder.getEnum(THROW_BEHAVIOR, NativeThrowBehavior.values);
|
| + behavior.isAllocation = decoder.getBool(IS_ALLOCATION);
|
| + behavior.useGvn = decoder.getBool(USE_GVN);
|
| + return behavior;
|
| + }
|
| }
|
|
|