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

Side by Side Diff: test/browser/runtime_tests.js

Issue 1100633006: Generate static calls for Object fields and methods (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Address comments Created 5 years, 8 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
« no previous file with comments | « lib/src/utils.dart ('k') | test/codegen/expect/misc.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 var assert = chai.assert; 5 var assert = chai.assert;
6 6
7 suite('generic', () => { 7 suite('generic', () => {
8 "use strict"; 8 "use strict";
9 9
10 let generic = dart.generic; 10 let generic = dart.generic;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 suite('instanceOf', () => { 78 suite('instanceOf', () => {
79 "use strict"; 79 "use strict";
80 80
81 let expect = assert.equal; 81 let expect = assert.equal;
82 let isGroundType = dart.isGroundType; 82 let isGroundType = dart.isGroundType;
83 let generic = dart.generic; 83 let generic = dart.generic;
84 let intIsNonNullable = false; 84 let intIsNonNullable = false;
85 let cast = dart.as; 85 let cast = dart.as;
86 let instanceOf = dart.is; 86 let instanceOf = dart.is;
87 let getRuntimeType = dart.getRuntimeType; 87 let runtimeType = dart.realRuntimeType;
88 let setType = dart.setType; 88 let setType = dart.setType;
89 let functionType = dart.functionType; 89 let functionType = dart.functionType;
90 let typedef = dart.typedef; 90 let typedef = dart.typedef;
91 91
92 let Object = core.Object; 92 let Object = core.Object;
93 let String = core.String; 93 let String = core.String;
94 let dynamic = dart.dynamic; 94 let dynamic = dart.dynamic;
95 let List = core.List; 95 let List = core.List;
96 let Map = core.Map; 96 let Map = core.Map;
97 let Map$ = core.Map$; 97 let Map$ = core.Map$;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 function bar8(b, s, o) { return null; } 148 function bar8(b, s, o) { return null; }
149 setType(bar8, functionType(B, [B, String], {p: Object})); 149 setType(bar8, functionType(B, [B, String], {p: Object}));
150 150
151 function checkType(x, type, expectedTrue) { 151 function checkType(x, type, expectedTrue) {
152 if (expectedTrue === undefined) expectedTrue = true; 152 if (expectedTrue === undefined) expectedTrue = true;
153 expect(instanceOf(x, type), expectedTrue); 153 expect(instanceOf(x, type), expectedTrue);
154 } 154 }
155 155
156 test('int', () => { 156 test('int', () => {
157 expect(isGroundType(int), true); 157 expect(isGroundType(int), true);
158 expect(isGroundType(getRuntimeType(5)), true); 158 expect(isGroundType(runtimeType(5)), true);
159 159
160 checkType(5, int); 160 checkType(5, int);
161 checkType(5, dynamic); 161 checkType(5, dynamic);
162 checkType(5, Object); 162 checkType(5, Object);
163 checkType(5, num); 163 checkType(5, num);
164 164
165 checkType(5, bool, false); 165 checkType(5, bool, false);
166 checkType(5, String, false); 166 checkType(5, String, false);
167 167
168 expect(cast(5, int), 5); 168 expect(cast(5, int), 5);
(...skipping 26 matching lines...) Expand all
195 checkType(null, core.String, false); 195 checkType(null, core.String, false);
196 checkType(null, core.int, false); 196 checkType(null, core.int, false);
197 checkType(null, Map, false); 197 checkType(null, Map, false);
198 checkType(void 0, core.Null); 198 checkType(void 0, core.Null);
199 checkType(void 0, core.Object); 199 checkType(void 0, core.Object);
200 checkType(void 0, dart.dynamic); 200 checkType(void 0, dart.dynamic);
201 }); 201 });
202 202
203 test('String', () => { 203 test('String', () => {
204 expect(isGroundType(String), true); 204 expect(isGroundType(String), true);
205 expect(isGroundType(getRuntimeType("foo")), true); 205 expect(isGroundType(runtimeType("foo")), true);
206 checkType("foo", String); 206 checkType("foo", String);
207 checkType("foo", Object); 207 checkType("foo", Object);
208 checkType("foo", dynamic); 208 checkType("foo", dynamic);
209 209
210 expect(cast(null, String), null); 210 expect(cast(null, String), null);
211 }); 211 });
212 212
213 test('Map', () => { 213 test('Map', () => {
214 let m1 = new (Map$(String, String))(); 214 let m1 = new (Map$(String, String))();
215 let m2 = new (Map$(Object, Object))(); 215 let m2 = new (Map$(Object, Object))();
216 let m3 = new Map(); 216 let m3 = new Map();
217 let m4 = new (collection.HashMap$(dart.dynamic, dart.dynamic))(); 217 let m4 = new (collection.HashMap$(dart.dynamic, dart.dynamic))();
218 let m5 = new collection.LinkedHashMap(); 218 let m5 = new collection.LinkedHashMap();
219 219
220 expect(isGroundType(Map), true); 220 expect(isGroundType(Map), true);
221 expect(isGroundType(getRuntimeType(m1)), false); 221 expect(isGroundType(runtimeType(m1)), false);
222 expect(isGroundType(Map$(String, String)), false); 222 expect(isGroundType(Map$(String, String)), false);
223 expect(isGroundType(getRuntimeType(m2)), true); 223 expect(isGroundType(runtimeType(m2)), true);
224 expect(isGroundType(Map$(Object, Object)), true); 224 expect(isGroundType(Map$(Object, Object)), true);
225 expect(isGroundType(getRuntimeType(m3)), true); 225 expect(isGroundType(runtimeType(m3)), true);
226 expect(isGroundType(Map), true); 226 expect(isGroundType(Map), true);
227 expect(isGroundType(getRuntimeType(m4)), true); 227 expect(isGroundType(runtimeType(m4)), true);
228 expect(isGroundType(collection.HashMap$(dynamic, dynamic)), true); 228 expect(isGroundType(collection.HashMap$(dynamic, dynamic)), true);
229 expect(isGroundType(getRuntimeType(m5)), true); 229 expect(isGroundType(runtimeType(m5)), true);
230 expect(isGroundType(collection.LinkedHashMap), true); 230 expect(isGroundType(collection.LinkedHashMap), true);
231 expect(isGroundType(collection.LinkedHashMap), true); 231 expect(isGroundType(collection.LinkedHashMap), true);
232 232
233 // Map<T1,T2> <: Map 233 // Map<T1,T2> <: Map
234 checkType(m1, Map); 234 checkType(m1, Map);
235 checkType(m1, Object); 235 checkType(m1, Object);
236 236
237 // Instance of self 237 // Instance of self
238 checkType(m1, getRuntimeType(m1)); 238 checkType(m1, runtimeType(m1));
239 checkType(m1, Map$(String, String)); 239 checkType(m1, Map$(String, String));
240 240
241 // Covariance on generics 241 // Covariance on generics
242 checkType(m1, getRuntimeType(m2)); 242 checkType(m1, runtimeType(m2));
243 checkType(m1, Map$(Object, Object)); 243 checkType(m1, Map$(Object, Object));
244 244
245 // No contravariance on generics. 245 // No contravariance on generics.
246 checkType(m2, getRuntimeType(m1), false); 246 checkType(m2, runtimeType(m1), false);
247 checkType(m2, Map$(String, String), false); 247 checkType(m2, Map$(String, String), false);
248 248
249 // null is! Map 249 // null is! Map
250 checkType(null, Map, false); 250 checkType(null, Map, false);
251 251
252 // Raw generic types 252 // Raw generic types
253 checkType(m5, Map); 253 checkType(m5, Map);
254 checkType(m4, Map); 254 checkType(m4, Map);
255 }); 255 });
256 256
257 test('generic and inheritance', () => { 257 test('generic and inheritance', () => {
258 let aaraw = new AA(); 258 let aaraw = new AA();
259 let aarawtype = getRuntimeType(aaraw); 259 let aarawtype = runtimeType(aaraw);
260 let aadynamic = new (AA$(dynamic, dynamic))(); 260 let aadynamic = new (AA$(dynamic, dynamic))();
261 let aadynamictype = getRuntimeType(aadynamic); 261 let aadynamictype = runtimeType(aadynamic);
262 let aa = new (AA$(String, List))(); 262 let aa = new (AA$(String, List))();
263 let aatype = getRuntimeType(aa); 263 let aatype = runtimeType(aa);
264 let bb = new (BB$(String, List))(); 264 let bb = new (BB$(String, List))();
265 let bbtype = getRuntimeType(bb); 265 let bbtype = runtimeType(bb);
266 let cc = new CC(); 266 let cc = new CC();
267 let cctype = getRuntimeType(cc); 267 let cctype = runtimeType(cc);
268 // We don't allow constructing bad types. 268 // We don't allow constructing bad types.
269 // This was AA<String> in Dart (wrong number of type args). 269 // This was AA<String> in Dart (wrong number of type args).
270 let aabad = new (AA$(dart.dynamic, dart.dynamic))(); 270 let aabad = new (AA$(dart.dynamic, dart.dynamic))();
271 let aabadtype = getRuntimeType(aabad); 271 let aabadtype = runtimeType(aabad);
272 272
273 expect(isGroundType(aatype), false); 273 expect(isGroundType(aatype), false);
274 expect(isGroundType(AA$(String, List)), false); 274 expect(isGroundType(AA$(String, List)), false);
275 expect(isGroundType(bbtype), false); 275 expect(isGroundType(bbtype), false);
276 expect(isGroundType(BB$(String, List)), false); 276 expect(isGroundType(BB$(String, List)), false);
277 expect(isGroundType(cctype), true); 277 expect(isGroundType(cctype), true);
278 expect(isGroundType(CC), true); 278 expect(isGroundType(CC), true);
279 checkType(cc, aatype, false); 279 checkType(cc, aatype, false);
280 checkType(cc, AA$(String, List), false); 280 checkType(cc, AA$(String, List), false);
281 checkType(cc, bbtype); 281 checkType(cc, bbtype);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 checkType(bar3, functionType(B, [B, String])); 331 checkType(bar3, functionType(B, [B, String]));
332 checkType(bar4, Foo, false); 332 checkType(bar4, Foo, false);
333 // TODO(vsm): Revisit. bar4 is (B, *) -> B. Perhaps it should be treated a s top for a reified object. 333 // TODO(vsm): Revisit. bar4 is (B, *) -> B. Perhaps it should be treated a s top for a reified object.
334 checkType(bar4, functionType(B, [B, String]), false); 334 checkType(bar4, functionType(B, [B, String]), false);
335 checkType(bar5, Foo); 335 checkType(bar5, Foo);
336 checkType(bar5, functionType(B, [B, String])); 336 checkType(bar5, functionType(B, [B, String]));
337 checkType(bar6, Foo, false); 337 checkType(bar6, Foo, false);
338 checkType(bar6, functionType(B, [B, String]), false); 338 checkType(bar6, functionType(B, [B, String]), false);
339 checkType(bar7, Foo); 339 checkType(bar7, Foo);
340 checkType(bar7, functionType(B, [B, String])); 340 checkType(bar7, functionType(B, [B, String]));
341 checkType(bar7, getRuntimeType(bar6)); 341 checkType(bar7, runtimeType(bar6));
342 checkType(bar8, Foo); 342 checkType(bar8, Foo);
343 checkType(bar8, functionType(B, [B, String])); 343 checkType(bar8, functionType(B, [B, String]));
344 checkType(bar8, getRuntimeType(bar6), false); 344 checkType(bar8, runtimeType(bar6), false);
345 checkType(bar7, getRuntimeType(bar8), false); 345 checkType(bar7, runtimeType(bar8), false);
346 checkType(bar8, getRuntimeType(bar7), false); 346 checkType(bar8, runtimeType(bar7), false);
347 347
348 // Parameterized typedefs 348 // Parameterized typedefs
349 expect(isGroundType(FuncG), true); 349 expect(isGroundType(FuncG), true);
350 expect(isGroundType(FuncG$(B, String)), false); 350 expect(isGroundType(FuncG$(B, String)), false);
351 checkType(bar1, FuncG$(B, String), false); 351 checkType(bar1, FuncG$(B, String), false);
352 checkType(bar3, FuncG$(B, String)); 352 checkType(bar3, FuncG$(B, String));
353 }); 353 });
354
355 test('Object members', () => {
356 let nullHash = dart.hashCode(null);
357 assert.equal(nullHash, 0);
358 let nullString = dart.toString(null);
359 assert.equal(nullString, 'null');
360 let nullType = dart.runtimeType(null);
361 assert.equal(nullType, core.Null);
362
363 let map = new Map();
364 let mapHash = dart.hashCode(map);
365 checkType(mapHash, core.int);
366 assert.equal(mapHash, map.hashCode);
367
368 let mapString = dart.toString(map);
369 assert.equal(mapString, map.toString());
370 checkType(mapString, core.String);
371 let mapType = dart.runtimeType(map);
372 assert.equal(mapType, map.runtimeType);
373
374 let str = "A string";
375 let strHash = dart.hashCode(str);
376 checkType(strHash, core.int);
377
378 let strString = dart.toString(str);
379 checkType(strString, core.String);
380 assert.equal(str, strString);
381 let strType = dart.runtimeType(str);
382 assert.equal(strType, core.String);
383
384 let n = 42;
385 let intHash = dart.hashCode(n);
386 checkType(intHash, core.int);
387
388 let intString = dart.toString(n);
389 assert.equal(intString, '42');
390 let intType = dart.runtimeType(n);
391 assert.equal(intType, core.int);
392 });
354 }); 393 });
OLDNEW
« no previous file with comments | « lib/src/utils.dart ('k') | test/codegen/expect/misc.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698