| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:compiler/src/compiler.dart' show Compiler; | 7 import 'package:compiler/src/compiler.dart' show Compiler; |
| 8 import 'package:compiler/src/elements/elements.dart' show Element; | 8 import 'package:compiler/src/elements/elements.dart' show Element; |
| 9 import 'package:compiler/src/js_backend/backend.dart' as js | 9 import 'package:compiler/src/js_backend/backend.dart' as js |
| 10 show JavaScriptBackend; | 10 show JavaScriptBackend; |
| 11 import 'package:compiler/src/commandline_options.dart' show Flags; | 11 import 'package:compiler/src/commandline_options.dart' show Flags; |
| 12 import 'package:test/test.dart'; | 12 import 'package:test/test.dart'; |
| 13 | 13 |
| 14 import '../memory_compiler.dart'; | 14 import '../memory_compiler.dart'; |
| 15 | 15 |
| 16 Future<String> compile(String code, | 16 Future<String> compile(String code, |
| 17 {String entry: 'main', | 17 {String entry: 'main', |
| 18 bool useKernel: true, | 18 bool useKernel: true, |
| 19 bool disableTypeInference: true}) async { | 19 bool disableTypeInference: true, |
| 20 List<String> extraOptions: const <String>[]}) async { |
| 20 List<String> options = <String>[ | 21 List<String> options = <String>[ |
| 21 Flags.disableInlining, | 22 Flags.disableInlining, |
| 22 ]; | 23 ]; |
| 23 if (disableTypeInference) options.add(Flags.disableTypeInference); | 24 if (disableTypeInference) options.add(Flags.disableTypeInference); |
| 24 if (useKernel) options.add(Flags.useKernel); | 25 if (useKernel) options.add(Flags.useKernel); |
| 26 options.addAll(extraOptions); |
| 25 | 27 |
| 26 if (entry != 'main' && !code.contains('main')) { | 28 if (entry != 'main' && !code.contains('main')) { |
| 27 code = "$code\n\nmain() => $entry;"; | 29 code = "$code\n\nmain() => $entry;"; |
| 28 } | 30 } |
| 29 CompilationResult result = await runCompiler( | 31 CompilationResult result = await runCompiler( |
| 30 memorySourceFiles: {'main.dart': code}, options: options); | 32 memorySourceFiles: {'main.dart': code}, options: options); |
| 31 expect(result.isSuccess, isTrue); | 33 expect(result.isSuccess, isTrue); |
| 32 Compiler compiler = result.compiler; | 34 Compiler compiler = result.compiler; |
| 33 Element element = compiler.mainApp.find(entry); | 35 Element element = compiler.mainApp.find(entry); |
| 34 js.JavaScriptBackend backend = compiler.backend; | 36 js.JavaScriptBackend backend = compiler.backend; |
| 35 return backend.getGeneratedCode(element); | 37 return backend.getGeneratedCode(element); |
| 36 } | 38 } |
| 37 | 39 |
| 38 Future check(String code, | 40 Future check(String code, |
| 39 {String entry: 'main', bool disableTypeInference: true}) async { | 41 {String entry: 'main', |
| 42 bool disableTypeInference: true, |
| 43 List<String> extraOptions: const <String>[]}) async { |
| 40 var original = await compile(code, | 44 var original = await compile(code, |
| 41 entry: entry, | 45 entry: entry, |
| 42 useKernel: false, | 46 useKernel: false, |
| 43 disableTypeInference: disableTypeInference); | 47 disableTypeInference: disableTypeInference, |
| 48 extraOptions: extraOptions); |
| 44 var kernel = await compile(code, | 49 var kernel = await compile(code, |
| 45 entry: entry, | 50 entry: entry, |
| 46 useKernel: true, | 51 useKernel: true, |
| 47 disableTypeInference: disableTypeInference); | 52 disableTypeInference: disableTypeInference, |
| 53 extraOptions: extraOptions); |
| 48 expect(kernel, original); | 54 expect(kernel, original); |
| 49 } | 55 } |
| OLD | NEW |