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

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

Issue 2996573002: fix #28988, remove throw on Dart1 incompatible is-checks for dartdevc (Closed)
Patch Set: Created 3 years, 4 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 define(['dart_sdk'], function(dart_sdk) { 5 define(['dart_sdk'], function(dart_sdk) {
6 const assert = chai.assert; 6 const assert = chai.assert;
7 const async = dart_sdk.async; 7 const async = dart_sdk.async;
8 const core = dart_sdk.core; 8 const core = dart_sdk.core;
9 const collection = dart_sdk.collection; 9 const collection = dart_sdk.collection;
10 const dart = dart_sdk.dart; 10 const dart = dart_sdk.dart;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 let l = dart_sdk._interceptors.JSArray$(core.int).of([1, 2, 3]); 136 let l = dart_sdk._interceptors.JSArray$(core.int).of([1, 2, 3]);
137 let s = l[dartx.join](); 137 let s = l[dartx.join]();
138 assert.equal(s, '123'); 138 assert.equal(s, '123');
139 }); 139 });
140 }); 140 });
141 141
142 142
143 suite('instanceOf', () => { 143 suite('instanceOf', () => {
144 "use strict"; 144 "use strict";
145 145
146 setup(() => {
147 dart_sdk.dart.failForWeakModeIsChecks(true);
148 });
149
150 teardown(() => {
151 dart_sdk.dart.failForWeakModeIsChecks(false);
152 });
153
154 let expect = assert.equal; 146 let expect = assert.equal;
155 let isGroundType = dart.isGroundType;
156 let generic = dart.generic; 147 let generic = dart.generic;
157 let intIsNonNullable = false; 148 let intIsNonNullable = false;
158 let cast = dart.as; 149 let cast = dart.as;
159 let instanceOf = dart.is; 150 let instanceOf = dart.is;
160 let strongInstanceOf = dart.strongInstanceOf; 151 let strongInstanceOf = dart.strongInstanceOf;
161 let getReifiedType = dart.getReifiedType; 152 let getReifiedType = dart.getReifiedType;
162 let fnTypeFuzzy = dart.fnTypeFuzzy; 153 let fnTypeFuzzy = dart.fnTypeFuzzy;
163 let typedef = dart.typedef; 154 let typedef = dart.typedef;
164 let isSubtype = dart.isSubtype; 155 let isSubtype = dart.isSubtype;
165 156
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 let cls6 = dart.fn((b, s, o) => { return null; }, 241 let cls6 = dart.fn((b, s, o) => { return null; },
251 dart.fnType(B, [B, String, String])); 242 dart.fnType(B, [B, String, String]));
252 243
253 let cls7 = dart.fn((b, s, o) => { return null; }, 244 let cls7 = dart.fn((b, s, o) => { return null; },
254 dart.fnType(B, [B, String], [Object])); 245 dart.fnType(B, [B, String], [Object]));
255 246
256 let cls8 = 247 let cls8 =
257 dart.fn((b, s, o) => { return null; }, 248 dart.fn((b, s, o) => { return null; },
258 dart.fnType(B, [B, String], {p: Object})); 249 dart.fnType(B, [B, String], {p: Object}));
259 250
260 function checkType(x, type, expectedTrue, strongOnly) { 251 function checkType(x, type, expectedTrue, strongOnly) {
Leaf 2017/08/05 02:24:27 Is strongOnly dead now?
Jennifer Messerly 2017/08/07 23:30:53 Done.
261 if (expectedTrue === undefined) expectedTrue = true; 252 if (expectedTrue === undefined) expectedTrue = true;
262 if (strongOnly === undefined) strongOnly = false; 253 expect(instanceOf(x, type), expectedTrue,
263 if (!strongOnly) { 254 '"' + x + '" ' +
264 assert.doesNotThrow(() => instanceOf(x, type)); 255 (expectedTrue ? 'should' : 'should not') +
265 expect(instanceOf(x, type), expectedTrue, 256 ' be an instance of "' + dart.typeName(type) + '"');
266 '"' + x + '" ' +
267 (expectedTrue ? 'should' : 'should not') +
268 ' be an instance of "' + dart.typeName(type) + '"');
269 } else {
270 assert.throws(() => instanceOf(x, type), dart.StrongModeError);
271 expect(expectedTrue, false);
272 expect(strongInstanceOf(x, type), null);
273 }
274 } 257 }
275 258
276 test('int', () => { 259 test('int', () => {
277 expect(isGroundType(int), true);
278 expect(isGroundType(getReifiedType(5)), true);
279
280 checkType(5, int); 260 checkType(5, int);
281 checkType(5, dynamic); 261 checkType(5, dynamic);
282 checkType(5, Object); 262 checkType(5, Object);
283 checkType(5, num); 263 checkType(5, num);
284 264
285 checkType(5, bool, false); 265 checkType(5, bool, false);
286 checkType(5, String, false); 266 checkType(5, String, false);
287 267
288 expect(cast(5, int), 5); 268 expect(cast(5, int), 5);
289 if (intIsNonNullable) { 269 if (intIsNonNullable) {
290 expect(() => cast(null, int), throws); 270 expect(() => cast(null, int), throws);
291 } else { 271 } else {
292 expect(cast(null, int), null); 272 expect(cast(null, int), null);
293 } 273 }
294 }); 274 });
295 275
296 test('dynamic', () => { 276 test('dynamic', () => {
297 expect(isGroundType(dynamic), true);
298 checkType(new Object.new(), dynamic); 277 checkType(new Object.new(), dynamic);
299 checkType(null, dynamic); 278 checkType(null, dynamic);
300 279
301 expect(cast(null, dynamic), null); 280 expect(cast(null, dynamic), null);
302 }); 281 });
303 282
304 test('Object', () => { 283 test('Object', () => {
305 expect(isGroundType(Object), true);
306 checkType(new Object.new(), dynamic); 284 checkType(new Object.new(), dynamic);
307 checkType(null, Object); 285 checkType(null, Object);
308 286
309 expect(cast(null, Object), null); 287 expect(cast(null, Object), null);
310 }); 288 });
311 289
312 test('null', () => { 290 test('null', () => {
313 // Object, dynamic cases are already handled above. 291 // Object, dynamic cases are already handled above.
314 checkType(null, core.Null); 292 checkType(null, core.Null);
315 checkType(null, core.String, false); 293 checkType(null, core.String, false);
316 checkType(null, core.int, false); 294 checkType(null, core.int, false);
317 checkType(null, Map, false); 295 checkType(null, Map, false);
318 checkType(void 0, core.Null); 296 checkType(void 0, core.Null);
319 checkType(void 0, core.Object); 297 checkType(void 0, core.Object);
320 checkType(void 0, dart.dynamic); 298 checkType(void 0, dart.dynamic);
321 }); 299 });
322 300
323 test('String', () => { 301 test('String', () => {
324 expect(isGroundType(String), true);
325 expect(isGroundType(getReifiedType("foo")), true);
326 checkType("foo", String); 302 checkType("foo", String);
327 checkType("foo", Object); 303 checkType("foo", Object);
328 checkType("foo", dynamic); 304 checkType("foo", dynamic);
329 305
330 expect(cast(null, String), null); 306 expect(cast(null, String), null);
331 }); 307 });
332 308
333 test('FutureOr', () => { 309 test('FutureOr', () => {
334 let FutureOr = async.FutureOr$; 310 let FutureOr = async.FutureOr$;
335 311
(...skipping 12 matching lines...) Expand all
348 }); 324 });
349 325
350 test('Map', () => { 326 test('Map', () => {
351 let m1 = Map$(String, String).new(); 327 let m1 = Map$(String, String).new();
352 let m2 = Map$(Object, Object).new(); 328 let m2 = Map$(Object, Object).new();
353 let m3 = Map.new(); 329 let m3 = Map.new();
354 let m4 = collection.HashMap$(dart.dynamic, dart.dynamic).new(); 330 let m4 = collection.HashMap$(dart.dynamic, dart.dynamic).new();
355 let m5 = collection.LinkedHashMap.new(); 331 let m5 = collection.LinkedHashMap.new();
356 let m6 = Map$(String, dart.dynamic).new(); 332 let m6 = Map$(String, dart.dynamic).new();
357 333
358 expect(isGroundType(Map), true);
359 expect(isGroundType(getReifiedType(m1)), false);
360 expect(isGroundType(Map$(String, String)), false);
361 expect(isGroundType(getReifiedType(m2)), true);
362 expect(isGroundType(Map$(Object, Object)), true);
363 expect(isGroundType(getReifiedType(m3)), true);
364 expect(isGroundType(Map), true);
365 expect(isGroundType(getReifiedType(m4)), true);
366 expect(isGroundType(collection.HashMap$(dynamic, dynamic)), true);
367 expect(isGroundType(getReifiedType(m5)), true);
368 expect(isGroundType(collection.LinkedHashMap), true);
369 expect(isGroundType(collection.LinkedHashMap), true);
370
371 // Map<T1,T2> <: Map 334 // Map<T1,T2> <: Map
372 checkType(m1, Map); 335 checkType(m1, Map);
373 checkType(m1, Object); 336 checkType(m1, Object);
374 337
375 // Instance of self 338 // Instance of self
376 checkType(m1, getReifiedType(m1)); 339 checkType(m1, getReifiedType(m1));
377 checkType(m1, Map$(String, String)); 340 checkType(m1, Map$(String, String));
378 341
379 // Covariance on generics 342 // Covariance on generics
380 checkType(m1, getReifiedType(m2)); 343 checkType(m1, getReifiedType(m2));
381 checkType(m1, Map$(Object, Object)); 344 checkType(m1, Map$(Object, Object));
382 345
383 // No contravariance on generics. 346 // No contravariance on generics.
384 checkType(m2, getReifiedType(m1), false); 347 checkType(m2, getReifiedType(m1), false);
385 checkType(m2, Map$(String, String), false); 348 checkType(m2, Map$(String, String), false);
386 349
387 // null is! Map 350 // null is! Map
388 checkType(null, Map, false); 351 checkType(null, Map, false);
389 352
390 // Raw generic types 353 // Raw generic types
391 checkType(m5, Map); 354 checkType(m5, Map);
392 checkType(m4, Map); 355 checkType(m4, Map);
393 356
394 // Is checks 357 // Is checks
395 assert.throws(() => dart.is(m3, Map$(String, String)), 358 assert.isFalse(dart.is(m3, Map$(String, String)));
396 dart.StrongModeError); 359 assert.isFalse(dart.is(m6, Map$(String, String)));
397 assert.throws(() => dart.is(m6, Map$(String, String)),
398 dart.StrongModeError);
399 assert.isTrue(dart.is(m1, Map$(String, String))); 360 assert.isTrue(dart.is(m1, Map$(String, String)));
400 assert.isFalse(dart.is(m2, Map$(String, String))); 361 assert.isFalse(dart.is(m2, Map$(String, String)));
401 362
402 // As checks 363 // As checks
403 // TODO(vsm): Enable these. We're currently only logging warnings on 364 // TODO(vsm): Enable these. We're currently only logging warnings on
404 // StrongModeErrors. 365 // StrongModeErrors.
405 // assert.throws(() => dart.as(m3, Map$(String, String)), 366 // assert.throws(() => dart.as(m3, Map$(String, String)),
406 // dart.StrongModeError); 367 // dart.StrongModeError);
407 // assert.throws(() => dart.as(m6, Map$(String, String)), 368 // assert.throws(() => dart.as(m6, Map$(String, String)),
408 // dart.StrongModeError); 369 // dart.StrongModeError);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 let aatype = getReifiedType(aa); 402 let aatype = getReifiedType(aa);
442 let bb = new (BB$(String, List).new)(); 403 let bb = new (BB$(String, List).new)();
443 let bbtype = getReifiedType(bb); 404 let bbtype = getReifiedType(bb);
444 let cc = new CC.new(); 405 let cc = new CC.new();
445 let cctype = getReifiedType(cc); 406 let cctype = getReifiedType(cc);
446 // We don't allow constructing bad types. 407 // We don't allow constructing bad types.
447 // This was AA<String> in Dart (wrong number of type args). 408 // This was AA<String> in Dart (wrong number of type args).
448 let aabad = new (AA$(dart.dynamic, dart.dynamic).new)(); 409 let aabad = new (AA$(dart.dynamic, dart.dynamic).new)();
449 let aabadtype = getReifiedType(aabad); 410 let aabadtype = getReifiedType(aabad);
450 411
451 expect(isGroundType(aatype), false);
452 expect(isGroundType(AA$(String, List)), false);
453 expect(isGroundType(bbtype), false);
454 expect(isGroundType(BB$(String, List)), false);
455 expect(isGroundType(cctype), true);
456 expect(isGroundType(CC), true);
457 checkType(cc, aatype, false); 412 checkType(cc, aatype, false);
458 checkType(cc, AA$(String, List), false); 413 checkType(cc, AA$(String, List), false);
459 checkType(cc, bbtype); 414 checkType(cc, bbtype);
460 checkType(cc, BB$(String, List)); 415 checkType(cc, BB$(String, List));
461 checkType(aa, cctype, false); 416 checkType(aa, cctype, false);
462 checkType(aa, CC, false); 417 checkType(aa, CC, false);
463 checkType(aa, bbtype, false); 418 checkType(aa, bbtype, false);
464 checkType(aa, BB$(String, List), false); 419 checkType(aa, BB$(String, List), false);
465 checkType(bb, cctype, false); 420 checkType(bb, cctype, false);
466 checkType(bb, CC, false); 421 checkType(bb, CC, false);
467 checkType(aa, aabadtype); 422 checkType(aa, aabadtype);
468 checkType(aa, dynamic); 423 checkType(aa, dynamic);
469 checkType(aabad, aatype, false, true); 424 checkType(aabad, aatype, false);
470 checkType(aabad, AA$(String, List), false, true); 425 checkType(aabad, AA$(String, List), false);
471 checkType(aabad, aarawtype); 426 checkType(aabad, aarawtype);
472 checkType(aabad, AA); 427 checkType(aabad, AA);
473 checkType(aaraw, aabadtype); 428 checkType(aaraw, aabadtype);
474 checkType(aaraw, AA$(dart.dynamic, dart.dynamic)); 429 checkType(aaraw, AA$(dart.dynamic, dart.dynamic));
475 checkType(aaraw, aadynamictype); 430 checkType(aaraw, aadynamictype);
476 checkType(aaraw, AA$(dynamic, dynamic)); 431 checkType(aaraw, AA$(dynamic, dynamic));
477 checkType(aadynamic, aarawtype); 432 checkType(aadynamic, aarawtype);
478 checkType(aadynamic, AA); 433 checkType(aadynamic, AA);
479 }); 434 });
480 435
(...skipping 28 matching lines...) Expand all
509 checkType(fnTypeFuzzy(dynamic, [dynamic]), core.Type, true); 464 checkType(fnTypeFuzzy(dynamic, [dynamic]), core.Type, true);
510 checkType(core.Type, core.Type, true); 465 checkType(core.Type, core.Type, true);
511 466
512 checkType(3, core.Type, false); 467 checkType(3, core.Type, false);
513 checkType("hello", core.Type, false); 468 checkType("hello", core.Type, false);
514 }) 469 })
515 470
516 test('Functions', () => { 471 test('Functions', () => {
517 // - return type: Dart is bivariant. We're covariant. 472 // - return type: Dart is bivariant. We're covariant.
518 // - param types: Dart is bivariant. We're contravariant. 473 // - param types: Dart is bivariant. We're contravariant.
519 expect(isGroundType(Func2), true); 474 checkType(bar1, Foo, false);
520 expect(isGroundType(Foo), false); 475 checkType(cls1, Foo, false);
521 expect(isGroundType(fnTypeFuzzy(B, [B, String])), false); 476 checkType(bar1, fnTypeFuzzy(B, [B, String]), false);
522 checkType(bar1, Foo, false, true); 477 checkType(cls1, fnTypeFuzzy(B, [B, String]), false);
523 checkType(cls1, Foo, false, true); 478 checkType(bar2, Foo, false);
524 checkType(bar1, fnTypeFuzzy(B, [B, String]), false, true); 479 checkType(cls2, Foo, false);
525 checkType(cls1, fnTypeFuzzy(B, [B, String]), false, true); 480 checkType(bar2, fnTypeFuzzy(B, [B, String]), false);
526 checkType(bar2, Foo, false, true); 481 checkType(cls2, fnTypeFuzzy(B, [B, String]), false);
527 checkType(cls2, Foo, false, true);
528 checkType(bar2, fnTypeFuzzy(B, [B, String]), false, true);
529 checkType(cls2, fnTypeFuzzy(B, [B, String]), false, true);
530 checkType(bar3, Foo); 482 checkType(bar3, Foo);
531 checkType(cls3, Foo); 483 checkType(cls3, Foo);
532 checkType(bar3, fnTypeFuzzy(B, [B, String])); 484 checkType(bar3, fnTypeFuzzy(B, [B, String]));
533 checkType(cls3, fnTypeFuzzy(B, [B, String])); 485 checkType(cls3, fnTypeFuzzy(B, [B, String]));
534 checkType(bar4, Foo, true); 486 checkType(bar4, Foo, true);
535 checkType(cls4, Foo, true); 487 checkType(cls4, Foo, true);
536 checkType(bar4, fnTypeFuzzy(B, [B, String]), true); 488 checkType(bar4, fnTypeFuzzy(B, [B, String]), true);
537 checkType(cls4, fnTypeFuzzy(B, [B, String]), true); 489 checkType(cls4, fnTypeFuzzy(B, [B, String]), true);
538 checkType(bar5, Foo); 490 checkType(bar5, Foo);
539 checkType(cls5, Foo); 491 checkType(cls5, Foo);
(...skipping 14 matching lines...) Expand all
554 checkType(bar8, fnTypeFuzzy(B, [B, String])); 506 checkType(bar8, fnTypeFuzzy(B, [B, String]));
555 checkType(cls8, fnTypeFuzzy(B, [B, String])); 507 checkType(cls8, fnTypeFuzzy(B, [B, String]));
556 checkType(bar8, getReifiedType(bar6), false); 508 checkType(bar8, getReifiedType(bar6), false);
557 checkType(cls8, getReifiedType(bar6), false); 509 checkType(cls8, getReifiedType(bar6), false);
558 checkType(bar7, getReifiedType(bar8), false); 510 checkType(bar7, getReifiedType(bar8), false);
559 checkType(cls7, getReifiedType(bar8), false); 511 checkType(cls7, getReifiedType(bar8), false);
560 checkType(bar8, getReifiedType(bar7), false); 512 checkType(bar8, getReifiedType(bar7), false);
561 checkType(cls8, getReifiedType(bar7), false); 513 checkType(cls8, getReifiedType(bar7), false);
562 514
563 // Parameterized typedefs 515 // Parameterized typedefs
564 expect(isGroundType(FuncG), true); 516 checkType(bar1, FuncG$(B, String), false);
565 expect(isGroundType(FuncG$(B, String)), false); 517 checkType(cls1, FuncG$(B, String), false);
566 checkType(bar1, FuncG$(B, String), false, true);
567 checkType(cls1, FuncG$(B, String), false, true);
568 checkType(bar3, FuncG$(B, String)); 518 checkType(bar3, FuncG$(B, String));
569 checkType(cls3, FuncG$(B, String)); 519 checkType(cls3, FuncG$(B, String));
570 }); 520 });
571 521
572 test('dcall', () => { 522 test('dcall', () => {
573 function dd2d(x, y) {return x}; 523 function dd2d(x, y) {return x};
574 dart.fn(dd2d); 524 dart.fn(dd2d);
575 function ii2i(x, y) {return x}; 525 function ii2i(x, y) {return x};
576 dart.fn(ii2i, dart.fnType(core.int, [core.int, core.int])); 526 dart.fn(ii2i, dart.fnType(core.int, [core.int, core.int]));
577 function ii_2i(x, y) {return x}; 527 function ii_2i(x, y) {return x};
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 m: dart.fnType(core.Object, [core.int]), 751 m: dart.fnType(core.Object, [core.int]),
802 }) 752 })
803 }); 753 });
804 754
805 class O extends dart.mixin(Base, M1, M2) {} 755 class O extends dart.mixin(Base, M1, M2) {}
806 (O.new = function() {}).prototype = O.prototype; 756 (O.new = function() {}).prototype = O.prototype;
807 dart.setSignature(O, {}); 757 dart.setSignature(O, {});
808 var obj = new O.new(); 758 var obj = new O.new();
809 var m = dart.bind(obj, 'm'); 759 var m = dart.bind(obj, 'm');
810 checkType(m, dart.fnTypeFuzzy(core.Object, [core.int])); 760 checkType(m, dart.fnTypeFuzzy(core.Object, [core.int]));
811 checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false, true); 761 checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false);
812 762
813 // Test inherited signatures 763 // Test inherited signatures
814 class P extends O { 764 class P extends O {
815 m(x) {return x;}; 765 m(x) {return x;};
816 }; 766 };
817 (P.new = function() {}).prototype = P.prototype; 767 (P.new = function() {}).prototype = P.prototype;
818 dart.setSignature(P, {}); 768 dart.setSignature(P, {});
819 var obj = new P.new(); 769 var obj = new P.new();
820 var m = dart.bind(obj, 'm'); 770 var m = dart.bind(obj, 'm');
821 checkType(m, dart.fnTypeFuzzy(core.Object, [core.int])); 771 checkType(m, dart.fnTypeFuzzy(core.Object, [core.int]));
822 checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false, true); 772 checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false);
823 }); 773 });
824 774
825 test('Object members', () => { 775 test('Object members', () => {
826 let nullHash = dart.hashCode(null); 776 let nullHash = dart.hashCode(null);
827 assert.equal(nullHash, 0); 777 assert.equal(nullHash, 0);
828 let nullString = dart.toString(null); 778 let nullString = dart.toString(null);
829 assert.equal(nullString, 'null'); 779 assert.equal(nullString, 'null');
830 780
831 let map = Map.new(); 781 let map = Map.new();
832 let mapHash = dart.hashCode(map); 782 let mapHash = dart.hashCode(map);
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 list[0] = 42; 1242 list[0] = 42;
1293 assert.throws(() => list.add(42)); 1243 assert.throws(() => list.add(42));
1294 }); 1244 });
1295 1245
1296 test('toString on ES Symbol', () => { 1246 test('toString on ES Symbol', () => {
1297 let sym = Symbol('_foobar'); 1247 let sym = Symbol('_foobar');
1298 assert.equal(dart.toString(sym), 'Symbol(_foobar)'); 1248 assert.equal(dart.toString(sym), 'Symbol(_foobar)');
1299 }); 1249 });
1300 }); 1250 });
1301 }); 1251 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698