| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Smoke test of the dart2js compiler API. | 5 // Smoke test of the dart2js compiler API. |
| 6 | 6 |
| 7 #import('../../../lib/compiler/compiler.dart'); | 7 #import('../../../lib/compiler/compiler.dart'); |
| 8 #import('dart:uri'); | 8 #import('dart:uri'); |
| 9 | 9 |
| 10 Future<String> provider(Uri uri) { | 10 Future<String> provider(Uri uri) { |
| 11 Completer<String> completer = new Completer<String>(); | 11 Completer<String> completer = new Completer<String>(); |
| 12 String source; | 12 String source; |
| 13 if (uri.scheme == "main") { | 13 if (uri.scheme == "main") { |
| 14 source = "main() {}"; | 14 source = "main() {}"; |
| 15 } else if (uri.scheme == "lib") { |
| 16 if (uri.path.endsWith("/core.dart")) { |
| 17 source = """#library('core'); |
| 18 class Object{} |
| 19 class bool {} |
| 20 class num {} |
| 21 class int {} |
| 22 class double{} |
| 23 class String{} |
| 24 class Function{} |
| 25 class List {} |
| 26 class Closure {} |
| 27 class Dynamic {} |
| 28 class Null {}"""; |
| 29 } else { |
| 30 source = "#library('lib');"; |
| 31 } |
| 15 } else { | 32 } else { |
| 16 source = "#library('lib');"; | 33 throw "unexpected URI $uri"; |
| 17 } | 34 } |
| 18 completer.complete(source); | 35 completer.complete(source); |
| 19 return completer.future; | 36 return completer.future; |
| 20 } | 37 } |
| 21 | 38 |
| 22 void handler(Uri uri, int begin, int end, String message, bool fatal) { | 39 void handler(Uri uri, int begin, int end, String message, bool fatal) { |
| 23 print(message); | 40 print(message); |
| 24 } | 41 } |
| 25 | 42 |
| 26 main() { | 43 main() { |
| 27 String code = compile(new Uri(scheme: 'main'), new Uri(scheme: 'lib'), | 44 String code = compile(new Uri(scheme: 'main'), new Uri(scheme: 'lib'), |
| 28 provider, handler).value; | 45 provider, handler).value; |
| 29 if (code === null) { | 46 if (code === null) { |
| 30 throw 'Compilation failed'; | 47 throw 'Compilation failed'; |
| 31 } | 48 } |
| 32 } | 49 } |
| OLD | NEW |