OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library js_backend.serialization; | 5 library js_backend.serialization; |
6 | 6 |
7 import '../common/backend_api.dart' show BackendSerialization; | 7 import '../common/backend_api.dart' show BackendSerialization; |
8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
9 import '../elements/resolution_types.dart'; | 9 import '../elements/resolution_types.dart'; |
10 import '../elements/types.dart'; | 10 import '../elements/types.dart'; |
(...skipping 16 matching lines...) Expand all Loading... |
27 const Key CODE_TEMPLATE = const Key('codeTemplate'); | 27 const Key CODE_TEMPLATE = const Key('codeTemplate'); |
28 const Key SIDE_EFFECTS = const Key('sideEffects'); | 28 const Key SIDE_EFFECTS = const Key('sideEffects'); |
29 const Key THROW_BEHAVIOR = const Key('throwBehavior'); | 29 const Key THROW_BEHAVIOR = const Key('throwBehavior'); |
30 const Key IS_ALLOCATION = const Key('isAllocation'); | 30 const Key IS_ALLOCATION = const Key('isAllocation'); |
31 const Key USE_GVN = const Key('useGvn'); | 31 const Key USE_GVN = const Key('useGvn'); |
32 | 32 |
33 class JavaScriptBackendSerialization implements BackendSerialization { | 33 class JavaScriptBackendSerialization implements BackendSerialization { |
34 final JavaScriptBackendSerializer serializer; | 34 final JavaScriptBackendSerializer serializer; |
35 final JavaScriptBackendDeserializer deserializer; | 35 final JavaScriptBackendDeserializer deserializer; |
36 | 36 |
37 JavaScriptBackendSerialization(NativeData nativeData) | 37 JavaScriptBackendSerialization( |
38 : serializer = new JavaScriptBackendSerializer(nativeData), | 38 NativeClassData nativeClassData, NativeData nativeData) |
39 deserializer = new JavaScriptBackendDeserializer(nativeData); | 39 : serializer = |
| 40 new JavaScriptBackendSerializer(nativeClassData, nativeData), |
| 41 deserializer = |
| 42 new JavaScriptBackendDeserializer(nativeClassData, nativeData); |
40 } | 43 } |
41 | 44 |
42 const Key JS_INTEROP_LIBRARY_NAME = const Key('jsInteropLibraryName'); | 45 const Key JS_INTEROP_LIBRARY_NAME = const Key('jsInteropLibraryName'); |
43 const Key JS_INTEROP_CLASS_NAME = const Key('jsInteropClassName'); | 46 const Key JS_INTEROP_CLASS_NAME = const Key('jsInteropClassName'); |
44 const Key JS_INTEROP_MEMBER_NAME = const Key('jsInteropMemberName'); | 47 const Key JS_INTEROP_MEMBER_NAME = const Key('jsInteropMemberName'); |
45 const Key NATIVE_MEMBER_NAME = const Key('nativeMemberName'); | 48 const Key NATIVE_MEMBER_NAME = const Key('nativeMemberName'); |
46 const Key NATIVE_CLASS_TAG_INFO = const Key('nativeClassTagInfo'); | 49 const Key NATIVE_CLASS_TAG_INFO = const Key('nativeClassTagInfo'); |
47 const Key NATIVE_METHOD_BEHAVIOR = const Key('nativeMethodBehavior'); | 50 const Key NATIVE_METHOD_BEHAVIOR = const Key('nativeMethodBehavior'); |
48 const Key NATIVE_FIELD_LOAD_BEHAVIOR = const Key('nativeFieldLoadBehavior'); | 51 const Key NATIVE_FIELD_LOAD_BEHAVIOR = const Key('nativeFieldLoadBehavior'); |
49 const Key NATIVE_FIELD_STORE_BEHAVIOR = const Key('nativeFieldStoreBehavior'); | 52 const Key NATIVE_FIELD_STORE_BEHAVIOR = const Key('nativeFieldStoreBehavior'); |
50 | 53 |
51 class JavaScriptBackendSerializer implements SerializerPlugin { | 54 class JavaScriptBackendSerializer implements SerializerPlugin { |
| 55 final NativeClassDataImpl nativeClassData; |
52 final NativeDataImpl nativeData; | 56 final NativeDataImpl nativeData; |
53 | 57 |
54 JavaScriptBackendSerializer(this.nativeData); | 58 JavaScriptBackendSerializer(this.nativeClassData, this.nativeData); |
55 | 59 |
56 @override | 60 @override |
57 void onElement(Element element, ObjectEncoder createEncoder(String tag)) { | 61 void onElement(Element element, ObjectEncoder createEncoder(String tag)) { |
58 ObjectEncoder encoder; | 62 ObjectEncoder encoder; |
59 ObjectEncoder getEncoder() { | 63 ObjectEncoder getEncoder() { |
60 return encoder ??= createEncoder(_BACKEND_DATA_TAG); | 64 return encoder ??= createEncoder(_BACKEND_DATA_TAG); |
61 } | 65 } |
62 | 66 |
63 String jsInteropLibraryName = nativeData.jsInteropLibraryNames[element]; | 67 String jsInteropLibraryName = nativeData.jsInteropLibraryNames[element]; |
64 if (jsInteropLibraryName != null) { | 68 if (jsInteropLibraryName != null) { |
65 getEncoder().setString(JS_INTEROP_LIBRARY_NAME, jsInteropLibraryName); | 69 getEncoder().setString(JS_INTEROP_LIBRARY_NAME, jsInteropLibraryName); |
66 } | 70 } |
67 String jsInteropClassName = nativeData.jsInteropClassNames[element]; | 71 String jsInteropClassName = nativeData.jsInteropClassNames[element]; |
68 if (jsInteropClassName != null) { | 72 if (jsInteropClassName != null) { |
69 getEncoder().setString(JS_INTEROP_CLASS_NAME, jsInteropClassName); | 73 getEncoder().setString(JS_INTEROP_CLASS_NAME, jsInteropClassName); |
70 } | 74 } |
71 String jsInteropMemberName = nativeData.jsInteropMemberNames[element]; | 75 String jsInteropMemberName = nativeData.jsInteropMemberNames[element]; |
72 if (jsInteropMemberName != null) { | 76 if (jsInteropMemberName != null) { |
73 getEncoder().setString(JS_INTEROP_MEMBER_NAME, jsInteropMemberName); | 77 getEncoder().setString(JS_INTEROP_MEMBER_NAME, jsInteropMemberName); |
74 } | 78 } |
75 String nativeMemberName = nativeData.nativeMemberName[element]; | 79 String nativeMemberName = nativeData.nativeMemberName[element]; |
76 if (nativeMemberName != null) { | 80 if (nativeMemberName != null) { |
77 getEncoder().setString(NATIVE_MEMBER_NAME, nativeMemberName); | 81 getEncoder().setString(NATIVE_MEMBER_NAME, nativeMemberName); |
78 } | 82 } |
79 String nativeClassTagInfo = nativeData.nativeClassTagInfo[element]; | 83 NativeClassTag nativeClassTagInfo = |
| 84 nativeClassData.nativeClassTagInfo[element]; |
80 if (nativeClassTagInfo != null) { | 85 if (nativeClassTagInfo != null) { |
81 getEncoder().setString(NATIVE_CLASS_TAG_INFO, nativeClassTagInfo); | 86 getEncoder().setString(NATIVE_CLASS_TAG_INFO, nativeClassTagInfo.text); |
82 } | 87 } |
83 NativeBehavior nativeMethodBehavior = | 88 NativeBehavior nativeMethodBehavior = |
84 nativeData.nativeMethodBehavior[element]; | 89 nativeData.nativeMethodBehavior[element]; |
85 if (nativeMethodBehavior != null) { | 90 if (nativeMethodBehavior != null) { |
86 NativeBehaviorSerialization.serializeNativeBehavior(nativeMethodBehavior, | 91 NativeBehaviorSerialization.serializeNativeBehavior(nativeMethodBehavior, |
87 getEncoder().createObject(NATIVE_METHOD_BEHAVIOR)); | 92 getEncoder().createObject(NATIVE_METHOD_BEHAVIOR)); |
88 } | 93 } |
89 NativeBehavior nativeFieldLoadBehavior = | 94 NativeBehavior nativeFieldLoadBehavior = |
90 nativeData.nativeFieldLoadBehavior[element]; | 95 nativeData.nativeFieldLoadBehavior[element]; |
91 if (nativeFieldLoadBehavior != null) { | 96 if (nativeFieldLoadBehavior != null) { |
(...skipping 10 matching lines...) Expand all Loading... |
102 } | 107 } |
103 } | 108 } |
104 | 109 |
105 @override | 110 @override |
106 void onData(NativeBehavior behavior, ObjectEncoder encoder) { | 111 void onData(NativeBehavior behavior, ObjectEncoder encoder) { |
107 NativeBehaviorSerialization.serializeNativeBehavior(behavior, encoder); | 112 NativeBehaviorSerialization.serializeNativeBehavior(behavior, encoder); |
108 } | 113 } |
109 } | 114 } |
110 | 115 |
111 class JavaScriptBackendDeserializer implements DeserializerPlugin { | 116 class JavaScriptBackendDeserializer implements DeserializerPlugin { |
| 117 final NativeClassDataImpl nativeClassData; |
112 final NativeDataImpl nativeData; | 118 final NativeDataImpl nativeData; |
113 | 119 |
114 JavaScriptBackendDeserializer(this.nativeData); | 120 JavaScriptBackendDeserializer(this.nativeClassData, this.nativeData); |
115 | 121 |
116 @override | 122 @override |
117 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { | 123 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { |
118 ObjectDecoder decoder = getDecoder(_BACKEND_DATA_TAG); | 124 ObjectDecoder decoder = getDecoder(_BACKEND_DATA_TAG); |
119 if (decoder != null) { | 125 if (decoder != null) { |
120 if (element is LibraryElement) { | 126 if (element is LibraryElement) { |
121 String jsInteropLibraryName = | 127 String jsInteropLibraryName = |
122 decoder.getString(JS_INTEROP_LIBRARY_NAME, isOptional: true); | 128 decoder.getString(JS_INTEROP_LIBRARY_NAME, isOptional: true); |
123 if (jsInteropLibraryName != null) { | 129 if (jsInteropLibraryName != null) { |
124 nativeData.jsInteropLibraryNames[element] = jsInteropLibraryName; | 130 nativeData.jsInteropLibraryNames[element] = jsInteropLibraryName; |
125 } | 131 } |
126 } else if (element is ClassElement) { | 132 } else if (element is ClassElement) { |
127 String jsInteropClassName = | 133 String jsInteropClassName = |
128 decoder.getString(JS_INTEROP_CLASS_NAME, isOptional: true); | 134 decoder.getString(JS_INTEROP_CLASS_NAME, isOptional: true); |
129 if (jsInteropClassName != null) { | 135 if (jsInteropClassName != null) { |
130 nativeData.jsInteropClassNames[element] = jsInteropClassName; | 136 nativeData.jsInteropClassNames[element] = jsInteropClassName; |
131 } | 137 } |
132 String nativeClassTagInfo = | 138 String nativeClassTagInfo = |
133 decoder.getString(NATIVE_CLASS_TAG_INFO, isOptional: true); | 139 decoder.getString(NATIVE_CLASS_TAG_INFO, isOptional: true); |
134 if (nativeClassTagInfo != null) { | 140 if (nativeClassTagInfo != null) { |
135 nativeData.nativeClassTagInfo[element] = nativeClassTagInfo; | 141 nativeClassData.nativeClassTagInfo[element] = |
| 142 new NativeClassTag(nativeClassTagInfo); |
136 } | 143 } |
137 } else if (element is MemberElement) { | 144 } else if (element is MemberElement) { |
138 String jsInteropMemberName = | 145 String jsInteropMemberName = |
139 decoder.getString(JS_INTEROP_MEMBER_NAME, isOptional: true); | 146 decoder.getString(JS_INTEROP_MEMBER_NAME, isOptional: true); |
140 if (jsInteropMemberName != null) { | 147 if (jsInteropMemberName != null) { |
141 nativeData.jsInteropMemberNames[element] = jsInteropMemberName; | 148 nativeData.jsInteropMemberNames[element] = jsInteropMemberName; |
142 } | 149 } |
143 String nativeMemberName = | 150 String nativeMemberName = |
144 decoder.getString(NATIVE_MEMBER_NAME, isOptional: true); | 151 decoder.getString(NATIVE_MEMBER_NAME, isOptional: true); |
145 if (nativeMemberName != null) { | 152 if (nativeMemberName != null) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 behavior.codeTemplate = js.js.parseForeignJS(behavior.codeTemplateText); | 286 behavior.codeTemplate = js.js.parseForeignJS(behavior.codeTemplateText); |
280 } | 287 } |
281 | 288 |
282 behavior.throwBehavior = | 289 behavior.throwBehavior = |
283 decoder.getEnum(THROW_BEHAVIOR, NativeThrowBehavior.values); | 290 decoder.getEnum(THROW_BEHAVIOR, NativeThrowBehavior.values); |
284 behavior.isAllocation = decoder.getBool(IS_ALLOCATION); | 291 behavior.isAllocation = decoder.getBool(IS_ALLOCATION); |
285 behavior.useGvn = decoder.getBool(USE_GVN); | 292 behavior.useGvn = decoder.getBool(USE_GVN); |
286 return behavior; | 293 return behavior; |
287 } | 294 } |
288 } | 295 } |
OLD | NEW |