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

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

Issue 1944483002: Redo how Type objects are exposed from DDC. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: More tweaks. Created 4 years, 7 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/compiler/code_generator.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 var dart_sdk = dart_library.import('dart_sdk'); 6 var dart_sdk = dart_library.import('dart_sdk');
7 var core = dart_sdk.core; 7 var core = dart_sdk.core;
8 var collection = dart_sdk.collection; 8 var collection = dart_sdk.collection;
9 var dart = dart_sdk.dart; 9 var dart = dart_sdk.dart;
10 var dartx = dart.dartx; 10 var dartx = dart.dartx;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 suite('instanceOf', () => { 112 suite('instanceOf', () => {
113 "use strict"; 113 "use strict";
114 114
115 let expect = assert.equal; 115 let expect = assert.equal;
116 let isGroundType = dart.isGroundType; 116 let isGroundType = dart.isGroundType;
117 let generic = dart.generic; 117 let generic = dart.generic;
118 let intIsNonNullable = false; 118 let intIsNonNullable = false;
119 let cast = dart.as; 119 let cast = dart.as;
120 let instanceOf = dart.is; 120 let instanceOf = dart.is;
121 let strongInstanceOf = dart.strongInstanceOf; 121 let strongInstanceOf = dart.strongInstanceOf;
122 let runtimeType = dart.realRuntimeType; 122 let getReifiedType = dart.getReifiedType;
123 let functionType = dart.functionType; 123 let functionType = dart.functionType;
124 let typedef = dart.typedef; 124 let typedef = dart.typedef;
125 let isSubtype = dart.isSubtype; 125 let isSubtype = dart.isSubtype;
126 126
127 let Object = core.Object; 127 let Object = core.Object;
128 let String = core.String; 128 let String = core.String;
129 let dynamic = dart.dynamic; 129 let dynamic = dart.dynamic;
130 let List = core.List; 130 let List = core.List;
131 let Map = core.Map; 131 let Map = core.Map;
132 let Map$ = core.Map$; 132 let Map$ = core.Map$;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if (!strongOnly) { 206 if (!strongOnly) {
207 expect(instanceOf(x, type), expectedTrue); 207 expect(instanceOf(x, type), expectedTrue);
208 } else { 208 } else {
209 assert.throws(() => instanceOf(x, type), dart.StrongModeError); 209 assert.throws(() => instanceOf(x, type), dart.StrongModeError);
210 expect(strongInstanceOf(x, type), expectedTrue); 210 expect(strongInstanceOf(x, type), expectedTrue);
211 } 211 }
212 } 212 }
213 213
214 test('int', () => { 214 test('int', () => {
215 expect(isGroundType(int), true); 215 expect(isGroundType(int), true);
216 expect(isGroundType(runtimeType(5)), true); 216 expect(isGroundType(getReifiedType(5)), true);
217 217
218 checkType(5, int); 218 checkType(5, int);
219 checkType(5, dynamic); 219 checkType(5, dynamic);
220 checkType(5, Object); 220 checkType(5, Object);
221 checkType(5, num); 221 checkType(5, num);
222 222
223 checkType(5, bool, false); 223 checkType(5, bool, false);
224 checkType(5, String, false); 224 checkType(5, String, false);
225 225
226 expect(cast(5, int), 5); 226 expect(cast(5, int), 5);
(...skipping 26 matching lines...) Expand all
253 checkType(null, core.String, false); 253 checkType(null, core.String, false);
254 checkType(null, core.int, false); 254 checkType(null, core.int, false);
255 checkType(null, Map, false); 255 checkType(null, Map, false);
256 checkType(void 0, core.Null); 256 checkType(void 0, core.Null);
257 checkType(void 0, core.Object); 257 checkType(void 0, core.Object);
258 checkType(void 0, dart.dynamic); 258 checkType(void 0, dart.dynamic);
259 }); 259 });
260 260
261 test('String', () => { 261 test('String', () => {
262 expect(isGroundType(String), true); 262 expect(isGroundType(String), true);
263 expect(isGroundType(runtimeType("foo")), true); 263 expect(isGroundType(getReifiedType("foo")), true);
264 checkType("foo", String); 264 checkType("foo", String);
265 checkType("foo", Object); 265 checkType("foo", Object);
266 checkType("foo", dynamic); 266 checkType("foo", dynamic);
267 267
268 expect(cast(null, String), null); 268 expect(cast(null, String), null);
269 }); 269 });
270 270
271 test('Map', () => { 271 test('Map', () => {
272 let m1 = new (Map$(String, String))(); 272 let m1 = new (Map$(String, String))();
273 let m2 = new (Map$(Object, Object))(); 273 let m2 = new (Map$(Object, Object))();
274 let m3 = new Map(); 274 let m3 = new Map();
275 let m4 = new (collection.HashMap$(dart.dynamic, dart.dynamic))(); 275 let m4 = new (collection.HashMap$(dart.dynamic, dart.dynamic))();
276 let m5 = new collection.LinkedHashMap(); 276 let m5 = new collection.LinkedHashMap();
277 let m6 = new (Map$(String, dart.dynamic))(); 277 let m6 = new (Map$(String, dart.dynamic))();
278 278
279 279
280 expect(isGroundType(Map), true); 280 expect(isGroundType(Map), true);
281 expect(isGroundType(runtimeType(m1)), false); 281 expect(isGroundType(getReifiedType(m1)), false);
282 expect(isGroundType(Map$(String, String)), false); 282 expect(isGroundType(Map$(String, String)), false);
283 expect(isGroundType(runtimeType(m2)), true); 283 expect(isGroundType(getReifiedType(m2)), true);
284 expect(isGroundType(Map$(Object, Object)), true); 284 expect(isGroundType(Map$(Object, Object)), true);
285 expect(isGroundType(runtimeType(m3)), true); 285 expect(isGroundType(getReifiedType(m3)), true);
286 expect(isGroundType(Map), true); 286 expect(isGroundType(Map), true);
287 expect(isGroundType(runtimeType(m4)), true); 287 expect(isGroundType(getReifiedType(m4)), true);
288 expect(isGroundType(collection.HashMap$(dynamic, dynamic)), true); 288 expect(isGroundType(collection.HashMap$(dynamic, dynamic)), true);
289 expect(isGroundType(runtimeType(m5)), true); 289 expect(isGroundType(getReifiedType(m5)), true);
290 expect(isGroundType(collection.LinkedHashMap), true); 290 expect(isGroundType(collection.LinkedHashMap), true);
291 expect(isGroundType(collection.LinkedHashMap), true); 291 expect(isGroundType(collection.LinkedHashMap), true);
292 292
293 // Map<T1,T2> <: Map 293 // Map<T1,T2> <: Map
294 checkType(m1, Map); 294 checkType(m1, Map);
295 checkType(m1, Object); 295 checkType(m1, Object);
296 296
297 // Instance of self 297 // Instance of self
298 checkType(m1, runtimeType(m1)); 298 checkType(m1, getReifiedType(m1));
299 checkType(m1, Map$(String, String)); 299 checkType(m1, Map$(String, String));
300 300
301 // Covariance on generics 301 // Covariance on generics
302 checkType(m1, runtimeType(m2)); 302 checkType(m1, getReifiedType(m2));
303 checkType(m1, Map$(Object, Object)); 303 checkType(m1, Map$(Object, Object));
304 304
305 // No contravariance on generics. 305 // No contravariance on generics.
306 checkType(m2, runtimeType(m1), false, true); 306 checkType(m2, getReifiedType(m1), false, true);
307 checkType(m2, Map$(String, String), false, true); 307 checkType(m2, Map$(String, String), false, true);
308 308
309 // null is! Map 309 // null is! Map
310 checkType(null, Map, false); 310 checkType(null, Map, false);
311 311
312 // Raw generic types 312 // Raw generic types
313 checkType(m5, Map); 313 checkType(m5, Map);
314 checkType(m4, Map); 314 checkType(m4, Map);
315 315
316 // Is checks 316 // Is checks
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 isSubtype(getType(C), dart.functionType(C, [core.String]), false); 351 isSubtype(getType(C), dart.functionType(C, [core.String]), false);
352 isSubtype(getType(C, 'C'), dart.functionType(C, [core.int])); 352 isSubtype(getType(C, 'C'), dart.functionType(C, [core.int]));
353 isSubtype(getType(C, 'C'), dart.functionType(C, [core.String]), false); 353 isSubtype(getType(C, 'C'), dart.functionType(C, [core.String]), false);
354 isSubtype(getType(C, 'named'), dart.functionType(C, [core.int, core.int])); 354 isSubtype(getType(C, 'named'), dart.functionType(C, [core.int, core.int]));
355 isSubtype(getType(C, 'named'), 355 isSubtype(getType(C, 'named'),
356 dart.functionType(C, [core.int, core.String]), false); 356 dart.functionType(C, [core.int, core.String]), false);
357 }); 357 });
358 358
359 test('generic and inheritance', () => { 359 test('generic and inheritance', () => {
360 let aaraw = new AA(); 360 let aaraw = new AA();
361 let aarawtype = runtimeType(aaraw); 361 let aarawtype = getReifiedType(aaraw);
362 let aadynamic = new (AA$(dynamic, dynamic))(); 362 let aadynamic = new (AA$(dynamic, dynamic))();
363 let aadynamictype = runtimeType(aadynamic); 363 let aadynamictype = getReifiedType(aadynamic);
364 let aa = new (AA$(String, List))(); 364 let aa = new (AA$(String, List))();
365 let aatype = runtimeType(aa); 365 let aatype = getReifiedType(aa);
366 let bb = new (BB$(String, List))(); 366 let bb = new (BB$(String, List))();
367 let bbtype = runtimeType(bb); 367 let bbtype = getReifiedType(bb);
368 let cc = new CC(); 368 let cc = new CC();
369 let cctype = runtimeType(cc); 369 let cctype = getReifiedType(cc);
370 // We don't allow constructing bad types. 370 // We don't allow constructing bad types.
371 // This was AA<String> in Dart (wrong number of type args). 371 // This was AA<String> in Dart (wrong number of type args).
372 let aabad = new (AA$(dart.dynamic, dart.dynamic))(); 372 let aabad = new (AA$(dart.dynamic, dart.dynamic))();
373 let aabadtype = runtimeType(aabad); 373 let aabadtype = getReifiedType(aabad);
374 374
375 expect(isGroundType(aatype), false); 375 expect(isGroundType(aatype), false);
376 expect(isGroundType(AA$(String, List)), false); 376 expect(isGroundType(AA$(String, List)), false);
377 expect(isGroundType(bbtype), false); 377 expect(isGroundType(bbtype), false);
378 expect(isGroundType(BB$(String, List)), false); 378 expect(isGroundType(BB$(String, List)), false);
379 expect(isGroundType(cctype), true); 379 expect(isGroundType(cctype), true);
380 expect(isGroundType(CC), true); 380 expect(isGroundType(CC), true);
381 checkType(cc, aatype, false, true); 381 checkType(cc, aatype, false, true);
382 checkType(cc, AA$(String, List), false, true); 382 checkType(cc, AA$(String, List), false, true);
383 checkType(cc, bbtype); 383 checkType(cc, bbtype);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 checkType(bar5, functionType(B, [B, String])); 464 checkType(bar5, functionType(B, [B, String]));
465 checkType(cls5, functionType(B, [B, String])); 465 checkType(cls5, functionType(B, [B, String]));
466 checkType(bar6, Foo, false, true); 466 checkType(bar6, Foo, false, true);
467 checkType(cls6, Foo, false, true); 467 checkType(cls6, Foo, false, true);
468 checkType(bar6, functionType(B, [B, String]), false, true); 468 checkType(bar6, functionType(B, [B, String]), false, true);
469 checkType(cls6, functionType(B, [B, String]), false, true); 469 checkType(cls6, functionType(B, [B, String]), false, true);
470 checkType(bar7, Foo); 470 checkType(bar7, Foo);
471 checkType(cls7, Foo); 471 checkType(cls7, Foo);
472 checkType(bar7, functionType(B, [B, String])); 472 checkType(bar7, functionType(B, [B, String]));
473 checkType(cls7, functionType(B, [B, String])); 473 checkType(cls7, functionType(B, [B, String]));
474 checkType(bar7, runtimeType(bar6)); 474 checkType(bar7, getReifiedType(bar6));
475 checkType(cls7, runtimeType(bar6)); 475 checkType(cls7, getReifiedType(bar6));
476 checkType(bar8, Foo); 476 checkType(bar8, Foo);
477 checkType(cls8, Foo); 477 checkType(cls8, Foo);
478 checkType(bar8, functionType(B, [B, String])); 478 checkType(bar8, functionType(B, [B, String]));
479 checkType(cls8, functionType(B, [B, String])); 479 checkType(cls8, functionType(B, [B, String]));
480 checkType(bar8, runtimeType(bar6), false, true); 480 checkType(bar8, getReifiedType(bar6), false, true);
481 checkType(cls8, runtimeType(bar6), false, true); 481 checkType(cls8, getReifiedType(bar6), false, true);
482 checkType(bar7, runtimeType(bar8), false, true); 482 checkType(bar7, getReifiedType(bar8), false, true);
483 checkType(cls7, runtimeType(bar8), false, true); 483 checkType(cls7, getReifiedType(bar8), false, true);
484 checkType(bar8, runtimeType(bar7), false, true); 484 checkType(bar8, getReifiedType(bar7), false, true);
485 checkType(cls8, runtimeType(bar7), false, true); 485 checkType(cls8, getReifiedType(bar7), false, true);
486 486
487 // Parameterized typedefs 487 // Parameterized typedefs
488 expect(isGroundType(FuncG), true); 488 expect(isGroundType(FuncG), true);
489 expect(isGroundType(FuncG$(B, String)), false); 489 expect(isGroundType(FuncG$(B, String)), false);
490 checkType(bar1, FuncG$(B, String), false, true); 490 checkType(bar1, FuncG$(B, String), false, true);
491 checkType(cls1, FuncG$(B, String), false, true); 491 checkType(cls1, FuncG$(B, String), false, true);
492 checkType(bar3, FuncG$(B, String)); 492 checkType(bar3, FuncG$(B, String));
493 checkType(cls3, FuncG$(B, String)); 493 checkType(cls3, FuncG$(B, String));
494 }); 494 });
495 495
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 var m = dart.bind(obj, 'm'); 740 var m = dart.bind(obj, 'm');
741 checkType(m, dart.functionType(core.Object, [core.int])); 741 checkType(m, dart.functionType(core.Object, [core.int]));
742 checkType(m, dart.functionType(core.int, [core.int]), false, true); 742 checkType(m, dart.functionType(core.int, [core.int]), false, true);
743 }); 743 });
744 744
745 test('Object members', () => { 745 test('Object members', () => {
746 let nullHash = dart.hashCode(null); 746 let nullHash = dart.hashCode(null);
747 assert.equal(nullHash, 0); 747 assert.equal(nullHash, 0);
748 let nullString = dart.toString(null); 748 let nullString = dart.toString(null);
749 assert.equal(nullString, 'null'); 749 assert.equal(nullString, 'null');
750 let nullType = dart.runtimeType(null);
751 assert.equal(nullType, core.Null);
752 750
753 let map = new Map(); 751 let map = new Map();
754 let mapHash = dart.hashCode(map); 752 let mapHash = dart.hashCode(map);
755 checkType(mapHash, core.int); 753 checkType(mapHash, core.int);
756 assert.equal(mapHash, map.hashCode); 754 assert.equal(mapHash, map.hashCode);
757 755
758 let mapString = dart.toString(map); 756 let mapString = dart.toString(map);
759 assert.equal(mapString, map.toString()); 757 assert.equal(mapString, map.toString());
760 checkType(mapString, core.String); 758 checkType(mapString, core.String);
761 let mapType = dart.runtimeType(map);
762 assert.equal(mapType, map.runtimeType);
763 759
764 let str = "A string"; 760 let str = "A string";
765 let strHash = dart.hashCode(str); 761 let strHash = dart.hashCode(str);
766 checkType(strHash, core.int); 762 checkType(strHash, core.int);
767 763
768 let strString = dart.toString(str); 764 let strString = dart.toString(str);
769 checkType(strString, core.String); 765 checkType(strString, core.String);
770 assert.equal(str, strString); 766 assert.equal(str, strString);
771 let strType = dart.runtimeType(str);
772 assert.equal(strType, core.String);
773 767
774 let n = 42; 768 let n = 42;
775 let intHash = dart.hashCode(n); 769 let intHash = dart.hashCode(n);
776 checkType(intHash, core.int); 770 checkType(intHash, core.int);
777 771
778 let intString = dart.toString(n); 772 let intString = dart.toString(n);
779 assert.equal(intString, '42'); 773 assert.equal(intString, '42');
780 let intType = dart.runtimeType(n);
781 assert.equal(intType, core.int);
782 }); 774 });
783 }); 775 });
784 776
785 suite('primitives', function() { 777 suite('primitives', function() {
786 'use strict'; 778 'use strict';
787 779
788 test('fixed length list', () => { 780 test('fixed length list', () => {
789 let list = new core.List(10); 781 let list = new core.List(10);
790 list[0] = 42; 782 list[0] = 42;
791 assert.throws(() => list.add(42)); 783 assert.throws(() => list.add(42));
792 }); 784 });
793 }); 785 });
OLDNEW
« no previous file with comments | « lib/src/compiler/code_generator.dart ('k') | test/codegen/expect/misc.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698