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 library dummy_compiler; |
| 8 |
7 import '../../sdk/lib/_internal/compiler/compiler.dart'; | 9 import '../../sdk/lib/_internal/compiler/compiler.dart'; |
8 import 'dart:uri'; | 10 import 'dart:uri'; |
9 | 11 |
10 Future<String> provider(Uri uri) { | 12 Future<String> provider(Uri uri) { |
11 Completer<String> completer = new Completer<String>(); | 13 Completer<String> completer = new Completer<String>(); |
12 String source; | 14 String source; |
13 if (uri.scheme == "main") { | 15 if (uri.scheme == "main") { |
14 source = "main() {}"; | 16 source = "main() {}"; |
15 } else if (uri.scheme == "lib") { | 17 } else if (uri.scheme == "lib") { |
16 if (uri.path.endsWith("/core.dart")) { | 18 if (uri.path.endsWith("/core.dart")) { |
17 source = """#library('core'); | 19 source = """library core; |
18 class Object {} | 20 class Object {} |
19 class Type {} | 21 class Type {} |
20 class bool {} | 22 class bool {} |
21 class num {} | 23 class num {} |
22 class int {} | 24 class int {} |
23 class double{} | 25 class double{} |
24 class String{} | 26 class String{} |
25 class Function{} | 27 class Function{} |
26 class List {} | 28 class List {} |
27 class Map {} | 29 class Map {} |
28 class Closure {} | 30 class Closure {} |
29 class Dynamic_ {} | 31 class Dynamic_ {} |
30 class Null {} | 32 class Null {} |
31 getRuntimeTypeInfo(o) {} | 33 getRuntimeTypeInfo(o) {} |
32 setRuntimeTypeInfo(o, i) {} | 34 setRuntimeTypeInfo(o, i) {} |
33 eqNull(a) {} | 35 eqNull(a) {} |
34 eqNullB(a) {}"""; | 36 eqNullB(a) {}"""; |
35 } else if (uri.path.endsWith('_patch.dart')) { | 37 } else if (uri.path.endsWith('_patch.dart')) { |
36 source = ''; | 38 source = ''; |
37 } else if (uri.path.endsWith('interceptors.dart')) { | 39 } else if (uri.path.endsWith('interceptors.dart')) { |
38 source = """class ObjectInterceptor {} | 40 source = """class ObjectInterceptor {} |
| 41 class JSArray {} |
| 42 class JSString {} |
| 43 class JSFunction {} |
| 44 class JSInt {} |
| 45 class JSDouble {} |
| 46 class JSNumber {} |
| 47 class JSNull {} |
| 48 class JSBool {} |
39 var getInterceptor;"""; | 49 var getInterceptor;"""; |
40 } else if (uri.path.endsWith('js_helper.dart')) { | 50 } else if (uri.path.endsWith('js_helper.dart')) { |
41 source = 'library jshelper; class JSInvocationMirror {}'; | 51 source = 'library jshelper; class JSInvocationMirror {}'; |
42 } else { | 52 } else { |
43 source = "#library('lib');"; | 53 source = "library lib;"; |
44 } | 54 } |
45 } else { | 55 } else { |
46 throw "unexpected URI $uri"; | 56 throw "unexpected URI $uri"; |
47 } | 57 } |
48 completer.complete(source); | 58 completer.complete(source); |
49 return completer.future; | 59 return completer.future; |
50 } | 60 } |
51 | 61 |
52 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { | 62 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { |
53 if (uri == null) { | 63 if (uri == null) { |
54 print('$kind: $message'); | 64 print('$kind: $message'); |
55 } else { | 65 } else { |
56 print('$uri:$begin:$end: $kind: $message'); | 66 print('$uri:$begin:$end: $kind: $message'); |
57 } | 67 } |
58 } | 68 } |
59 | 69 |
60 main() { | 70 main() { |
61 String code = compile(new Uri.fromComponents(scheme: 'main'), | 71 String code = compile(new Uri.fromComponents(scheme: 'main'), |
62 new Uri.fromComponents(scheme: 'lib', path: '/'), | 72 new Uri.fromComponents(scheme: 'lib', path: '/'), |
63 new Uri.fromComponents(scheme: 'package', path: '/'), | 73 new Uri.fromComponents(scheme: 'package', path: '/'), |
64 provider, handler).value; | 74 provider, handler).value; |
65 if (code == null) { | 75 if (code == null) { |
66 throw 'Compilation failed'; | 76 throw 'Compilation failed'; |
67 } | 77 } |
68 } | 78 } |
OLD | NEW |