OLD | NEW |
(Empty) | |
| 1 import 'dart:html'; |
| 2 import 'package:js/js.dart'; |
| 3 import 'package:expect/expect.dart'; |
| 4 |
| 5 @JS() |
| 6 class A { |
| 7 external get foo; |
| 8 |
| 9 external A(var foo); |
| 10 } |
| 11 |
| 12 @JS() |
| 13 @anonymous |
| 14 class C { |
| 15 final foo; |
| 16 |
| 17 external factory C({foo}); |
| 18 } |
| 19 |
| 20 @JS() |
| 21 @anonymous |
| 22 class D { |
| 23 final foo; |
| 24 |
| 25 external factory D({foo}); |
| 26 } |
| 27 |
| 28 class F { |
| 29 final foo; |
| 30 |
| 31 F(this.foo); |
| 32 } |
| 33 |
| 34 @NoInline() |
| 35 testA(A o) { |
| 36 return o.foo; |
| 37 } |
| 38 |
| 39 @NoInline() |
| 40 testC(C o) { |
| 41 return o.foo; |
| 42 } |
| 43 |
| 44 |
| 45 @NoInline() |
| 46 testD(D o) { |
| 47 return o.foo; |
| 48 } |
| 49 |
| 50 @NoInline() |
| 51 testF(F o) { |
| 52 return o.foo; |
| 53 } |
| 54 |
| 55 |
| 56 _injectJs() { |
| 57 document.body.append(new ScriptElement() |
| 58 ..type = 'text/javascript' |
| 59 ..innerHtml = r""" |
| 60 function A(foo) { |
| 61 this.foo = foo; |
| 62 } |
| 63 """); |
| 64 } |
| 65 |
| 66 void expectValueOrTypeError(f(), value) { |
| 67 try { |
| 68 String i = 0; // Test for checked mode. |
| 69 Expect.equals(f(), value); |
| 70 } on TypeError catch (error) { |
| 71 Expect.throws(f, (ex) => ex is TypeError); |
| 72 } |
| 73 } |
| 74 |
| 75 main() { |
| 76 _injectJs(); |
| 77 |
| 78 var a = new A(1); |
| 79 var d = new D(foo: 4); |
| 80 |
| 81 Expect.equals(testA(a), 1); /// 01: ok |
| 82 Expect.equals(testA(a), 1); /// 02: ok |
| 83 Expect.equals(testA(d), 4); |
| 84 Expect.equals(testD(d), 4); /// 02: continued |
| 85 } |
| 86 |
| 87 |
OLD | NEW |