OLD | NEW |
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 let Map$ = core.Map$; | 171 let Map$ = core.Map$; |
172 let double = core.double; | 172 let double = core.double; |
173 let int = core.int; | 173 let int = core.int; |
174 let num = core.num; | 174 let num = core.num; |
175 let bool = core.bool; | 175 let bool = core.bool; |
176 | 176 |
177 class A {} | 177 class A {} |
178 class B extends A {} | 178 class B extends A {} |
179 class C extends B {} | 179 class C extends B {} |
180 | 180 |
181 let AA$ = generic((T, U) => class AA extends core.Object {}); | 181 let AA$ = generic((T, U) => { |
| 182 class AA extends core.Object {} |
| 183 (AA.new = function() {}).prototype = AA.prototype; |
| 184 return AA; |
| 185 }); |
182 let AA = AA$(); | 186 let AA = AA$(); |
183 let BB$ = generic((T, U) => class BB extends AA$(U, T) {}); | 187 let BB$ = generic((T, U) => { |
| 188 class BB extends AA$(U, T) {} |
| 189 (BB.new = function() {}).prototype = BB.prototype; |
| 190 return BB; |
| 191 }); |
184 let BB = BB$(); | 192 let BB = BB$(); |
185 class CC extends BB$(String, List) {} | 193 class CC extends BB$(String, List) {} |
| 194 (CC.new = function() {}).prototype = CC.prototype; |
186 | 195 |
187 let Func2 = typedef('Func2', () => fnTypeFuzzy(dynamic, [dynamic, dynamic]))
; | 196 let Func2 = typedef('Func2', () => fnTypeFuzzy(dynamic, [dynamic, dynamic]))
; |
188 let Foo = typedef('Foo', () => fnTypeFuzzy(B, [B, String])); | 197 let Foo = typedef('Foo', () => fnTypeFuzzy(B, [B, String])); |
189 | 198 |
190 let FuncG$ = generic((T, U) => typedef('FuncG', () => fnTypeFuzzy(T, [T, U])
)) | 199 let FuncG$ = generic((T, U) => typedef('FuncG', () => fnTypeFuzzy(T, [T, U])
)) |
191 let FuncG = FuncG$(); | 200 let FuncG = FuncG$(); |
192 | 201 |
193 // TODO(vsm): Revisit when we encode types on functions properly. | 202 // TODO(vsm): Revisit when we encode types on functions properly. |
194 // A bar1(C c, String s) => null; | 203 // A bar1(C c, String s) => null; |
195 function bar1(c, s) { return null; } | 204 function bar1(c, s) { return null; } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 expect(cast(5, int), 5); | 288 expect(cast(5, int), 5); |
280 if (intIsNonNullable) { | 289 if (intIsNonNullable) { |
281 expect(() => cast(null, int), throws); | 290 expect(() => cast(null, int), throws); |
282 } else { | 291 } else { |
283 expect(cast(null, int), null); | 292 expect(cast(null, int), null); |
284 } | 293 } |
285 }); | 294 }); |
286 | 295 |
287 test('dynamic', () => { | 296 test('dynamic', () => { |
288 expect(isGroundType(dynamic), true); | 297 expect(isGroundType(dynamic), true); |
289 checkType(new Object(), dynamic); | 298 checkType(new Object.new(), dynamic); |
290 checkType(null, dynamic); | 299 checkType(null, dynamic); |
291 | 300 |
292 expect(cast(null, dynamic), null); | 301 expect(cast(null, dynamic), null); |
293 }); | 302 }); |
294 | 303 |
295 test('Object', () => { | 304 test('Object', () => { |
296 expect(isGroundType(Object), true); | 305 expect(isGroundType(Object), true); |
297 checkType(new Object(), dynamic); | 306 checkType(new Object.new(), dynamic); |
298 checkType(null, Object); | 307 checkType(null, Object); |
299 | 308 |
300 expect(cast(null, Object), null); | 309 expect(cast(null, Object), null); |
301 }); | 310 }); |
302 | 311 |
303 test('null', () => { | 312 test('null', () => { |
304 // Object, dynamic cases are already handled above. | 313 // Object, dynamic cases are already handled above. |
305 checkType(null, core.Null); | 314 checkType(null, core.Null); |
306 checkType(null, core.String, false); | 315 checkType(null, core.String, false); |
307 checkType(null, core.int, false); | 316 checkType(null, core.int, false); |
(...skipping 24 matching lines...) Expand all Loading... |
332 assert.isTrue(dart.is(3, FutureOr(double))); | 341 assert.isTrue(dart.is(3, FutureOr(double))); |
333 assert.isFalse(dart.is(3.5, FutureOr(int))); | 342 assert.isFalse(dart.is(3.5, FutureOr(int))); |
334 assert.isTrue(dart.is(3.5, FutureOr(double))); | 343 assert.isTrue(dart.is(3.5, FutureOr(double))); |
335 | 344 |
336 assert.equal(dart.as(3, FutureOr(FutureOr(double))), 3); | 345 assert.equal(dart.as(3, FutureOr(FutureOr(double))), 3); |
337 assert.isTrue(dart.is(3, FutureOr(FutureOr(double)))); | 346 assert.isTrue(dart.is(3, FutureOr(FutureOr(double)))); |
338 | 347 |
339 }); | 348 }); |
340 | 349 |
341 test('Map', () => { | 350 test('Map', () => { |
342 let m1 = new (Map$(String, String))(); | 351 let m1 = Map$(String, String).new(); |
343 let m2 = new (Map$(Object, Object))(); | 352 let m2 = Map$(Object, Object).new(); |
344 let m3 = new Map(); | 353 let m3 = Map.new(); |
345 let m4 = new (collection.HashMap$(dart.dynamic, dart.dynamic))(); | 354 let m4 = collection.HashMap$(dart.dynamic, dart.dynamic).new(); |
346 let m5 = new collection.LinkedHashMap(); | 355 let m5 = collection.LinkedHashMap.new(); |
347 let m6 = new (Map$(String, dart.dynamic))(); | 356 let m6 = Map$(String, dart.dynamic).new(); |
348 | |
349 | 357 |
350 expect(isGroundType(Map), true); | 358 expect(isGroundType(Map), true); |
351 expect(isGroundType(getReifiedType(m1)), false); | 359 expect(isGroundType(getReifiedType(m1)), false); |
352 expect(isGroundType(Map$(String, String)), false); | 360 expect(isGroundType(Map$(String, String)), false); |
353 expect(isGroundType(getReifiedType(m2)), true); | 361 expect(isGroundType(getReifiedType(m2)), true); |
354 expect(isGroundType(Map$(Object, Object)), true); | 362 expect(isGroundType(Map$(Object, Object)), true); |
355 expect(isGroundType(getReifiedType(m3)), true); | 363 expect(isGroundType(getReifiedType(m3)), true); |
356 expect(isGroundType(Map), true); | 364 expect(isGroundType(Map), true); |
357 expect(isGroundType(getReifiedType(m4)), true); | 365 expect(isGroundType(getReifiedType(m4)), true); |
358 expect(isGroundType(collection.HashMap$(dynamic, dynamic)), true); | 366 expect(isGroundType(collection.HashMap$(dynamic, dynamic)), true); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 // dart.StrongModeError); | 406 // dart.StrongModeError); |
399 // assert.throws(() => dart.as(m6, Map$(String, String)), | 407 // assert.throws(() => dart.as(m6, Map$(String, String)), |
400 // dart.StrongModeError); | 408 // dart.StrongModeError); |
401 assert.equal(dart.as(m1, Map$(String, String)), m1); | 409 assert.equal(dart.as(m1, Map$(String, String)), m1); |
402 // assert.throws(() => dart.as(m2, Map$(String, String)), | 410 // assert.throws(() => dart.as(m2, Map$(String, String)), |
403 // dart.StrongModeError); | 411 // dart.StrongModeError); |
404 }); | 412 }); |
405 | 413 |
406 test('constructors', () => { | 414 test('constructors', () => { |
407 class C extends core.Object { | 415 class C extends core.Object { |
408 new(x) {}; | |
409 named(x, y) {}; | |
410 } | 416 } |
411 dart.defineNamedConstructor(C, 'named'); | 417 (C.new = function(x) {}).prototype = C.prototype; |
| 418 (C.named = function(x, y) {}).prototype = C.prototype; |
412 dart.setSignature(C, { | 419 dart.setSignature(C, { |
413 constructors: () => ({ | 420 constructors: () => ({ |
414 new: dart.fnType(C, [core.int]), | 421 new: dart.fnType(C, [core.int]), |
415 named: dart.fnType(C, [core.int, core.int]) | 422 named: dart.fnType(C, [core.int, core.int]) |
416 }) | 423 }) |
417 }); | 424 }); |
418 let getType = dart.classGetConstructorType; | 425 let getType = dart.classGetConstructorType; |
419 isSubtype(getType(C), dart.fnTypeFuzzy(C, [core.int])); | 426 isSubtype(getType(C), dart.fnTypeFuzzy(C, [core.int])); |
420 isSubtype(getType(C), dart.fnTypeFuzzy(C, [core.String]), false); | 427 isSubtype(getType(C), dart.fnTypeFuzzy(C, [core.String]), false); |
421 isSubtype(getType(C, 'new'), dart.fnTypeFuzzy(C, [core.int])); | 428 isSubtype(getType(C, 'new'), dart.fnTypeFuzzy(C, [core.int])); |
422 isSubtype(getType(C, 'new'), dart.fnTypeFuzzy(C, [core.String]), false); | 429 isSubtype(getType(C, 'new'), dart.fnTypeFuzzy(C, [core.String]), false); |
423 isSubtype(getType(C, 'named'), dart.fnTypeFuzzy(C, [core.int, core.int])); | 430 isSubtype(getType(C, 'named'), dart.fnTypeFuzzy(C, [core.int, core.int])); |
424 isSubtype(getType(C, 'named'), | 431 isSubtype(getType(C, 'named'), |
425 dart.fnTypeFuzzy(C, [core.int, core.String]), false); | 432 dart.fnTypeFuzzy(C, [core.int, core.String]), false); |
426 }); | 433 }); |
427 | 434 |
428 test('generic and inheritance', () => { | 435 test('generic and inheritance', () => { |
429 let aaraw = new AA(); | 436 let aaraw = new AA.new(); |
430 let aarawtype = getReifiedType(aaraw); | 437 let aarawtype = getReifiedType(aaraw); |
431 let aadynamic = new (AA$(dynamic, dynamic))(); | 438 let aadynamic = new (AA$(dynamic, dynamic).new)(); |
432 let aadynamictype = getReifiedType(aadynamic); | 439 let aadynamictype = getReifiedType(aadynamic); |
433 let aa = new (AA$(String, List))(); | 440 let aa = new (AA$(String, List).new)(); |
434 let aatype = getReifiedType(aa); | 441 let aatype = getReifiedType(aa); |
435 let bb = new (BB$(String, List))(); | 442 let bb = new (BB$(String, List).new)(); |
436 let bbtype = getReifiedType(bb); | 443 let bbtype = getReifiedType(bb); |
437 let cc = new CC(); | 444 let cc = new CC.new(); |
438 let cctype = getReifiedType(cc); | 445 let cctype = getReifiedType(cc); |
439 // We don't allow constructing bad types. | 446 // We don't allow constructing bad types. |
440 // This was AA<String> in Dart (wrong number of type args). | 447 // This was AA<String> in Dart (wrong number of type args). |
441 let aabad = new (AA$(dart.dynamic, dart.dynamic))(); | 448 let aabad = new (AA$(dart.dynamic, dart.dynamic).new)(); |
442 let aabadtype = getReifiedType(aabad); | 449 let aabadtype = getReifiedType(aabad); |
443 | 450 |
444 expect(isGroundType(aatype), false); | 451 expect(isGroundType(aatype), false); |
445 expect(isGroundType(AA$(String, List)), false); | 452 expect(isGroundType(AA$(String, List)), false); |
446 expect(isGroundType(bbtype), false); | 453 expect(isGroundType(bbtype), false); |
447 expect(isGroundType(BB$(String, List)), false); | 454 expect(isGroundType(BB$(String, List)), false); |
448 expect(isGroundType(cctype), true); | 455 expect(isGroundType(cctype), true); |
449 expect(isGroundType(CC), true); | 456 expect(isGroundType(CC), true); |
450 checkType(cc, aatype, false); | 457 checkType(cc, aatype, false); |
451 checkType(cc, AA$(String, List), false); | 458 checkType(cc, AA$(String, List), false); |
(...skipping 18 matching lines...) Expand all Loading... |
470 checkType(aadynamic, aarawtype); | 477 checkType(aadynamic, aarawtype); |
471 checkType(aadynamic, AA); | 478 checkType(aadynamic, AA); |
472 }); | 479 }); |
473 | 480 |
474 test('void', () => { | 481 test('void', () => { |
475 //checkType((x) => x, type((void _(x)) {})); | 482 //checkType((x) => x, type((void _(x)) {})); |
476 }); | 483 }); |
477 | 484 |
478 test('mixins', () => { | 485 test('mixins', () => { |
479 let c = collection; | 486 let c = collection; |
480 var s1 = new (c.SplayTreeSet$(String))(); | 487 var s1 = new (c.SplayTreeSet$(String).new)(); |
481 | 488 |
482 checkType(s1, c.IterableMixin); | 489 checkType(s1, c.IterableMixin); |
483 checkType(s1, c.IterableMixin$(String)); | 490 checkType(s1, c.IterableMixin$(String)); |
484 checkType(s1, c.IterableMixin$(int), false); | 491 checkType(s1, c.IterableMixin$(int), false); |
485 | 492 |
486 checkType(s1, c.SetMixin); | 493 checkType(s1, c.SetMixin); |
487 checkType(s1, c.SetMixin$(String)); | 494 checkType(s1, c.SetMixin$(String)); |
488 checkType(s1, c.SetMixin$(int), false); | 495 checkType(s1, c.SetMixin$(int), false); |
489 }); | 496 }); |
490 | 497 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 | 600 |
594 assert.throws(() => dart.dcall(i_i2i, 0, 1)); | 601 assert.throws(() => dart.dcall(i_i2i, 0, 1)); |
595 assert.throws(() => dart.dcall(i_i2i, "hello", "world")); | 602 assert.throws(() => dart.dcall(i_i2i, "hello", "world")); |
596 assert.equal(dart.dcall(i_i2i, 0), 0); | 603 assert.equal(dart.dcall(i_i2i, 0), 0); |
597 assert.throws(() => dart.dcall(i_i2i, 0, 1, 2)); | 604 assert.throws(() => dart.dcall(i_i2i, 0, 1, 2)); |
598 assert.equal(dart.dcall(i_i2i, 0, {extra: 3}), 0); | 605 assert.equal(dart.dcall(i_i2i, 0, {extra: 3}), 0); |
599 }); | 606 }); |
600 | 607 |
601 test('dsend', () => { | 608 test('dsend', () => { |
602 class Tester extends core.Object { | 609 class Tester extends core.Object { |
603 new() { | |
604 this.f = dart.fn(x => x, | |
605 dart.fnType(core.int, [core.int])); | |
606 this.me = this; | |
607 } | |
608 m(x, y) {return x;} | 610 m(x, y) {return x;} |
609 call(x) {return x;} | 611 call(x) {return x;} |
610 static s(x, y) { return x;} | 612 static s(x, y) { return x;} |
611 } | 613 } |
| 614 (Tester.new = function() { |
| 615 this.f = dart.fn(x => x, |
| 616 dart.fnType(core.int, [core.int])); |
| 617 this.me = this; |
| 618 }).prototype = Tester.prototype; |
612 dart.setSignature(Tester, { | 619 dart.setSignature(Tester, { |
613 methods: () => ({ | 620 methods: () => ({ |
614 m: dart.fnType(core.int, [core.int, core.int]), | 621 m: dart.fnType(core.int, [core.int, core.int]), |
615 call: dart.fnType(core.int, [core.int]) | 622 call: dart.fnType(core.int, [core.int]) |
616 }), | 623 }), |
617 statics: () => ({ | 624 statics: () => ({ |
618 s: dart.fnType(core.String, [core.String]) | 625 s: dart.fnType(core.String, [core.String]) |
619 }), | 626 }), |
620 names: ['s'] | 627 names: ['s'] |
621 }) | 628 }) |
622 let o = new Tester(); | 629 let o = new Tester.new(); |
623 | 630 |
624 // Method send | 631 // Method send |
625 assert.equal(dart.dsend(o, 'm', 3, 4), 3); | 632 assert.equal(dart.dsend(o, 'm', 3, 4), 3); |
626 assert.equal(dart.dsend(o, 'm', null, 4), null); | 633 assert.equal(dart.dsend(o, 'm', null, 4), null); |
627 assert.throws(() => dart.dsend(o, 'm', 3)); | 634 assert.throws(() => dart.dsend(o, 'm', 3)); |
628 assert.throws(() => dart.dsend(o, 'm', "hello", "world")); | 635 assert.throws(() => dart.dsend(o, 'm', "hello", "world")); |
629 assert.throws(() => dart.dsend(o, 'q', 3)); | 636 assert.throws(() => dart.dsend(o, 'q', 3)); |
630 | 637 |
631 // Method send through a field | 638 // Method send through a field |
632 assert.equal(dart.dsend(o, 'f', 3), 3); | 639 assert.equal(dart.dsend(o, 'f', 3), 3); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 checkType(i_i2i, | 718 checkType(i_i2i, |
712 dart.fnTypeFuzzy(core.int, [], {extra: core.int, | 719 dart.fnTypeFuzzy(core.int, [], {extra: core.int, |
713 also: core.int}), false); | 720 also: core.int}), false); |
714 checkType(i_i2i, | 721 checkType(i_i2i, |
715 dart.fnTypeFuzzy(core.int, [core.int], [core.int]), false); | 722 dart.fnTypeFuzzy(core.int, [core.int], [core.int]), false); |
716 }); | 723 }); |
717 | 724 |
718 test('Method tearoffs', () => { | 725 test('Method tearoffs', () => { |
719 let c = collection; | 726 let c = collection; |
720 // Tear off of an inherited method | 727 // Tear off of an inherited method |
721 let map = new (Map$(core.int, core.String))(); | 728 let map = Map$(core.int, core.String).new(); |
722 checkType(dart.bind(map, 'toString'), | 729 checkType(dart.bind(map, 'toString'), |
723 dart.fnTypeFuzzy(String, [])); | 730 dart.fnTypeFuzzy(String, [])); |
724 checkType(dart.bind(map, 'toString'), | 731 checkType(dart.bind(map, 'toString'), |
725 dart.fnTypeFuzzy(int, []), false, true); | 732 dart.fnTypeFuzzy(int, []), false, true); |
726 | 733 |
727 // Tear off of a method directly on the object | 734 // Tear off of a method directly on the object |
728 let smap = new (c.SplayTreeMap$(core.int, core.String))(); | 735 let smap = new (c.SplayTreeMap$(core.int, core.String).new)(); |
729 checkType(dart.bind(smap, 'forEach'), | 736 checkType(dart.bind(smap, 'forEach'), |
730 dart.fnTypeFuzzy(dart.void, | 737 dart.fnTypeFuzzy(dart.void, |
731 [dart.fnTypeFuzzy(dart.void, [core.int, core.String]
)])); | 738 [dart.fnTypeFuzzy(dart.void, [core.int, core.String]
)])); |
732 checkType(dart.bind(smap, 'forEach'), | 739 checkType(dart.bind(smap, 'forEach'), |
733 dart.fnTypeFuzzy(dart.void, | 740 dart.fnTypeFuzzy(dart.void, |
734 [dart.fnTypeFuzzy(dart.void, | 741 [dart.fnTypeFuzzy(dart.void, |
735 [core.String, core.String])]), false, true); | 742 [core.String, core.String])]), false, true); |
736 | 743 |
737 // Tear off of a mixed in method | 744 // Tear off of a mixed in method |
738 let mapB = new (c.MapBase$(core.int, core.int))(); | 745 let mapB = new (c.MapBase$(core.int, core.int).new)(); |
739 checkType(dart.bind(mapB, 'forEach'), | 746 checkType(dart.bind(mapB, 'forEach'), |
740 dart.fnTypeFuzzy(dart.void, [ | 747 dart.fnTypeFuzzy(dart.void, [ |
741 dart.fnTypeFuzzy(dart.void, [core.int, core.int])])); | 748 dart.fnTypeFuzzy(dart.void, [core.int, core.int])])); |
742 checkType(dart.bind(mapB, 'forEach'), | 749 checkType(dart.bind(mapB, 'forEach'), |
743 dart.fnTypeFuzzy(dart.void, [ | 750 dart.fnTypeFuzzy(dart.void, [ |
744 dart.fnTypeFuzzy(dart.void, [core.int, core.String])]), | 751 dart.fnTypeFuzzy(dart.void, [core.int, core.String])]), |
745 false, true); | 752 false, true); |
746 | 753 |
747 // Tear off of a method with a symbol name | 754 // Tear off of a method with a symbol name |
748 let listB = new (c.ListBase$(core.int))(); | 755 let listB = new (c.ListBase$(core.int).new)(); |
749 checkType(dart.bind(listB, dartx.add), | 756 checkType(dart.bind(listB, dartx.add), |
750 dart.fnTypeFuzzy(dart.void, [core.int])); | 757 dart.fnTypeFuzzy(dart.void, [core.int])); |
751 checkType(dart.bind(listB, dartx.add), | 758 checkType(dart.bind(listB, dartx.add), |
752 dart.fnTypeFuzzy(dart.void, [core.String]), false, true); | 759 dart.fnTypeFuzzy(dart.void, [core.String]), false, true); |
753 | 760 |
754 // Tear off of a static method | 761 // Tear off of a static method |
755 checkType(c.ListBase.listToString, | 762 checkType(c.ListBase.listToString, |
756 dart.fnTypeFuzzy(core.String, [core.List])); | 763 dart.fnTypeFuzzy(core.String, [core.List])); |
757 checkType(c.ListBase.listToString, | 764 checkType(c.ListBase.listToString, |
758 dart.fnTypeFuzzy(core.String, [core.String]), false, true); | 765 dart.fnTypeFuzzy(core.String, [core.String]), false, true); |
(...skipping 29 matching lines...) Expand all Loading... |
788 | 795 |
789 class M2 { | 796 class M2 { |
790 m(x) {return x;} | 797 m(x) {return x;} |
791 }; | 798 }; |
792 dart.setSignature(M2, { | 799 dart.setSignature(M2, { |
793 methods: () => ({ | 800 methods: () => ({ |
794 m: dart.fnType(core.Object, [core.int]), | 801 m: dart.fnType(core.Object, [core.int]), |
795 }) | 802 }) |
796 }); | 803 }); |
797 | 804 |
798 class O extends dart.mixin(Base, M1, M2) { | 805 class O extends dart.mixin(Base, M1, M2) {} |
799 new() {}; | 806 (O.new = function() {}).prototype = O.prototype; |
800 }; | |
801 dart.setSignature(O, {}); | 807 dart.setSignature(O, {}); |
802 var obj = new O(); | 808 var obj = new O.new(); |
803 var m = dart.bind(obj, 'm'); | 809 var m = dart.bind(obj, 'm'); |
804 checkType(m, dart.fnTypeFuzzy(core.Object, [core.int])); | 810 checkType(m, dart.fnTypeFuzzy(core.Object, [core.int])); |
805 checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false, true); | 811 checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false, true); |
806 | 812 |
807 // Test inherited signatures | 813 // Test inherited signatures |
808 class P extends O { | 814 class P extends O { |
809 new() {}; | |
810 m(x) {return x;}; | 815 m(x) {return x;}; |
811 }; | 816 }; |
| 817 (P.new = function() {}).prototype = P.prototype; |
812 dart.setSignature(P, {}); | 818 dart.setSignature(P, {}); |
813 var obj = new P(); | 819 var obj = new P.new(); |
814 var m = dart.bind(obj, 'm'); | 820 var m = dart.bind(obj, 'm'); |
815 checkType(m, dart.fnTypeFuzzy(core.Object, [core.int])); | 821 checkType(m, dart.fnTypeFuzzy(core.Object, [core.int])); |
816 checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false, true); | 822 checkType(m, dart.fnTypeFuzzy(core.int, [core.int]), false, true); |
817 }); | 823 }); |
818 | 824 |
819 test('Object members', () => { | 825 test('Object members', () => { |
820 let nullHash = dart.hashCode(null); | 826 let nullHash = dart.hashCode(null); |
821 assert.equal(nullHash, 0); | 827 assert.equal(nullHash, 0); |
822 let nullString = dart.toString(null); | 828 let nullString = dart.toString(null); |
823 assert.equal(nullString, 'null'); | 829 assert.equal(nullString, 'null'); |
824 | 830 |
825 let map = new Map(); | 831 let map = Map.new(); |
826 let mapHash = dart.hashCode(map); | 832 let mapHash = dart.hashCode(map); |
827 checkType(mapHash, core.int); | 833 checkType(mapHash, core.int); |
828 assert.equal(mapHash, map.hashCode); | 834 assert.equal(mapHash, map.hashCode); |
829 | 835 |
830 let mapString = dart.toString(map); | 836 let mapString = dart.toString(map); |
831 assert.equal(mapString, map.toString()); | 837 assert.equal(mapString, map.toString()); |
832 checkType(mapString, core.String); | 838 checkType(mapString, core.String); |
833 | 839 |
834 let str = "A string"; | 840 let str = "A string"; |
835 let strHash = dart.hashCode(str); | 841 let strHash = dart.hashCode(str); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 fnTypeFuzzy(T, [Func$(R, S)]))); | 1142 fnTypeFuzzy(T, [Func$(R, S)]))); |
1137 | 1143 |
1138 maybe(fnTypeFuzzy(int, [fnTypeFuzzy(int, [num])]), | 1144 maybe(fnTypeFuzzy(int, [fnTypeFuzzy(int, [num])]), |
1139 fnTypeFuzzy(num, [fnTypeFuzzy(int, [int])])); | 1145 fnTypeFuzzy(num, [fnTypeFuzzy(int, [int])])); |
1140 maybe(fnTypeFuzzy(int, [Func$(num, int)]), | 1146 maybe(fnTypeFuzzy(int, [Func$(num, int)]), |
1141 fnTypeFuzzy(num, [Func$(int, int)])); | 1147 fnTypeFuzzy(num, [Func$(int, int)])); |
1142 maybe(Func2$(num, int, int), Func2$(int, int, num)); | 1148 maybe(Func2$(num, int, int), Func2$(int, int, num)); |
1143 }); | 1149 }); |
1144 | 1150 |
1145 test('mixed types', () => { | 1151 test('mixed types', () => { |
1146 let AA$ = dart.generic((T) => class AA extends core.Object {}); | 1152 let AA$ = dart.generic((T) => { |
| 1153 class AA extends core.Object {} |
| 1154 (AA.new = function() {}).prototype = AA.prototype; |
| 1155 return AA; |
| 1156 }); |
1147 | 1157 |
1148 always(int, dyn); | 1158 always(int, dyn); |
1149 maybe(dyn, int); | 1159 maybe(dyn, int); |
1150 | 1160 |
1151 never(fnTypeFuzzy(int, [int]), int); | 1161 never(fnTypeFuzzy(int, [int]), int); |
1152 | 1162 |
1153 never(int, fnTypeFuzzy(int, [int])); | 1163 never(int, fnTypeFuzzy(int, [int])); |
1154 | 1164 |
1155 always(AA$(int), AA$(dyn)); | 1165 always(AA$(int), AA$(dyn)); |
1156 maybe(AA$(dyn), AA$(int)); | 1166 maybe(AA$(dyn), AA$(int)); |
(...skipping 20 matching lines...) Expand all Loading... |
1177 let Object = core.Object; | 1187 let Object = core.Object; |
1178 let String = core.String; | 1188 let String = core.String; |
1179 let int = core.int; | 1189 let int = core.int; |
1180 let dynamic = dart.dynamic; | 1190 let dynamic = dart.dynamic; |
1181 let bottom = dart.bottom; | 1191 let bottom = dart.bottom; |
1182 let Map = core.Map; | 1192 let Map = core.Map; |
1183 let Map$ = core.Map$; | 1193 let Map$ = core.Map$; |
1184 | 1194 |
1185 class A {} | 1195 class A {} |
1186 | 1196 |
1187 let AA$ = generic((T, U) => class AA extends core.Object {}); | 1197 let AA$ = generic((T, U) => { |
| 1198 class AA extends core.Object {} |
| 1199 (AA.new = function() {}).prototype = AA.prototype; |
| 1200 return AA; |
| 1201 }); |
1188 let AA = AA$(); | 1202 let AA = AA$(); |
1189 | 1203 |
1190 let Func2 = typedef('Func2', () => fnTypeFuzzy(dynamic, [dynamic, dynamic]))
; | 1204 let Func2 = typedef('Func2', () => fnTypeFuzzy(dynamic, [dynamic, dynamic]))
; |
1191 | 1205 |
1192 let FuncG$ = generic((T, U) => typedef('FuncG', () => fnTypeFuzzy(T, [T, U])
)) | 1206 let FuncG$ = generic((T, U) => typedef('FuncG', () => fnTypeFuzzy(T, [T, U])
)) |
1193 let FuncG = FuncG$(); | 1207 let FuncG = FuncG$(); |
1194 | 1208 |
1195 test('base types', () => { | 1209 test('base types', () => { |
1196 assert.equal(Object, Object); | 1210 assert.equal(Object, Object); |
1197 assert.equal(String, String); | 1211 assert.equal(String, String); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 | 1281 |
1268 assert.notEqual(fnTypeFuzzy(String, []), | 1282 assert.notEqual(fnTypeFuzzy(String, []), |
1269 fnTypeFuzzy(int, [])) | 1283 fnTypeFuzzy(int, [])) |
1270 }); | 1284 }); |
1271 }); | 1285 }); |
1272 | 1286 |
1273 suite('primitives', function() { | 1287 suite('primitives', function() { |
1274 'use strict'; | 1288 'use strict'; |
1275 | 1289 |
1276 test('fixed length list', () => { | 1290 test('fixed length list', () => { |
1277 let list = new core.List(10); | 1291 let list = core.List.new(10); |
1278 list[0] = 42; | 1292 list[0] = 42; |
1279 assert.throws(() => list.add(42)); | 1293 assert.throws(() => list.add(42)); |
1280 }); | 1294 }); |
1281 | 1295 |
1282 test('toString on ES Symbol', () => { | 1296 test('toString on ES Symbol', () => { |
1283 let sym = Symbol('_foobar'); | 1297 let sym = Symbol('_foobar'); |
1284 assert.equal(dart.toString(sym), 'Symbol(_foobar)'); | 1298 assert.equal(dart.toString(sym), 'Symbol(_foobar)'); |
1285 }); | 1299 }); |
1286 }); | 1300 }); |
1287 }); | 1301 }); |
OLD | NEW |