| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 "native_testing.dart"; |
| 6 import "package:expect/expect.dart"; | |
| 7 | 6 |
| 8 @Native("A") | 7 @Native("A") |
| 9 class A { | 8 class A { |
| 10 var foo; | 9 var foo; |
| 11 } | 10 } |
| 12 | 11 |
| 13 class B { | 12 class B { |
| 14 var foo; | 13 var foo; |
| 15 } | 14 } |
| 16 | 15 |
| 17 nativeId(x) native ; | 16 nativeId(x) native ; |
| 18 | 17 |
| 19 void setup() native """ | 18 void setup() native """ |
| 20 nativeId = function(x) { return x; } | 19 nativeId = function(x) { return x; } |
| 21 """; | 20 """; |
| 22 | 21 |
| 23 main() { | 22 main() { |
| 24 setup(); | 23 setup(); |
| 25 var b = new B(); | 24 var b = new B(); |
| 26 b.foo = (x) => x + 1; | 25 b.foo = (x) => x + 1; |
| 27 b = nativeId(b); // Inferrer doesn't know if A has been instantiated. | 26 b = nativeId(b); // Inferrer doesn't know if A has been instantiated. |
| 28 // At this point b could be A or B. The call to "foo" thus needs to go through | 27 // At this point b could be A or B. The call to "foo" thus needs to go through |
| 29 // an interceptor. Tests that the interceptor doesn't screw with retrieving | 28 // an interceptor. Tests that the interceptor works for retrieving the field |
| 30 // the field and invoking the closure. | 29 // and invoking the closure. |
| 31 // Use a type-check to guarantee that b is a "B". | 30 // Use a type-check to guarantee that b is a "B". |
| 32 if (b is B) { | 31 if (b is B) { |
| 33 Expect.equals(499, b.foo(498)); | 32 Expect.equals(499, b.foo(498)); |
| 34 } | 33 } |
| 35 } | 34 } |
| OLD | NEW |