| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart2js.serialization_analysis_test; | 5 library dart2js.serialization_analysis_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 import 'package:compiler/src/commandline_options.dart'; | 10 import 'package:compiler/src/commandline_options.dart'; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 Future analyze(String serializedData, Uri entryPoint, Test test) async { | 236 Future analyze(String serializedData, Uri entryPoint, Test test) async { |
| 237 DiagnosticCollector diagnosticCollector = new DiagnosticCollector(); | 237 DiagnosticCollector diagnosticCollector = new DiagnosticCollector(); |
| 238 await runCompiler( | 238 await runCompiler( |
| 239 entryPoint: entryPoint, | 239 entryPoint: entryPoint, |
| 240 memorySourceFiles: test != null ? test.sourceFiles : const {}, | 240 memorySourceFiles: test != null ? test.sourceFiles : const {}, |
| 241 options: [Flags.analyzeOnly], | 241 options: [Flags.analyzeOnly], |
| 242 diagnosticHandler: diagnosticCollector, | 242 diagnosticHandler: diagnosticCollector, |
| 243 beforeRun: (Compiler compiler) { | 243 beforeRun: (Compiler compiler) { |
| 244 Deserializer deserializer = new Deserializer.fromText( | 244 Deserializer deserializer = new Deserializer.fromText( |
| 245 new DeserializationContext(), |
| 245 serializedData, | 246 serializedData, |
| 246 const JsonSerializationDecoder()); | 247 const JsonSerializationDecoder()); |
| 247 deserializer.plugins.add(compiler.backend.serialization.deserializer); | 248 deserializer.plugins.add(compiler.backend.serialization.deserializer); |
| 248 compiler.serialization.deserializer = | 249 compiler.serialization.deserializer = |
| 249 new _DeserializerSystem(deserializer); | 250 new _DeserializerSystem(deserializer); |
| 250 }); | 251 }); |
| 251 if (test != null) { | 252 if (test != null) { |
| 252 Expect.equals(test.expectedErrorCount, diagnosticCollector.errors.length, | 253 Expect.equals(test.expectedErrorCount, diagnosticCollector.errors.length, |
| 253 "Unexpected error count."); | 254 "Unexpected error count."); |
| 254 Expect.equals( | 255 Expect.equals( |
| 255 test.expectedWarningCount, | 256 test.expectedWarningCount, |
| 256 diagnosticCollector.warnings.length, | 257 diagnosticCollector.warnings.length, |
| 257 "Unexpected warning count."); | 258 "Unexpected warning count."); |
| 258 Expect.equals(test.expectedHintCount, diagnosticCollector.hints.length, | 259 Expect.equals(test.expectedHintCount, diagnosticCollector.hints.length, |
| 259 "Unexpected hint count."); | 260 "Unexpected hint count."); |
| 260 Expect.equals(test.expectedInfoCount, diagnosticCollector.infos.length, | 261 Expect.equals(test.expectedInfoCount, diagnosticCollector.infos.length, |
| 261 "Unexpected info count."); | 262 "Unexpected info count."); |
| 262 } | 263 } |
| 263 } | 264 } |
| 264 | 265 |
| 265 Future<String> serializeDartCore() async { | 266 Future<String> serializeDartCore() async { |
| 266 Compiler compiler = compilerFor( | 267 Compiler compiler = compilerFor( |
| 267 options: [Flags.analyzeAll]); | 268 options: [Flags.analyzeAll]); |
| 268 compiler.serialization.supportSerialization = true; | 269 compiler.serialization.supportSerialization = true; |
| 269 await compiler.run(Uris.dart_core); | 270 await compiler.run(Uris.dart_core); |
| 270 return serialize(compiler); | 271 return serialize(compiler); |
| 271 } | 272 } |
| 272 | 273 |
| 273 String serialize(Compiler compiler) { | 274 String serialize(Compiler compiler) { |
| 274 Serializer serializer = new Serializer(const JsonSerializationEncoder()); | 275 Serializer serializer = new Serializer(); |
| 275 serializer.plugins.add(compiler.backend.serialization.serializer); | 276 serializer.plugins.add(compiler.backend.serialization.serializer); |
| 276 serializer.plugins.add(new WorldImpactSerializer(compiler.resolution)); | 277 serializer.plugins.add(new WorldImpactSerializer(compiler.resolution)); |
| 277 | 278 |
| 278 for (LibraryElement library in compiler.libraryLoader.libraries) { | 279 for (LibraryElement library in compiler.libraryLoader.libraries) { |
| 279 serializer.serialize(library); | 280 serializer.serialize(library); |
| 280 } | 281 } |
| 281 return serializer.toText(); | 282 return serializer.toText(const JsonSerializationEncoder()); |
| 282 } | 283 } |
| 283 | 284 |
| 284 const String WORLD_IMPACT_TAG = 'worldImpact'; | 285 const String WORLD_IMPACT_TAG = 'worldImpact'; |
| 285 | 286 |
| 286 class WorldImpactSerializer extends SerializerPlugin { | 287 class WorldImpactSerializer extends SerializerPlugin { |
| 287 final Resolution resolution; | 288 final Resolution resolution; |
| 288 | 289 |
| 289 WorldImpactSerializer(this.resolution); | 290 WorldImpactSerializer(this.resolution); |
| 290 | 291 |
| 291 @override | 292 @override |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 impact = const WorldImpact(); | 337 impact = const WorldImpact(); |
| 337 } | 338 } |
| 338 return impact; | 339 return impact; |
| 339 } | 340 } |
| 340 | 341 |
| 341 @override | 342 @override |
| 342 bool isDeserialized(Element element) { | 343 bool isDeserialized(Element element) { |
| 343 return deserializedLibraries.contains(element.library); | 344 return deserializedLibraries.contains(element.library); |
| 344 } | 345 } |
| 345 } | 346 } |
| OLD | NEW |