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 '../../sdk/lib/_internal/compiler/compiler.dart'; | 13 import '../../sdk/lib/_internal/compiler/compiler.dart'; |
14 | 14 |
15 Future<String> provider(Uri uri) { | 15 String libProvider(Uri uri) { |
16 String source; | 16 if (uri.path.endsWith("/core.dart")) { |
17 if (uri.scheme == "main") { | 17 return """ |
18 source = "main() {}"; | |
19 } else if (uri.scheme == "lib") { | |
20 if (uri.path.endsWith("/core.dart")) { | |
21 source = """ | |
22 library core; | 18 library core; |
23 class Object { | 19 class Object { |
24 Object(); | 20 Object(); |
25 // Note: JSNull below must reimplement all members. | 21 // Note: JSNull below must reimplement all members. |
26 operator==(other) {} | 22 operator==(other) {} |
27 get hashCode => throw 'Object.hashCode not implemented.'; | 23 get hashCode => throw 'Object.hashCode not implemented.'; |
28 } | 24 } |
29 class Type {} | 25 class Type {} |
30 class bool {} | 26 class bool {} |
31 class num {} | 27 class num {} |
(...skipping 11 matching lines...) Expand all Loading... |
43 class LinkedHashMap { | 39 class LinkedHashMap { |
44 factory LinkedHashMap._empty() => null; | 40 factory LinkedHashMap._empty() => null; |
45 factory LinkedHashMap._literal(elements) => null; | 41 factory LinkedHashMap._literal(elements) => null; |
46 } | 42 } |
47 identical(a, b) => true; | 43 identical(a, b) => true; |
48 getRuntimeTypeInfo(o) {} | 44 getRuntimeTypeInfo(o) {} |
49 setRuntimeTypeInfo(o, i) {} | 45 setRuntimeTypeInfo(o, i) {} |
50 eqNull(a) {} | 46 eqNull(a) {} |
51 eqNullB(a) {} | 47 eqNullB(a) {} |
52 const proxy = 0;"""; | 48 const proxy = 0;"""; |
53 } else if (uri.path.endsWith('_patch.dart')) { | 49 } else if (uri.path.endsWith('_patch.dart')) { |
54 source = ''; | 50 return """ |
55 } else if (uri.path.endsWith('interceptors.dart')) { | 51 import 'dart:_js_helper'; |
56 source = """ | 52 import 'dart:_interceptors'; |
| 53 import 'dart:_isolate_helper';"""; |
| 54 } else if (uri.path.endsWith('interceptors.dart')) { |
| 55 return """ |
57 class Interceptor { | 56 class Interceptor { |
58 operator==(other) {} | 57 operator==(other) {} |
59 get hashCode => throw 'Interceptor.hashCode not implemented.'; | 58 get hashCode => throw 'Interceptor.hashCode not implemented.'; |
60 } | 59 } |
61 abstract class JSIndexable { | 60 abstract class JSIndexable { |
62 get length; | 61 get length; |
63 } | 62 } |
64 abstract class JSMutableIndexable {} | 63 abstract class JSMutableIndexable {} |
65 abstract class JSArray<E> implements JSIndexable { | 64 abstract class JSArray<E> implements JSIndexable { |
66 JSArray() {} | 65 JSArray() {} |
(...skipping 20 matching lines...) Expand all Loading... |
87 class JSNumber {} | 86 class JSNumber {} |
88 class JSNull { | 87 class JSNull { |
89 bool operator ==(other) => identical(null, other); | 88 bool operator ==(other) => identical(null, other); |
90 int get hashCode => 0; | 89 int get hashCode => 0; |
91 } | 90 } |
92 class JSBool {} | 91 class JSBool {} |
93 getInterceptor(o){} | 92 getInterceptor(o){} |
94 getDispatchProperty(o) {} | 93 getDispatchProperty(o) {} |
95 setDispatchProperty(o, v) {} | 94 setDispatchProperty(o, v) {} |
96 var mapTypeToInterceptor;"""; | 95 var mapTypeToInterceptor;"""; |
97 } else if (uri.path.endsWith('js_helper.dart')) { | 96 } else if (uri.path.endsWith('js_helper.dart')) { |
98 source = 'library jshelper; class JSInvocationMirror {} ' | 97 return """ |
99 'class ConstantMap {} class TypeImpl {} ' | 98 library jshelper; class JSInvocationMirror {} |
100 'createRuntimeType(String name) => null;'; | 99 class ConstantMap {} class TypeImpl {} |
101 } else if (uri.path.endsWith('isolate_helper.dart')) { | 100 createRuntimeType(String name) => null; |
102 source = 'library isolatehelper; class _WorkerStub {}'; | 101 class Closure {} |
103 } else { | 102 class BoundClosure extends Closure {} |
104 source = "library lib${uri.path.replaceAll('/', '.')};"; | 103 """; |
105 } | 104 } else if (uri.path.endsWith('isolate_helper.dart')) { |
| 105 return 'library isolatehelper; class _WorkerStub {}'; |
| 106 } else { |
| 107 return "library lib${uri.path.replaceAll('/', '.')};"; |
| 108 } |
| 109 } |
| 110 |
| 111 Future<String> provider(Uri uri) { |
| 112 String source; |
| 113 if (uri.scheme == "main") { |
| 114 source = "main() {}"; |
| 115 } else if (uri.scheme == "lib") { |
| 116 source = libProvider(uri); |
106 } else { | 117 } else { |
107 throw "unexpected URI $uri"; | 118 throw "unexpected URI $uri"; |
108 } | 119 } |
109 return new Future.value(source); | 120 return new Future.value(source); |
110 } | 121 } |
111 | 122 |
112 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { | 123 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { |
113 if (uri == null) { | 124 if (uri == null) { |
114 print('$kind: $message'); | 125 print('$kind: $message'); |
115 } else { | 126 } else { |
116 print('$uri:$begin:$end: $kind: $message'); | 127 print('$uri:$begin:$end: $kind: $message'); |
117 } | 128 } |
118 } | 129 } |
119 | 130 |
120 main() { | 131 main() { |
121 asyncStart(); | 132 asyncStart(); |
122 Future<String> result = | 133 Future<String> result = |
123 compile(new Uri(scheme: 'main'), | 134 compile(new Uri(scheme: 'main'), |
124 new Uri(scheme: 'lib', path: '/'), | 135 new Uri(scheme: 'lib', path: '/'), |
125 new Uri(scheme: 'package', path: '/'), | 136 new Uri(scheme: 'package', path: '/'), |
126 provider, handler); | 137 provider, handler); |
127 result.then((String code) { | 138 result.then((String code) { |
128 if (code == null) { | 139 if (code == null) { |
129 throw 'Compilation failed'; | 140 throw 'Compilation failed'; |
130 } | 141 } |
131 }, onError: (e) { | 142 }, onError: (e) { |
132 throw 'Compilation failed'; | 143 throw 'Compilation failed'; |
133 }).then(asyncSuccess); | 144 }).then(asyncSuccess); |
134 } | 145 } |
OLD | NEW |