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

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

Powered by Google App Engine
This is Rietveld 408576698