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

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: 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
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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 var m = dart.bind(obj, 'm'); 741 var m = dart.bind(obj, 'm');
742 checkType(m, dart.functionType(core.Object, [core.int])); 742 checkType(m, dart.functionType(core.Object, [core.int]));
743 checkType(m, dart.functionType(core.int, [core.int]), false, true); 743 checkType(m, dart.functionType(core.int, [core.int]), false, true);
744 }); 744 });
745 745
746 test('Object members', () => { 746 test('Object members', () => {
747 let nullHash = dart.hashCode(null); 747 let nullHash = dart.hashCode(null);
748 assert.equal(nullHash, 0); 748 assert.equal(nullHash, 0);
749 let nullString = dart.toString(null); 749 let nullString = dart.toString(null);
750 assert.equal(nullString, 'null'); 750 assert.equal(nullString, 'null');
751 let nullType = dart.runtimeType(null);
752 assert.equal(nullType, core.Null);
753 751
754 let map = new Map(); 752 let map = new Map();
755 let mapHash = dart.hashCode(map); 753 let mapHash = dart.hashCode(map);
756 checkType(mapHash, core.int); 754 checkType(mapHash, core.int);
757 assert.equal(mapHash, map.hashCode); 755 assert.equal(mapHash, map.hashCode);
758 756
759 let mapString = dart.toString(map); 757 let mapString = dart.toString(map);
760 assert.equal(mapString, map.toString()); 758 assert.equal(mapString, map.toString());
761 checkType(mapString, core.String); 759 checkType(mapString, core.String);
762 let mapType = dart.runtimeType(map);
763 assert.equal(mapType, map.runtimeType);
764 760
765 let str = "A string"; 761 let str = "A string";
766 let strHash = dart.hashCode(str); 762 let strHash = dart.hashCode(str);
767 checkType(strHash, core.int); 763 checkType(strHash, core.int);
768 764
769 let strString = dart.toString(str); 765 let strString = dart.toString(str);
770 checkType(strString, core.String); 766 checkType(strString, core.String);
771 assert.equal(str, strString); 767 assert.equal(str, strString);
772 let strType = dart.runtimeType(str);
773 assert.equal(strType, core.String);
774 768
775 let n = 42; 769 let n = 42;
776 let intHash = dart.hashCode(n); 770 let intHash = dart.hashCode(n);
777 checkType(intHash, core.int); 771 checkType(intHash, core.int);
778 772
779 let intString = dart.toString(n); 773 let intString = dart.toString(n);
780 assert.equal(intString, '42'); 774 assert.equal(intString, '42');
781 let intType = dart.runtimeType(n);
782 assert.equal(intType, core.int);
783 }); 775 });
784 }); 776 });
785 777
786 suite('primitives', function() { 778 suite('primitives', function() {
787 'use strict'; 779 'use strict';
788 780
789 test('fixed length list', () => { 781 test('fixed length list', () => {
790 let list = new core.List(10); 782 let list = new core.List(10);
791 list[0] = 42; 783 list[0] = 42;
792 assert.throws(() => list.add(42)); 784 assert.throws(() => list.add(42));
793 }); 785 });
794 }); 786 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698