Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: tests/compiler/dart2js/mock_libraries.dart

Issue 362243003: Generate mock libraries and assert that helpers are non-null. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 // Library for creating mock versions of platform and internal libraries.
6
7 library mock_libraries;
8
9 String buildLibrarySource(Map elementMap,
10 [Map additionalElementMap = const {}]) {
11 Map map = new Map.from(elementMap);
12 if (additionalElementMap != null) {
13 map.addAll(additionalElementMap);
14 }
15 StringBuffer sb = new StringBuffer();
16 map.values.forEach((String element) {
17 sb.write('$element\n');
18 });
19 return sb.toString();
20 }
21
22 const Map DEFAULT_CORE_LIBRARY = const {
23 'bool': 'class bool {}',
24 'DateTime': r'''
25 class DateTime {
26 DateTime(year);
27 DateTime.utc(year);
28 }''',
29 'double': r'''
30 abstract class double extends num {
31 static var NAN = 0;
32 static parse(s) {}
33 }''',
34 'Function': 'class Function {}',
35 'identical': 'bool identical(Object a, Object b) { return true; }',
36 'int': 'abstract class int extends num { }',
37 'LinkedHashMap': r'''
38 class LinkedHashMap {
39 factory LinkedHashMap._empty() => null;
40 factory LinkedHashMap._literal(elements) => null;
41 }''',
42 'List': r'''
43 class List<E> {
44 var length;
45 List([length]);
46 List.filled(length, element);
47 E get first => null;
48 E get last => null;
49 E get single => null;
50 E removeLast() => null;
51 E removeAt(i) => null;
52 E elementAt(i) => null;
53 E singleWhere(f) => null;
54 }''',
55 'Map': 'abstract class Map<K,V> {}',
56 'Null': 'class Null {}',
57 'num': 'abstract class num {}',
58 'print': 'print(var obj) {}',
59 'proxy': 'const proxy = 0;',
60 'Object': r'''
61 class Object {
62 const Object();
63 operator ==(other) { return true; }
64 get hashCode => throw "Object.hashCode not implemented.";
65 String toString() { return null; }
66 noSuchMethod(im) { throw im; }
67 }''',
68 'StackTrace': 'abstract class StackTrace {}',
69 'String': 'class String implements Pattern {}',
70 'Type': 'class Type {}',
71 'Pattern': 'abstract class Pattern {}',
72 };
73
74 const String DEFAULT_PATCH_CORE_SOURCE = r'''
75 import 'dart:_js_helper';
76 import 'dart:_interceptors';
77 import 'dart:_isolate_helper';
78 ''';
79
80 const Map DEFAULT_JS_HELPER_LIBRARY = const {
81 'assertHelper': 'assertHelper(a) {}',
82 'assertIsSubtype': 'assertIsSubtype(subtype, supertype, message) {}',
83 'assertSubtype': 'assertSubtype(object, isField, checks, asField) {}',
84 'assertSubtypeOfRuntimeType': 'assertSubtypeOfRuntimeType(object, type) {}',
85 'boolConversionCheck': 'boolConversionCheck(x) {}',
86 'boolTypeCast': 'boolTypeCast(value) {}',
87 'boolTypeCheck': 'boolTypeCheck(value) {}',
88 'BoundClosure': r'''abstract class BoundClosure extends Closure {
89 var self;
90 var target;
91 var receiver;
92 }''',
93 'buildFunctionType':
94 r'''buildFunctionType(returnType, parameterTypes,
95 optionalParameterTypes) {}''',
96 'buildInterfaceType': 'buildInterfaceType(rti, typeArguments) {}',
97 'buildNamedFunctionType':
98 r'''buildNamedFunctionType(returnType, parameterTypes,
99 namedParameters) {}''',
100 'checkFunctionSubtype':
101 r'''checkFunctionSubtype(var target, String signatureName,
102 String contextName, var context,
103 var typeArguments) {}''',
104 'checkMalformedType': 'checkMalformedType(value, message) {}',
105 'Closure': 'abstract class Closure implements Function { }',
106 'closureFromTearOff':
107 r'''closureFromTearOff(receiver, functions, reflectionInfo,
108 isStatic, jsArguments, name) {}''',
109 'computeSignature':
110 'computeSignature(var signature, var context, var contextName) {}',
111 'ConstantMap': 'class ConstantMap {}',
112 'ConstantProtoMap': 'class ConstantProtoMap {}',
113 'ConstantStringMap': 'class ConstantStringMap {}',
114 'copyTypeArguments': 'copyTypeArguments(source, target) {}',
115 'createInvocationMirror': 'createInvocationMirror(a0, a1, a2, a3, a4, a5) {}',
116 'createRuntimeType': 'createRuntimeType(a) {}',
117 'doubleTypeCast': 'doubleTypeCast(value) {}',
118 'doubleTypeCheck': 'doubleTypeCheck(value) {}',
119 'functionSubtypeCast':
120 r'''functionSubtypeCast(Object object, String signatureName,
121 String contextName, var context) {}''',
122 'functionTypeTestMetaHelper': r'''
123 functionTypeTestMetaHelper() {
124 buildFunctionType(null, null, null);
125 buildNamedFunctionType(null, null, null);
126 buildInterfaceType(null, null);
127 }''',
128 'getFallThroughError': 'getFallThroughError() {}',
129 'getIsolateAffinityTag': 'getIsolateAffinityTag(_) {}',
130 'getRuntimeTypeArgument':
131 'getRuntimeTypeArgument(target, substitutionName, index) {}',
132 'getRuntimeTypeArguments':
133 'getRuntimeTypeArguments(target, substitutionName) {}',
134 'getRuntimeTypeInfo': 'getRuntimeTypeInfo(a) {}',
135 'getTraceFromException': 'getTraceFromException(exception) {}',
136 'getTypeArgumentByIndex': 'getTypeArgumentByIndex(target, index) {}',
137 'GeneralConstantMap': 'class GeneralConstantMap {}',
138 'iae': 'iae(x) { throw x; } ioore(x) { throw x; }',
139 'interceptedTypeCast': 'interceptedTypeCast(value, property) {}',
140 'interceptedTypeCheck': 'interceptedTypeCheck(value, property) {}',
141 'intTypeCast': 'intTypeCast(value) {}',
142 'intTypeCheck': 'intTypeCheck(value) {}',
143 'IrRepresentation': 'class IrRepresentation {}',
144 'isJsIndexable': 'isJsIndexable(a, b) {}',
145 'JavaScriptIndexingBehavior': 'abstract class JavaScriptIndexingBehavior {}',
146 'JSInvocationMirror': 'class JSInvocationMirror {}',
147 'listSuperNativeTypeCast': 'listSuperNativeTypeCast(value) {}',
148 'listSuperNativeTypeCheck': 'listSuperNativeTypeCheck(value) {}',
149 'listSuperTypeCast': 'listSuperTypeCast(value) {}',
150 'listSuperTypeCheck': 'listSuperTypeCheck(value) {}',
151 'listTypeCast': 'listTypeCast(value) {}',
152 'listTypeCheck': 'listTypeCheck(value) {}',
153 'makeLiteralMap': 'makeLiteralMap(List keyValuePairs) {}',
154 'NoInline': 'class NoInline {}',
155 'NoSideEffects': 'class NoSideEffects {}',
156 'NoThrows': 'class NoThrows {}',
157 'numberOrStringSuperNativeTypeCast':
158 'numberOrStringSuperNativeTypeCast(value) {}',
159 'numberOrStringSuperNativeTypeCheck':
160 'numberOrStringSuperNativeTypeCheck(value) {}',
161 'numberOrStringSuperTypeCast': 'numberOrStringSuperTypeCast(value) {}',
162 'numberOrStringSuperTypeCheck': 'numberOrStringSuperTypeCheck(value) {}',
163 'numTypeCast': 'numTypeCast(value) {}',
164 'numTypeCheck': 'numTypeCheck(value) {}',
165 'patch': 'const patch = 0;',
166 'propertyTypeCast': 'propertyTypeCast(x) {}',
167 'propertyTypeCheck': 'propertyTypeCheck(value, property) {}',
168 'RuntimeFunctionType': 'class RuntimeFunctionType {}',
169 'RuntimeTypePlain': 'class RuntimeTypePlain {}',
170 'runtimeTypeToString': 'runtimeTypeToString(type, {onTypeVariable(i)}) {}',
171 'S': 'S() {}',
172 'setRuntimeTypeInfo': 'setRuntimeTypeInfo(a, b) {}',
173 'stringSuperNativeTypeCast': 'stringSuperNativeTypeCast(value) {}',
174 'stringSuperNativeTypeCheck': 'stringSuperNativeTypeCheck(value) {}',
175 'stringSuperTypeCast': 'stringSuperTypeCast(value) {}',
176 'stringSuperTypeCheck': 'stringSuperTypeCheck(value) {}',
177 'stringTypeCast': 'stringTypeCast(x) {}',
178 'stringTypeCheck': 'stringTypeCheck(x) {}',
179 'subtypeCast': 'subtypeCast(object, isField, checks, asField) {}',
180 'subtypeOfRuntimeTypeCast': 'subtypeOfRuntimeTypeCast(object, type) {}',
181 'throwAbstractClassInstantiationError':
182 'throwAbstractClassInstantiationError(className) {}',
183 'throwCyclicInit': 'throwCyclicInit() {}',
184 'throwExpression': 'throwExpression(e) {}',
185 'throwNoSuchMethod':
186 'throwNoSuchMethod(obj, name, arguments, expectedArgumentNames) {}',
187 'throwRuntimeError': 'throwRuntimeError(message) {}',
188 'throwTypeError': 'throwTypeError(message) {}',
189 'TypeImpl': 'class TypeImpl {}',
190 'TypeVariable': 'class TypeVariable {}',
191 'unwrapException': 'unwrapException(e) {}',
192 'voidTypeCheck': 'voidTypeCheck(value) {}',
193 'wrapException': 'wrapException(x) { return x; }',
194 };
195
196 const Map DEFAULT_FOREIGN_HELPER_LIBRARY = const {
197 'JS': r'''
198 dynamic JS(String typeDescription, String codeTemplate,
199 [var arg0, var arg1, var arg2, var arg3, var arg4, var arg5, var arg6,
200 var arg7, var arg8, var arg9, var arg10, var arg11]) {}''',
201 };
202
203 const Map DEFAULT_INTERCEPTORS_LIBRARY = const {
204 'findIndexForNativeSubclassType':
205 'findIndexForNativeSubclassType(type) {}',
206 'getDispatchProperty': 'getDispatchProperty(o) {}',
207 'getInterceptor': 'getInterceptor(x) {}',
208 'getNativeInterceptor': 'getNativeInterceptor(x) {}',
209 'initializeDispatchProperty': 'initializeDispatchProperty(f,p,i) {}',
210 'initializeDispatchPropertyCSP': 'initializeDispatchPropertyCSP(f,p,i) {}',
211 'interceptedNames': 'var interceptedNames;',
212 'Interceptor': r'''
213 class Interceptor {
214 toString() {}
215 bool operator==(other) => identical(this, other);
216 get hashCode => throw "Interceptor.hashCode not implemented.";
217 noSuchMethod(im) { throw im; }
218 }''',
219 'JSArray': r'''
220 class JSArray<E> extends Interceptor implements List<E>, JSIndexable {
221 JSArray();
222 factory JSArray.typed(a) => a;
223 var length;
224 operator[](index) => this[index];
225 operator[]=(index, value) { this[index] = value; }
226 add(value) { this[length + 1] = value; }
227 insert(index, value) {}
228 E get first => this[0];
229 E get last => this[0];
230 E get single => this[0];
231 E removeLast() => this[0];
232 E removeAt(index) => this[0];
233 E elementAt(index) => this[0];
234 E singleWhere(f) => this[0];
235 }''',
236 'JSBool': 'class JSBool extends Interceptor implements bool {}',
237 'JSDouble': 'class JSDouble extends JSNumber implements double {}',
238 'JSExtendableArray': 'class JSExtendableArray extends JSMutableArray {}',
239 'JSFixedArray': 'class JSFixedArray extends JSMutableArray {}',
240 'JSFunction':
241 'abstract class JSFunction extends Interceptor implements Function {}',
242 'JSIndexable': r'''
243 abstract class JSIndexable {
244 get length;
245 operator[](index);
246 }''',
247 'JSInt': r'''
248 class JSInt extends JSNumber implements int {
249 operator~() => this;
250 }''',
251 'JSMutableArray':
252 'class JSMutableArray extends JSArray implements JSMutableIndexable {}',
253 'JSMutableIndexable':
254 'abstract class JSMutableIndexable extends JSIndexable {}',
255 'JSPositiveInt': 'class JSPositiveInt extends JSInt {}',
256 'JSNull': r'''
257 class JSNull extends Interceptor {
258 bool operator==(other) => identical(null, other);
259 get hashCode => throw "JSNull.hashCode not implemented.";
260 String toString() => 'Null';
261 Type get runtimeType => null;
262 noSuchMethod(x) => super.noSuchMethod(x);
263 }''',
264 'JSNumber': r'''
265 class JSNumber extends Interceptor implements num {
266 // All these methods return a number to please type inferencing.
267 operator-() => (this is JSInt) ? 42 : 42.2;
268 operator +(other) => (this is JSInt) ? 42 : 42.2;
269 operator -(other) => (this is JSInt) ? 42 : 42.2;
270 operator ~/(other) => _tdivFast(other);
271 operator /(other) => (this is JSInt) ? 42 : 42.2;
272 operator *(other) => (this is JSInt) ? 42 : 42.2;
273 operator %(other) => (this is JSInt) ? 42 : 42.2;
274 operator <<(other) => _shlPositive(other);
275 operator >>(other) {
276 return _shrBothPositive(other) + _shrReceiverPositive(other) +
277 _shrOtherPositive(other);
278 }
279 operator |(other) => 42;
280 operator &(other) => 42;
281 operator ^(other) => 42;
282
283 operator >(other) => true;
284 operator >=(other) => true;
285 operator <(other) => true;
286 operator <=(other) => true;
287 operator ==(other) => true;
288 get hashCode => throw "JSNumber.hashCode not implemented.";
289
290 // We force side effects on _tdivFast to mimic the shortcomings of
291 // the effect analysis: because the `_tdivFast` implementation of
292 // the core library has calls that may not already be analyzed,
293 // the analysis will conclude that `_tdivFast` may have side
294 // effects.
295 _tdivFast(other) => new List()..length = 42;
296 _shlPositive(other) => 42;
297 _shrBothPositive(other) => 42;
298 _shrReceiverPositive(other) => 42;
299 _shrOtherPositive(other) => 42;
300
301 abs() => (this is JSInt) ? 42 : 42.2;
302 remainder(other) => (this is JSInt) ? 42 : 42.2;
303 truncate() => 42;
304 }''',
305 'JSString': r'''
306 class JSString extends Interceptor implements String, JSIndexable {
307 var split;
308 var length;
309 operator[](index) {}
310 toString() {}
311 operator+(other) => this;
312 }''',
313 'JSUInt31': 'class JSUInt31 extends JSUInt32 {}',
314 'JSUInt32': 'class JSUInt32 extends JSPositiveInt {}',
315 'mapTypeToInterceptor': 'var mapTypeToInterceptor;',
316 'ObjectInterceptor': 'class ObjectInterceptor {}',
317 'PlainJavaScriptObject': 'class PlainJavaScriptObject {}',
318 'UnknownJavaScriptObject': 'class UnknownJavaScriptObject {}',
319 };
320
321 const Map DEFAULT_ISOLATE_HELPER_LIBRARY = const {
322 'startRootIsolate': 'var startRootIsolate;',
323 '_currentIsolate': 'var _currentIsolate;',
324 '_callInIsolate': 'var _callInIsolate;',
325 '_WorkerBase': 'class _WorkerBase {}',
326 };
327
328 const Map DEFAULT_MIRRORS_LIBRARY = const {
329 'Comment': 'class Comment {}',
330 'MirrorSystem': 'class MirrorSystem {}',
331 'MirrorsUsed': 'class MirrorsUsed {}',
332 };
333
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698