| 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 'native_testing.dart'; | 5 import "dart:_js_helper"; |
| 6 import "package:expect/expect.dart"; |
| 7 |
| 6 @Native("A") | 8 @Native("A") |
| 7 class A {} | 9 class A {} |
| 8 | 10 |
| 9 A makeA() native ; | 11 makeA() native ; |
| 10 | 12 |
| 11 void setup() native """ | 13 void setup() native """ |
| 12 function A() {}; | 14 function A() {}; |
| 13 A.prototype.foo = function() { return 42; } | 15 A.prototype.foo = function() { return 42; } |
| 14 makeA = function() { return new A; } | 16 makeA = function() { return new A; } |
| 15 self.nativeConstructor(A); | |
| 16 """; | 17 """; |
| 17 | 18 |
| 18 class B { | 19 class B { |
| 19 foo() { | 20 foo() { |
| 20 return 42; | 21 return 42; |
| 21 } | 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) { | 28 foo(x) { |
| 28 return 43; | 29 return 43; |
| 29 } | 30 } |
| 30 } | 31 } |
| 31 | 32 |
| 32 typedContext() { | 33 typedContext() { |
| 33 A a = makeA(); | 34 var things = [makeA(), new B()]; |
| 35 A a = things[0]; |
| 34 Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError); | 36 Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError); |
| 35 Expect.throws(() => a.foo, (e) => e is NoSuchMethodError); | 37 Expect.throws(() => a.foo, (e) => e is NoSuchMethodError); |
| 36 Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError); | 38 Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError); |
| 37 } | 39 } |
| 38 | 40 |
| 39 untypedContext() { | 41 untypedContext() { |
| 40 var a = confuse(makeA()); | 42 var things = [makeA(), new B()]; |
| 43 var a = things[0]; |
| 41 Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError); | 44 Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError); |
| 42 Expect.throws(() => a.foo, (e) => e is NoSuchMethodError); | 45 Expect.throws(() => a.foo, (e) => e is NoSuchMethodError); |
| 43 Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError); | 46 Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError); |
| 44 } | 47 } |
| 45 | 48 |
| 46 main() { | 49 main() { |
| 47 nativeTesting(); | |
| 48 setup(); | 50 setup(); |
| 49 confuse(new B()).foo(); | |
| 50 confuse(new C()).foo(1); | |
| 51 typedContext(); | 51 typedContext(); |
| 52 untypedContext(); | 52 untypedContext(); |
| 53 } | 53 } |
| OLD | NEW |