OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "dart:_js_helper"; | 5 import "dart:_js_helper"; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 @Native("A") | 8 @Native("A") |
9 class A { | 9 class A {} |
10 } | |
11 | 10 |
12 makeA() native; | 11 makeA() native ; |
13 | 12 |
14 void setup() native """ | 13 void setup() native """ |
15 function A() {}; | 14 function A() {}; |
16 A.prototype.foo = function() { return 42; } | 15 A.prototype.foo = function() { return 42; } |
17 makeA = function() { return new A; } | 16 makeA = function() { return new A; } |
18 """; | 17 """; |
19 | 18 |
20 class B { | 19 class B { |
21 foo() { return 42; } | 20 foo() { |
| 21 return 42; |
| 22 } |
22 } | 23 } |
23 | 24 |
24 class C { | 25 class C { |
25 // By having two 'foo' defined in the application, Frog will mangle | 26 // By having two 'foo' defined in the application, Frog will mangle |
26 // all calls to 'foo', which makes this test pass. | 27 // all calls to 'foo', which makes this test pass. |
27 foo(x) { return 43; } | 28 foo(x) { |
| 29 return 43; |
| 30 } |
28 } | 31 } |
29 | 32 |
30 typedContext() { | 33 typedContext() { |
31 var things = [ makeA(), new B() ]; | 34 var things = [makeA(), new B()]; |
32 A a = things[0]; | 35 A a = things[0]; |
33 Expect.throws(() => a.foo(), | 36 Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError); |
34 (e) => e is NoSuchMethodError); | 37 Expect.throws(() => a.foo, (e) => e is NoSuchMethodError); |
35 Expect.throws(() => a.foo, | 38 Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError); |
36 (e) => e is NoSuchMethodError); | |
37 Expect.throws(() => a.foo = 4, | |
38 (e) => e is NoSuchMethodError); | |
39 } | 39 } |
40 | 40 |
41 untypedContext() { | 41 untypedContext() { |
42 var things = [ makeA(), new B() ]; | 42 var things = [makeA(), new B()]; |
43 var a = things[0]; | 43 var a = things[0]; |
44 Expect.throws(() => a.foo(), | 44 Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError); |
45 (e) => e is NoSuchMethodError); | 45 Expect.throws(() => a.foo, (e) => e is NoSuchMethodError); |
46 Expect.throws(() => a.foo, | 46 Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError); |
47 (e) => e is NoSuchMethodError); | |
48 Expect.throws(() => a.foo = 4, | |
49 (e) => e is NoSuchMethodError); | |
50 } | 47 } |
51 | 48 |
52 main() { | 49 main() { |
53 setup(); | 50 setup(); |
54 typedContext(); | 51 typedContext(); |
55 untypedContext(); | 52 untypedContext(); |
56 } | 53 } |
OLD | NEW |