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 // VMOptions= | 4 // VMOptions= |
5 // VMOptions=--print-object-histogram | 5 // VMOptions=--print-object-histogram |
6 | 6 |
7 // Smoke test of the dart2js compiler API. | 7 // Smoke test of the dart2js compiler API. |
8 library dummy_compiler; | 8 library dummy_compiler; |
9 | 9 |
10 import 'dart:async'; | 10 import 'dart:async'; |
11 import "package:async_helper/async_helper.dart"; | 11 import "package:async_helper/async_helper.dart"; |
12 | 12 |
13 import 'package:compiler/compiler.dart'; | 13 import 'package:compiler/compiler.dart'; |
14 | 14 |
| 15 import '../compiler/dart2js/mock_libraries.dart'; |
| 16 |
15 String libProvider(Uri uri) { | 17 String libProvider(Uri uri) { |
16 if (uri.path.endsWith("/core.dart")) { | 18 if (uri.path.endsWith("/core.dart")) { |
17 return """ | 19 return buildLibrarySource(DEFAULT_CORE_LIBRARY); |
18 library core; | 20 } else if (uri.path.endsWith('core_patch.dart')) { |
19 class Object { | 21 return DEFAULT_PATCH_CORE_SOURCE; |
20 Object(); | |
21 // Note: JSNull below must reimplement all members. | |
22 operator==(other) {} | |
23 get hashCode => throw 'Object.hashCode not implemented.'; | |
24 } | |
25 class Type {} | |
26 class bool {} | |
27 class num {} | |
28 class int {} | |
29 class double{} | |
30 class String{} | |
31 class Function{} | |
32 class List<E> {} | |
33 class Map {} | |
34 class Closure {} | |
35 class BoundClosure {} | |
36 class Dynamic_ {} | |
37 class Null {} | |
38 class StackTrace {} | |
39 class LinkedHashMap { | |
40 factory LinkedHashMap._empty() => null; | |
41 factory LinkedHashMap._literal(elements) => null; | |
42 } | |
43 identical(a, b) => true; | |
44 getRuntimeTypeInfo(o) {} | |
45 setRuntimeTypeInfo(o, i) {} | |
46 eqNull(a) {} | |
47 eqNullB(a) {} | |
48 const proxy = 0;"""; | |
49 } else if (uri.path.endsWith('_patch.dart')) { | |
50 return """ | |
51 import 'dart:_js_helper'; | |
52 import 'dart:_interceptors'; | |
53 import 'dart:_isolate_helper';"""; | |
54 } else if (uri.path.endsWith('interceptors.dart')) { | 22 } else if (uri.path.endsWith('interceptors.dart')) { |
55 return """ | 23 return buildLibrarySource(DEFAULT_INTERCEPTORS_LIBRARY); |
56 class Interceptor { | |
57 operator==(other) {} | |
58 get hashCode => throw 'Interceptor.hashCode not implemented.'; | |
59 } | |
60 abstract class JSIndexable { | |
61 get length; | |
62 } | |
63 abstract class JSMutableIndexable {} | |
64 abstract class JSArray<E> implements JSIndexable { | |
65 JSArray() {} | |
66 factory JSArray.typed(a) => a; | |
67 var removeLast; | |
68 var add; | |
69 } | |
70 abstract class JSMutableArray extends JSArray {} | |
71 abstract class JSFixedArray extends JSMutableArray {} | |
72 abstract class JSExtendableArray extends JSMutableArray {} | |
73 class JSString implements JSIndexable { | |
74 var split; | |
75 var concat; | |
76 operator+(other) {} | |
77 var toString; | |
78 get length => 0; | |
79 } | |
80 class JSFunction {} | |
81 class JSInt {} | |
82 class JSPositiveInt {} | |
83 class JSUInt31 {} | |
84 class JSUInt32 {} | |
85 class JSDouble {} | |
86 class JSNumber {} | |
87 class JSNull { | |
88 bool operator ==(other) => identical(null, other); | |
89 int get hashCode => 0; | |
90 } | |
91 class JSBool {} | |
92 getInterceptor(o){} | |
93 getDispatchProperty(o) {} | |
94 setDispatchProperty(o, v) {} | |
95 var mapTypeToInterceptor;"""; | |
96 } else if (uri.path.endsWith('js_helper.dart')) { | 24 } else if (uri.path.endsWith('js_helper.dart')) { |
97 return """ | 25 return buildLibrarySource(DEFAULT_JS_HELPER_LIBRARY); |
98 library jshelper; class JSInvocationMirror {} | |
99 class ConstantMap {} class TypeImpl {} | |
100 createRuntimeType(String name) => null; | |
101 class Closure {} | |
102 class BoundClosure extends Closure {} | |
103 const patch = 0; | |
104 """; | |
105 } else if (uri.path.endsWith('isolate_helper.dart')) { | 26 } else if (uri.path.endsWith('isolate_helper.dart')) { |
106 return 'library isolatehelper; class _WorkerStub {}'; | 27 return buildLibrarySource(DEFAULT_ISOLATE_HELPER_LIBRARY); |
107 } else { | 28 } else { |
108 return "library lib${uri.path.replaceAll('/', '.')};"; | 29 return "library lib${uri.path.replaceAll('/', '.')};"; |
109 } | 30 } |
110 } | 31 } |
111 | 32 |
112 Future<String> provider(Uri uri) { | 33 Future<String> provider(Uri uri) { |
113 String source; | 34 String source; |
114 if (uri.scheme == "main") { | 35 if (uri.scheme == "main") { |
115 source = "main() {}"; | 36 source = "main() {}"; |
116 } else if (uri.scheme == "lib") { | 37 } else if (uri.scheme == "lib") { |
(...skipping 17 matching lines...) Expand all Loading... |
134 Future<String> result = | 55 Future<String> result = |
135 compile(new Uri(scheme: 'main'), | 56 compile(new Uri(scheme: 'main'), |
136 new Uri(scheme: 'lib', path: '/'), | 57 new Uri(scheme: 'lib', path: '/'), |
137 new Uri(scheme: 'package', path: '/'), | 58 new Uri(scheme: 'package', path: '/'), |
138 provider, handler); | 59 provider, handler); |
139 result.then((String code) { | 60 result.then((String code) { |
140 if (code == null) { | 61 if (code == null) { |
141 throw 'Compilation failed'; | 62 throw 'Compilation failed'; |
142 } | 63 } |
143 }, onError: (e) { | 64 }, onError: (e) { |
144 throw 'Compilation failed'; | 65 throw 'Compilation failed: $e'; |
145 }).then(asyncSuccess); | 66 }).then(asyncSuccess); |
146 } | 67 } |
OLD | NEW |